06-13-2018 01:17 AM - edited 03-01-2019 04:11 AM
Hi All,
I've been banging my head about this issue for a couple of days... I wonder if it's normal that it's not possible to combine multiple API calls into a single one to create multiple instances of service using only one API REST call
The attached example can help you to understand what I mean
thank you for your time
Francesco
Header 1 |
---|
cisco ~ $ ncs_cli -u admin -C admin connected from x.x.x.x using ssh on debian admin@ncs# conf Entering configuration mode terminal admin@ncs(config)# services vrf R3 VRFBLUE rd 65000:65000 admin@ncs(config-vrf-R3/VRFBLUE)# address-family ipv4 route-target 1 export 65000:65000 import 65000:65000 admin@ncs(config-route-target-1)# address-family ipv4 route-target 2 export 65000:65001 import 65000:65001 admin@ncs(config-route-target-2)# commit dry-run outformat xml result-xml { local-node { data <devices xmlns="http://tail-f.com/ns/ncs"> <device> <name>R3</name> <config> <vrf xmlns="urn:ios"> <definition> <name>VRFBLUE</name> <rd>65000:65000</rd> <address-family> <ipv4> <route-target> <export> <asn-ip>65000:65000</asn-ip> </export> <export> <asn-ip>65000:65001</asn-ip> </export> <import> <asn-ip>65000:65000</asn-ip> </import> <import> <asn-ip>65000:65001</asn-ip> </import> </route-target> </ipv4> </address-family> </definition> </vrf> </config> </device> </devices> <services xmlns="http://tail-f.com/ns/ncs"> <vrf xmlns="http://example.com/vrf"> <device>R3</device> <vpn-name>VRFBLUE</vpn-name> <rd>65000:65000</rd> <address-family> <af>ipv4</af> <route-target> <id>1</id> <import>65000:65000</import> <export>65000:65000</export> </route-target> <route-target> <id>2</id> <import>65000:65001</import> <export>65000:65001</export> </route-target> </address-family> </vrf> </services> } } admin@ncs(config-route-target-2)# Uncommitted changes found, commit them? [yes/no/CANCEL] no admin@ncs# exit cisco ~ $ cat << EOF > v.xml > <vrf xmlns="http://example.com/vrf"> <export>65000:65000</export> > <device>R3</device> > <vpn-name>VRFBLUE</vpn-name> > <rd>65000:65000</rd> > <address-family> > <af>ipv4</af> > <route-target> > <id>1</id> > <import>65000:65000</import> > <export>65000:65000</export> > </route-target> > <route-target> > <id>2</id> > <import>65000:65001</import> > <export>65000:65001</export> > </route-target> > </address-family> > </vrf> > > EOF cisco ~ $ cat v.xml <vrf xmlns="http://example.com/vrf"> <device>R3</device> <vpn-name>VRFBLUE</vpn-name> <rd>65000:65000</rd> <address-family> <af>ipv4</af> <route-target> <id>1</id> <import>65000:65000</import> <export>65000:65000</export> </route-target> <route-target> <id>2</id> <import>65000:65001</import> <export>65000:65001</export> </route-target> </address-family> </vrf> cisco ~ $ curl -I --header 'Authorization: Basic YWRtaW46YWRtaW4=' --header 'Content-Type: application/vnd.yang.data+xml' -X POST -T v.xml http://10.58.0.24:8080/api/config/services?dry-run=native HTTP/1.1 100 Continue Server: Allow: GET, POST, OPTIONS, HEAD Content-Length: 0 HTTP/1.1 201 Created Server: Location: http://10.58.0.24:8080/api/config/services/vrf:vrf/R3,VRFBLUE Date: Wed, 13 Jun 2018 06:26:47 GMT Allow: GET, POST, OPTIONS, HEAD Last-Modified: Wed, 13 Jun 2018 06:21:50 GMT Cache-Control: private, no-cache, must-revalidate, proxy-revalidate Etag: 1528-870910-103174 Content-Length: 388 Content-Type: text/xml Vary: Accept-Encoding Access-Control-Allow-Methods: GET,POST,OPTIONS,PUT,DELETE Access-Control-Allow-Headers: access-control-allow-credentials,access-control-allow-headers,access-control-allow-methods,access-control-allow-origin,authorization,content-type Access-Control-Allow-Credentials: true Access-Control-Allow-Origin: * Pragma: no-cache <dry-run-result xmlns='http://tail-f.com/ns/rest/dry-run'> <native> <device> <name>R3</name> <data> ! Generated offline vrf definition VRFBLUE rd 65000:65000 address-family ipv4 route-target export 65000:65000 route-target export 65000:65001 route-target import 65000:65000 route-target import 65000:65001 exit-address-family ! ! </data> </device> </native> </dry-run-result>cisco ~ $ </dry-run-result>cisco ~ $ cat << EOF > v.xml > <vrf xmlns="http://example.com/vrf"> > <device>R3</device> > <vpn-name>VRFBLUE</vpn-name> > <rd>65000:65000</rd> > <address-family> > <af>ipv4</af> > <route-target> > <id>1</id> > <import>65000:65000</import> > <export>65000:65000</export> > </route-target> > <route-target> > <id>2</id> > <import>65000:65001</import> > <export>65000:65001</export> > </route-target> > </address-family> > </vrf> > <vrf xmlns="http://example.com/vrf"> <vpn-name>VRFBLUE</vpn-name> > <device>R4</device> > <vpn-name>VRFBLUE</vpn-name> > <rd>65000:65000</rd> > <address-family> > <af>ipv4</af> > <route-target> > <id>1</id> > <import>65000:65000</import> > <export>65000:65000</export> > </route-target> > <route-target> > <id>2</id> > <import>65000:65001</import> > <export>65000:65001</export> > </route-target> > </address-family> > </vrf> > EOF cisco ~ $ cat v.xml <vrf xmlns="http://example.com/vrf"> <device>R3</device> <vpn-name>VRFBLUE</vpn-name> <rd>65000:65000</rd> <address-family> <af>ipv4</af> <route-target> <id>1</id> <import>65000:65000</import> <export>65000:65000</export> </route-target> <route-target> <id>2</id> <import>65000:65001</import> <export>65000:65001</export> </route-target> </address-family> </vrf> <vrf xmlns="http://example.com/vrf"> <device>R4</device> <vpn-name>VRFBLUE</vpn-name> <rd>65000:65000</rd> <address-family> <af>ipv4</af> <route-target> <id>1</id> <import>65000:65000</import> <export>65000:65000</export> </route-target> <route-target> <id>2</id> <import>65000:65001</import> <export>65000:65001</export> </route-target> </address-family> </vrf> cisco ~ $ curl -I --header 'Authorization: Basic YWRtaW46YWRtaW4=' --header 'Content-Type: application/vnd.yang.data+xml' -X POST -T v.xml http://10.58.0.24:8080/api/config/services?dry-run=native HTTP/1.1 100 Continue Server: Allow: GET, POST, OPTIONS, HEAD Content-Length: 0 HTTP/1.1 400 Bad Request Server: Date: Wed, 13 Jun 2018 06:28:17 GMT Allow: GET, POST, OPTIONS, HEAD Cache-Control: private, no-cache, must-revalidate, proxy-revalidate Content-Length: 253 Content-Type: text/xml Vary: Accept-Encoding Access-Control-Allow-Methods: GET,POST,OPTIONS,PUT,DELETE Access-Control-Allow-Headers: access-control-allow-credentials,access-control-allow-headers,access-control-allow-methods,access-control-allow-origin,authorization,content-type Access-Control-Allow-Credentials: true Access-Control-Allow-Origin: * Pragma: no-cache <errors xmlns="http://tail-f.com/ns/tailf-rest-error"> <error> <error-tag>malformed-message</error-tag> <error-urlpath>/api/config/services</error-urlpath> <error-message>unexpected trailing data: vrf</error-message> </error> </errors> |
Solved! Go to Solution.
06-18-2018 01:14 AM
Hi Francesco,
You need to do partial operation on services resource. Here sample that worked for me with postman.
- http method PATCH,
- uri http://192.168.122.232:8080/api/config/
- Content-Type: application/vnd.yang.datastore+xml
- payload:
just wrap services instances in services tag:
<services xmlns="http://tail-f.com/ns/ncs">
<ip_vrf xmlns="http://com/example/ipvrf">
<owning_entity_id>iosxr0</owning_entity_id>
<vrf_name>karolprov</vrf_name>
<asn>10</asn>
<address_family_type>ipv4</address_family_type>
<rd>10:10</rd>
</ip_vrf>
<ip_vrf xmlns="http://com/example/ipvrf">
<owning_entity_id>iosxr0</owning_entity_id>
<vrf_name>karolprov3</vrf_name>
<asn>20</asn>
<address_family_type>ipv4</address_family_type>
<rd>12:10</rd>
</ip_vrf>
</services>
I hope it helps
Karol
06-13-2018 02:27 AM
If you want to create multiple instances it is possible to send a call to higher level URI.
However if you want to mix create of one instance with i.e. deletion of another - for this one you'd need to use yang-patch as defined in RFC8072 - NSO 4.6 / 4.5.2 comes with support for it
06-13-2018 04:08 AM
Hi Maciej
thank you for your time,
could you provide me a working example (with curl) or something similiar that could help me to solve this situation?
(i'm using NSO >4.6)
thank you
Fra
06-18-2018 01:14 AM
Hi Francesco,
You need to do partial operation on services resource. Here sample that worked for me with postman.
- http method PATCH,
- uri http://192.168.122.232:8080/api/config/
- Content-Type: application/vnd.yang.datastore+xml
- payload:
just wrap services instances in services tag:
<services xmlns="http://tail-f.com/ns/ncs">
<ip_vrf xmlns="http://com/example/ipvrf">
<owning_entity_id>iosxr0</owning_entity_id>
<vrf_name>karolprov</vrf_name>
<asn>10</asn>
<address_family_type>ipv4</address_family_type>
<rd>10:10</rd>
</ip_vrf>
<ip_vrf xmlns="http://com/example/ipvrf">
<owning_entity_id>iosxr0</owning_entity_id>
<vrf_name>karolprov3</vrf_name>
<asn>20</asn>
<address_family_type>ipv4</address_family_type>
<rd>12:10</rd>
</ip_vrf>
</services>
I hope it helps
Karol
06-20-2018 05:48 AM
Thank you so much Karol,
this is exactly what i was looking for
thank you for your time
bye
Francesco
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide