cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1159
Views
25
Helpful
4
Replies

Restconf pushing multiple services in one commit

tsiemers1
Spotlight
Spotlight

Options for pushing multiple services in one restconf push.

 

I was reading over the docs and was thinking about using yang-patch to push multiple services using multiple edits in one commit. Does anybody have any other options they have used to complete this? I think the other option would be to convert the two services into stacked service and control with a parent service.

 

Thanks

1 Accepted Solution

Accepted Solutions

If you work with XML, when reading multiple instances, you need to use the NSO collection extension as you do not want to read the full CDB in . From userguide:

Collections

The RESTCONF specification states that a result containing multiple instances (e.g a number of list entries) is not allowed if XML encoding is used. The reason for this is that an XML document can only have one root node.

To remedy this, a HTTP GET request can make use of the "Accept:" media type: application/vnd.yang.collection+xml as shown in the following example.

Example 63. Use of collections

curl -H "Accept: application/vnd.yang.collection+xml" http://....

The result will then be wrapped with a "collection" element as shown below:

Example 64. Use of collections



....



View solution in original post

4 Replies 4

gmuloche
Cisco Employee
Cisco Employee

Hello,

 

I am not sure if I get your question right but for instance if you want to push 2 instances of the service test defined at the root level you can use the base RESTCONF URL like this:

 

Before:

admin@scratch# show running-config test
% No entries found.

 

Request (extracted from local POSTMAN):

curl --location --request PATCH 'http://127.0.0.1:8080/restconf/data' \
--header 'Content-Type: application/yang-data+json' \
--header 'Authorization: Basic YWRtaW46YWRtaW4=' \
--data-raw '{
"test:test": [
{
"name": 42
},
{
"name": 43
}
]
}'
 
After:
admin@scratch# show running-config test
test 42
!
test 43
!

 

 

note - in XML you can use a container data around the multiple services

 

CURL:

curl --location --request PATCH 'http://127.0.0.1:8080/restconf/data' \
--header 'Content-Type: application/yang-data+xml' \
--header 'Authorization: Basic YWRtaW46YWRtaW4=' \
--data-raw '<data>
<test>
<name>42</name>
<dummy>1.1.1.2</dummy>
</test>
<test>
<name>43</name>
<dummy>1.1.1.3</dummy>
</test>
</data>'

Looks like XML will work. I was trying to push two different services from a 3rd party vendor (itential) using JSON to produce a single dry-run for the end-user. Using your example above I found a way to push XML instead of JSON so that will work. The idea was like below, instead of pushing two instances of the test, it would be service-1 and service-2 in the same payload. Thanks

 

curl --location --request PATCH 'http://127.0.0.1:8080/restconf/data' \
--header 'Content-Type: application/yang-data+xml' \
--header 'Authorization: Basic YWRtaW46YWRtaW4=' \
--data-raw '<data>
<service-1>
<name>42</name>
<dummy>1.1.1.2</dummy>
</service-1>
<service-2>
<name>43</name>
<dummy>1.1.1.3</dummy>
</service-2>
</data>'

If you work with XML, when reading multiple instances, you need to use the NSO collection extension as you do not want to read the full CDB in . From userguide:

Collections

The RESTCONF specification states that a result containing multiple instances (e.g a number of list entries) is not allowed if XML encoding is used. The reason for this is that an XML document can only have one root node.

To remedy this, a HTTP GET request can make use of the "Accept:" media type: application/vnd.yang.collection+xml as shown in the following example.

Example 63. Use of collections

curl -H "Accept: application/vnd.yang.collection+xml" http://....

The result will then be wrapped with a "collection" element as shown below:

Example 64. Use of collections



....