cURL
Requirement on the RESTCONF client
RESTCONF examples using cURL
GET
Get interface description for Ethernet1
curl -s GET 'https://192.0.2.105:6020/restconf/data/openconfig-interfaces:interfaces/interface=Ethernet1/config/description' \
--header 'Accept: application/yang-data+json' -u arista:arista --insecure
Output:
Get interface stats for Ethernet1 and output the "in-octets" using jq
curl -s GET 'https://192.0.2.105:6020/restconf/data/openconfig-interfaces:interfaces/interface=Ethernet1' \
--header 'Accept: application/yang-data+json' -u arista:arista \
--insecure | jq .'"openconfig-interfaces:state".counters."in-octets"'
Output:
Get interfaces stats and output the name of the second (third index) using jq
curl -s GET 'https://192.0.2.105:6020/restconf/data/openconfig-interfaces:interfaces' \
--header 'Accept: application/yang-data+json' -u arista:arista \
--insecure | jq .'"openconfig-interfaces:interface"[2].name'
Output:
Get the system information and parse the hostname using jq
curl -X GET https://192.0.2.105:6020/restconf/data/system \
--header 'Accept: application/yang-data+json' -u arista:arista \
--insecure | jq .'"openconfig-system:config".hostname'
Output:
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 66151 0 66151 0 0 284k 0 --:--:-- --:--:-- --:--:-- 284k
"switch1"
Get PfxRcd and PfxAcc stats from a BGP neighbor
curl -s GET 'https://192.0.2.100:5900/restconf/data/network-instances/network-instance=default/protocols/protocol=BGP,BGP/bgp/neighbors/neighbor=192.0.2.21/afi-safis/afi-safi=IPV4_UNICAST' \
--header 'Accept: application/yang-data+json' -u cvpadmin:arastra --insecure | jq
Output:
{
"openconfig-network-instance:afi-safi-name": "openconfig-bgp-types:IPV4_UNICAST",
"openconfig-network-instance:config": {
"afi-safi-name": "openconfig-bgp-types:IPV4_UNICAST"
},
"openconfig-network-instance:state": {
"afi-safi-name": "openconfig-bgp-types:IPV4_UNICAST",
"prefixes": {
"arista-bgp-augments:best-ecmp-paths": 0,
"arista-bgp-augments:best-paths": 0,
"installed": 7,
"received": 7,
"sent": 7
}
}
}
NOTE: The protocol must have multiple keys, i.e.:
protocol=BGP,BGP
, in this case, it's theidentifier
and thename
of the protocol, if either of these is omitted; on the switch side in the Octa/OpenConfig agent logs an error similar to the following would be generated:
handler.go:95] ERROR mismatch between number of keys in [identifier name] and values present [BGP]
or if are omitted the error message would be:handler.go:95] ERROR failed to find key values after element "protocol" in "network-instances/network-instance=default/protocols/protocol
Tip: pyang can be useful to understand what keys each leaf requires, e.g:
pyang openconfig-network-instance.yang -f tree --tree-depth=4 | tail -n 4
| ...
+--rw protocols
+--rw protocol* [identifier name]
...
HEAD
curl --head 'https://192.0.2.105:6020/restconf/data/openconfig-interfaces:interfaces/interface=Ethernet1' \
--header 'Accept: application/yang-data+json' -u arista:arista --insecure
output
PUT
Interface configuration example
Let's check before the change
curl -s GET 'https://192.0.2.105:6020/restconf/data/openconfig-interfaces:interfaces/interface=Ethernet4/config' \
--header 'Accept: application/yang-data+json' -u arista:arista --insecure
output
{"openconfig-interfaces:description":"blabla","openconfig-interfaces:enabled":false,"arista-intf-augments:load-interval":300,"openconfig-interfaces:loopback-mode":false,"openconfig-interfaces:mtu":0,"openconfig-interfaces:name":"Ethernet4","openconfig-vlan:tpid":"openconfig-vlan-types:TPID_0X8100","openconfig-interfaces:type":"iana-if-type:ethernetCsmacd"}
Let's use the file interface.json
output
curl -X PUT https://192.0.2.105:6020/restconf/data/openconfig-interfaces:interfaces/interface=Ethernet4/config \
-H 'Content-Type: application/json' -u arista:arista -d @interface.json --insecure
output
{"openconfig-interfaces:description":"restconf_test","openconfig-interfaces:enabled":true,"openconfig-interfaces:name":"Ethernet4"}
Let's verify after the change
curl -s GET 'https://192.0.2.105:6020/restconf/data/openconfig-interfaces:interfaces/interface=Ethernet4/config' \
--header 'Accept: application/yang-data+json' -u arista:arista --insecure
output
{"openconfig-interfaces:description":"restconf_test","openconfig-interfaces:enabled":true,"arista-intf-augments:load-interval":300,"openconfig-interfaces:loopback-mode":false,"openconfig-interfaces:mtu":0,"openconfig-interfaces:name":"Ethernet4","openconfig-vlan:tpid":"openconfig-vlan-types:TPID_0X8100","openconfig-interfaces:type":"iana-if-type:ethernetCsmacd"}
curl -s GET 'https://192.0.2.105:6020/restconf/data/openconfig-interfaces:interfaces/interface=Ethernet4/config' \
--header 'Accept: application/yang-data+json' -u arista:arista --insecure | jq .
output
{
"openconfig-interfaces:description": "restconf_test",
"openconfig-interfaces:enabled": true,
"arista-intf-augments:load-interval": 300,
"openconfig-interfaces:loopback-mode": false,
"openconfig-interfaces:mtu": 0,
"openconfig-interfaces:name": "Ethernet4",
"openconfig-vlan:tpid": "openconfig-vlan-types:TPID_0X8100",
"openconfig-interfaces:type": "iana-if-type:ethernetCsmacd"
}
Device hostname example
Let's check before the change
curl -X GET https://192.0.2.105:6020/restconf/data/system/config \
--header 'Accept: application/yang-data+json' -u arista:arista --insecure
output
curl -X GET https://192.0.2.105:6020/restconf/data/system \
--header 'Accept: application/yang-data+json' -u arista:arista \
--insecure | jq .'"openconfig-system:config".hostname'
output
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 74748 0 74748 0 0 300k 0 --:--:-- --:--:-- --:--:-- 300k
"DC1-LEAF1A"
curl -X PUT https://192.0.2.105:6020/restconf/data/system/config \
-H 'Content-Type: application/json' -u arista:arista \
-d '{"openconfig-system:hostname":"test"}' --insecure
output
Let's verify after the change
curl -X GET https://192.0.2.105:6020/restconf/data/system/config \
--header 'Accept: application/yang-data+json' -u arista:arista --insecure
output
POST
Interface configuration example
Let's check before the change
curl -s GET 'https://192.0.2.105:6020/restconf/data/openconfig-interfaces:interfaces/interface=Ethernet4' \
--header 'Accept: application/yang-data+json' -u arista:arista \
--insecure | jq .'"openconfig-interfaces:config"'
output
{
"description": "",
"enabled": true,
"arista-intf-augments:load-interval": 300,
"loopback-mode": false,
"mtu": 0,
"name": "Ethernet4",
"openconfig-vlan:tpid": "openconfig-vlan-types:TPID_0X8100",
"type": "iana-if-type:ethernetCsmacd"
}
curl -X POST https://192.0.2.105:6020/restconf/data/openconfig-interfaces:interfaces/interface=Ethernet4/config \
-H 'Content-Type: application/json' -u arista:arista \
-d '{"openconfig-interfaces:description":"restconf_test"}' --insecure
output
curl -X POST https://192.0.2.105:6020/restconf/data/openconfig-interfaces:interfaces/interface=Ethernet4/config \
-H 'Content-Type: application/json' -u arista:arista \
-d '{"openconfig-interfaces:enabled":false}' --insecure
output
Let's verify after the change
curl -s GET 'https://192.0.2.105:6020/restconf/data/openconfig-interfaces:interfaces/interface=Ethernet4' \
--header 'Accept: application/yang-data+json' -u arista:arista \
--insecure | jq .'"openconfig-interfaces:config".description'
output
curl -s GET 'https://192.0.2.105:6020/restconf/data/openconfig-interfaces:interfaces/interface=Ethernet4' \
--header 'Accept: application/yang-data+json' \
-u arista:arista --insecure | jq .'"openconfig-interfaces:config"'
output
{
"description": "restconf_test",
"enabled": false,
"arista-intf-augments:load-interval": 300,
"loopback-mode": false,
"mtu": 0,
"name": "Ethernet4",
"openconfig-vlan:tpid": "openconfig-vlan-types:TPID_0X8100",
"type": "iana-if-type:ethernetCsmacd"
}
DELETE
Let's check before the change
curl -s GET 'https://192.0.2.105:6020/restconf/data/ietf-interfaces:interfaces/interface=Loopback100' \
--header 'Accept: application/yang-data+json' -u arista:arista --insecure
output
{"openconfig-interfaces:config":{"description":"test","enabled":true,"arista-intf-augments:load-interval":300,"loopback-mode":true,"name":"Loopback100","openconfig-vlan:tpid":"openconfig-vlan-types:TPID_0X8100","type":"iana-if-type:softwareLoopback"},"openconfig-interfaces:hold-time":{"config":{"down":0,"up":0},"state":{"down":0,"up":0}},"openconfig-interfaces:name":"Loopback100","openconfig-interfaces:state":{"enabled":true,"loopback-mode":false,"openconfig-vlan:tpid":"openconfig-vlan-types:TPID_0X8100"},"openconfig-interfaces:subinterfaces":{"subinterface":[{"config":{"description":"test","enabled":true,"index":0},"index":0,"openconfig-if-ip:ipv4":{"config":{"dhcp-client":false,"enabled":true,"mtu":1500},"state":{"dhcp-client":false,"enabled":true,"mtu":1500}},"openconfig-if-ip:ipv6":{"config":{"dhcp-client":false,"enabled":false,"mtu":1500},"state":{"dhcp-client":false,"enabled":false,"mtu":1500}},"state":{"enabled":true,"index":0}}]}}