cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1603
Views
0
Helpful
4
Replies

How to delete configuration on Junos via NSO

oldcreek12
Level 1
Level 1

Hi,

I am new to NSO, so apologize for my ignorance. I recently downloaded NSO 5.3 and I was able to successfully develop a static NAT service with real device being a Juniper vSRX, I can call API to successfully create a valid static NAT entry on vSRX, for example, 

 
$curl -i -X POST http://localhost:8080/restconf/data/ -u admin:admin -H "Content-Type: application/yang-data+xml" -d '<static_nat xmlns="http://com/example/static_nat">
>         <rule_name>nsonatrulename</rule_name>
>         <ext_pub_ip>192.168.1.3</ext_pub_ip>
>         <int_pri_ip>10.1.1.3</int_pri_ip>
>         <device>jnpr-dev-vsrx</device>
>  </static_nat>'
 
Now I wanted to delete this above NAT entry, it worked find on NSO CLI with "no static_nat nsonatrulename",  commit dry-run outputformat xml shows that corresponding XML snippet for this change is,
 
<static_nat xmlns="http://com/example/static_nat"
xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"
nc:operation="delete">
<rule_name>nsonatrulename</rule_name>
</static_nat>
 
Now when I POST the above XML to API, I always get "HTTP/1.1 500 Internal Server Error", where did I do wrong?
1 Accepted Solution

Accepted Solutions

vleijon
Cisco Employee
Cisco Employee
So, the dry-run with the delete tag is a netconf payload, which you cannot send over the RESTCONF API. You can move to NETCONF but a way to achieve the same over the RESTCONF API is to use the DELETE action instead of POST, you can look at examples.ncs/getting-started/developing-with-ncs/13-restconf in your NSO install.

View solution in original post

4 Replies 4

vleijon
Cisco Employee
Cisco Employee
So, the dry-run with the delete tag is a netconf payload, which you cannot send over the RESTCONF API. You can move to NETCONF but a way to achieve the same over the RESTCONF API is to use the DELETE action instead of POST, you can look at examples.ncs/getting-started/developing-with-ncs/13-restconf in your NSO install.

Thanks, I tried DELETE actions, it is not accepted/supported.

It should work, what url do you use? Try following the pattern in the example, in particular remember to give the module name in the url.

lmanor
Cisco Employee
Cisco Employee

So, it looks like you create a service instance of service 'static-nat' called nsonatrulename (presuming that the service is a list and rule_name is the instance identifier (key to list))

 

After creation of your service instance as shown below, the delete of that instance would be accomplished by:

curl -i -X DELETE -u admin:admin http://localhost:8080/restconf/data/static-nat:static-nat=nsonatrulename

 

Simple example ('name' is key for service 'hostname' list):

$ curl -i -X POST http://localhost:8080/restconf/data/ -u admin:admin -H "Content-Type: application/yang-data+xml" -d '<hostname xmlns="http://com/example/hostname"> <name>hn1</name> <device>j-0</device> <zone>zone1</zone> <location>Boston</location> </hostname>'
HTTP/1.1 201 Created

$ curl -i -X DELETE -u admin:admin http://localhost:8080/restconf/data/hostname:hostname=hn1
HTTP/1.1 204 No Content