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.

Routes_on_fortigate.png

The READ can be implemented as below:

Fortigate_routes_READ.png

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.$object_id.gw}
set device {$Routing.$object_id.interface}
set comment "{$Routing.$object_id.comment}"
next
end

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 10.60.60.0 255.255.255.0\nset gateway 10.1.1.1\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}">
  <dest_ip>{$Routing.$object_id.ip_dest}</dest_ip>
  <mask>{$Routing.$object_id.mask}</mask>
  <gw>{$Routing.$object_id.gw}</gw>
  <interface>{$Routing.$object_id.interface}</interface>
</route>

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>95.138.182.173</dest_ip>\n  <mask>255.255.255.255</mask>\n  <gw>192.168.2.30</gw>\n  <interface>port3</interface>\n</route>\n\n","status":"OK"}