How to Use LIST & READ

How to read configuration items from the CMDB (READ & LIST)

The Microservice are mostly used to manage the device by updating (CREATE, UPDATE, DELETE) the configuration.

The IMPORT will get the configuration items and store them in the OpenMSA CMDB but how can we read the configuration items (CI) from the CMDB?

Implement the READ to generate some formatted list of CI

case 1: read the CI from CMDB and generate a configuration

the implementation of a READ is very open and basically it's a template that will be resolved with the values from the CMDB

As an example, we can print the CI for a route on Fortigate.


The READ can be implemented as below:


in the code sample below, note the use of the syntax {$Routing.$object_id.object_id}. The $Routing refers to the name of the Microservice (Routing.xml) and the $object_id should be the ID of the Microservice instance in the database (2 in the example below)

config router static
edit {$Routing.$object_id.object_id}
set dst {$Routing.$object_id.ip_dest} {$Routing.$object_id.mask}
set gateway {$Routing.$}
set device {$Routing.$object_id.interface}
set comment "{$Routing.$object_id.comment}"

the REST API can be used to call the READ with the ID of a route.

For example, with route #2:

curl -u ncroot:ubiqube  -XPOST http://localhost/ubi-api-rest/ordercommand/execute/392/READ -d '{
    "Routing": {
        "2": {}

the result will be:

    "commandId": 0,
    "message": "config router static\nedit 2\nset dst\nset gateway\nset device port3\nset comment \"\"\nnext\nend\n",
    "status": "OK"

case 2: read the CI from CMDB and generate a structured file

The implementation of the READ can also be used to generate a structured file (XML, JSON, YAML,...)

<route id="{$Routing.$object_id.object_id}">

the REST call is the same (with object_id=4 below):

curl -u ncroot:ubiqube  -XPOST http://localhost/ubi-api-rest/ordercommand/execute/392/READ -d '{"Routing": {"4": {}}}'

returns the XML with the CI for route ID 4 in the message field:

{"commandId":0,"message":"<route id=\"4\">\n  <dest_ip></dest_ip>\n  <mask></mask>\n  <gw></gw>\n  <interface>port3</interface>\n</route>\n\n","status":"OK"}