cancel
Showing results for 
Search instead for 
Did you mean: 
cancel

JSON-RPC vs Restconf service creation difference

565
Views
5
Helpful
5
Comments
Cisco Employee

Hi All,


NSO : 5.2.2.1

Same input data when sent using restconf gives a different output vs when sent using JSONRPC

Yang model:

The contents list is ordered-by user

list ip-access-list {
key acl-name;
leaf acl-name {
tailf:info "list name (max size 64)";
type string;
tailf:cli-expose-key-name;
}
list contents {
key content;
ordered-by user;
leaf content {
tailf:info "rules";
type string;
tailf:cli-expose-key-name;
}
min-elements 1;
}
}

User input payload :

"ip-access-list": [
{
"acl-name": "45",
"contents": [
{
"content": "permit ip host 10.122.32.86 host 0.0.0.0"
},
{
"content": "permit ip host 10.122.32.88 host 0.0.0.0"
},
{
"content": "permit ip host 10.81.59.57 host 0.0.0.0"
},
{
"content": "permit ip host 10.81.59.56 host 0.0.0.0"
}
]
}
]


Service output When sent using restconf:

admin@ncs-cfs# show running-config services nx-global-conf-cfs device nx_0
services nx-global-conf-cfs device nx_0
aaa-flag false
banner motd "Robot Test WithCheck\n"
banner start-end-marker ^
snmp ip-access-list acl-name 45
contents content "permit ip host 10.122.32.86 host 0.0.0.0"
!
contents content "permit ip host 10.122.32.88 host 0.0.0.0"
!
contents content "permit ip host 10.81.59.57 host 0.0.0.0"
!
contents content "permit ip host 10.81.59.56 host 0.0.0.0"
!
!
!


Service output When sent using JSONRPC:

services nx-global-conf-cfs device nx_0
base-config domain-name boa
aaa-flag false
snmp ip-access-list acl-name 45
contents content "permit ip host 10.122.32.86 host 0.0.0.0"
!
contents content "permit ip host 10.122.32.88 host 0.0.0.0"
!
contents content "permit ip host 10.81.59.56 host 0.0.0.0"
!
contents content "permit ip host 10.81.59.57 host 0.0.0.0"
!
!
!

 

If we see the service output when sent using JSONRPC is not as per our expectation of "ordered-by user" 10.81.59.57 and 10.81.59.56 got re-ordered.

Just thinking if JSONRPC input to NSO is getting re-ordered even before it is hitting the NSO yang.

I am looking for, is this known behavior/bug with JSONRPC and the reason for this re-ordering.

How to handle this scenario ?

Thank you.

5 Comments
Cisco Employee

Hi,

 

I think you missed the API calls you were doing.

 

In any case, with JSON-RPC, you can use the method "append_list_entry" to add a new entry into the list. Then you can use "move_list_entry" to move it where you want it using the different keywords first/last/before/after.

 

Remember that in RESTCONF you do not have the concept of a sessions, therefore you cannot apply two commands (which you can in JSON-RPC).

 

Roque

 

Params
{"th": <integer>,
"from_path": <string>,
"to_path": <string>,
"mode": <"first" | "last" | "before" | "after">}
The from_path is a keypath pointing out the list entry to be moved.
The list entry to be moved can either be moved to the first or the last position, i.e. if the mode param is set
to first or last the to_path keypath param has no meaning.
If the mode param is set to before or after the to_path param must be specified, i.e. the list entry will be
moved to the position before or after the list entry which the to_path keypath param points to.

 

RESTCONF manipulations:

B.3.4. "insert" Parameter

   In this example, a new first song entry in the "Foo-One" playlist is
   being created.

   Request from client:

      POST /restconf/data/example-jukebox:jukebox/\
          playlist=Foo-One?insert=first HTTP/1.1
      Host: example.com
      Content-Type: application/yang-data+json

      {
        "example-jukebox:song" : [
           {
             "index" : 1,
             "id" : "/example-jukebox:jukebox/library\
                /artist[name='Foo Fighters']\
                /album[name='Wasting Light']\
                /song[name='Rope']"
           }
         ]
      }

   Response from server:

      HTTP/1.1 201 Created
      Date: Thu, 26 Jan 2017 20:56:30 GMT
      Server: example-server
      Last-Modified: Thu, 26 Jan 2017 20:56:30 GMT
      Location: https://example.com/restconf/data/\
          example-jukebox:jukebox/playlist=Foo-One/song=1
      ETag: "eeeada438af"



 

Cisco Employee

HI Roque,

 

Thank you for your response.

We can add this if we are doing it from postman. But in case if we are using ansible module to configure or any other northbound who will be interacting with NSO using JSONRPC. How to handle this ?

 

 

 

Cisco Employee

JSON-RPC is an API...it is meant for machines to talk to machines. I am not possitive on how the Ansible module handles "ordered-by-user" but that is another question to ask in the Forum.

Cisco Employee

Thank you Roque

Cisco Employee

Thank you All,

 

Got the fix from NSO BU. Fix available in NSO 5.2.3.1