06-13-2022
05:36 AM
- last edited on
08-10-2022
01:46 PM
by
Paul Zimmerman
Hi!
I want to automate the configuration of vlans across a network based on Catalyst 9300 and Nexus 9XXX switches. I have enabled restconf on all the switches and I am able to look at the configuration. I have developed a python script for the Nexus switches that will add a vlan to the switch if it doesn't exist and I am looking to do the same for the catalyst 9300. However I can't find anything that seems to work. I have seen several suggestions using the Cisco-IOS-XE-native yang model but using a get for https://<host>/restconf/data/Cisco-IOS-XE-native pulls the configuration but it doesn't include the vlan database. So adding vlan to the end of the previous url returns a 204, no body or data. The Cisco-IOS-XE-vlan-oper pulls data but is a read only model. The Cisco-IOS-XE-vlan I can't get to return any sensible data and I get a 404 back from the switch.
Any suggestions?
Solved! Go to Solution.
06-17-2022 11:34 AM
Peter,
I just tested out of my own curiosity without specifying port :443 in the URL thinking some odd bug indeed; however, my responses are still complete/correct.
I then tested the URL you shared (which returns the entire configuration) but in my case, I do see the VLAN DB as part of the JSON response. It is right after the VRF/DNS portions in the body:
"vlan": { "Cisco-IOS-XE-vlan:vlan-list": [ { "id": 171, "name": "CiscoForum" }, { "id": 172, "name": "DevTest" }, { "id": 173, "name": "Example" }, { "id": 4000, "name": "AppHosting-VLAN" } ] },
I'll upgrade my C9K to 17.6.3 to make sure there's no behavioral changes there. Having that said:
1 - What do your headers look like for the GET request?
2- Could you share your Python script and/or CURL/Postman outputs? (want to make sure we are apples to apples)
Below my sample:
import requests url = "https://10.10.20.100/restconf/data/Cisco-IOS-XE-native:native" payload={} headers = { 'Accept': 'application/yang-data+json, application/yang-data.errors+json', 'Authorization': 'Basic ZGV2ZWxvcGVyOkMxc2NvMTIzNDU=' } response = requests.request("GET", url, headers=headers, data=payload) print(response.text)
Thanks!
06-22-2022 06:30 AM
Peter,
GET https://{{ip_address}}/restconf/data/Cisco-IOS-XE-vlan-oper:vlans/vlan
C9K-Dev-Test#show vtp status VTP Version capable : 1 to 3 VTP version running : 1 VTP Domain Name : VTP Pruning Mode : Disabled VTP Traps Generation : Disabled Device ID : 701f.53b9.6d80 Configuration last modified by 10.201.168.181 at 6-22-22 12:43:37 Local updater ID is 10.201.168.181 on interface Gi0/0 (first layer3 interface found) Feature VLAN: -------------- VTP Operating Mode : Server Maximum VLANs supported locally : 1005 Number of existing VLANs : 7 Configuration Revision : 2 MD5 digest : 0x45 0x29 0x47 0xB6 0x5E 0x8B 0xF3 0xAF 0xE0 0x3E 0xE8 0xBE 0xB2 0xC8 0xD0 0x49
C9K-Dev-Test#show run | sec vlan vlan 1010 name Test-1010 vlan 1200 name Test-1200
C9K-Dev-Test#show vlan brief VLAN Name Status Ports ---- -------------------------------- --------- ------------------------------- <snip> 5 Test-5 active 7 Test-7 active 1002 fddi-default act/unsup 1003 token-ring-default act/unsup 1004 fddinet-default act/unsup 1005 trnet-default act/unsup 1010 Test-1010 active 1200 Test-1200 active
atestini@ATESTINI-M-26WU YANG % curl -k --request GET 'https://10.201.168.181/restconf/data/Cisco-IOS-XE-vlan-oper:vlans/vlan' \ --header 'Accept: application/yang-data+json, application/yang-data.errors+json' \ --header 'Authorization: Basic YWRtaW46Y2lzY28hMTIz' { "Cisco-IOS-XE-vlan-oper:vlan": [ { "id": 1, "name": "default", "status": "active", "vlan-interfaces": [ { "interface": "GigabitEthernet1/0/1", "subinterface": 0 ## snipping output here for brevity ## ] }, { "id": 5, "name": "Test-5", "status": "active" }, { "id": 7, "name": "Test-7", "status": "active" }, { "id": 1002, "name": "fddi-default", "status": "suspend" }, { "id": 1003, "name": "token-ring-default", "status": "suspend" }, { "id": 1004, "name": "fddinet-default", "status": "suspend" }, { "id": 1005, "name": "trnet-default", "status": "suspend" }, { "id": 1010, "name": "Test-1010", "status": "active" }, { "id": 1200, "name": "Test-1200", "status": "active" } ] }
06-13-2022 06:10 AM
@p.weeks this should work i think https://github.com/jeremycohoe/restconf-catalyst-3850
06-13-2022 06:56 AM
06-13-2022 07:02 AM
The other example i found was https://github.com/CiscoDevNet/restconf-examples/tree/master/restconf-samplecode/vlans
06-13-2022 07:08 AM
06-13-2022 08:59 AM
@p.weeks take a look at Yang Suite https://developer.cisco.com/yangsuite/ might help too. I do not have a 9300 to test with, so mostly guessing here, but saw this `data/Cisco-IOS-XE/native/native:vlan/vlan-list=100`
06-14-2022 03:35 AM
03-06-2023 07:11 AM
Hi!
Thanks for the link, it was a good start for me.
Is there any Catalyst 9000 RESTCONF documentation where I could find similar and more? Fro example, how to configure LACP on Catalyst 90000 with help of RESTCONF?
TIA
Alexei.
03-17-2023 08:48 AM
Hei Alexei
There are two ways to find what your looking for, the easy way is to configure what your after on a switch and then do a get to the switch using restconf/data/native. This should present you with the whole config and you can use the bit you need. Alternatively install Cisco's yangsuite some where and use that a look up. Again use the Cisco-IOS-XE-native yang model as your start point.
I hope this helps.
Peter
06-17-2022 10:09 AM - edited 06-17-2022 10:11 AM
Hi Peter,
Not sure if this is what you are looking for but sharing in hopes it helps:
Using the following Catalyst 9K & XE version:
cat9k#show module Switch Ports Model Serial No. MAC address Hw Ver. Sw Ver. ------ ----- --------- ----------- -------------- ------- -------- 1 65 C9300-48T XXXXXXXXXXX acf5.e65d.e580 V02 17.03.03
Sample VLAN configured:
cat9k#show vlan brief
VLAN Name Status Ports ---- -------------------------------- --------- ------------------------------- 4000 AppHosting-VLAN active Gi1/0/1
Confirming I can see this via RESTCONF:
GET https://{{ip_address}}}:443/restconf/data/Cisco-IOS-XE-native:native/vlan
Response:
{ "Cisco-IOS-XE-native:vlan": { "Cisco-IOS-XE-vlan:vlan-list": [ { "id": 4000, "name": "AppHosting-VLAN" } ] } }
Adding three new VLANs for testing purposes via RESTCONF. VLAN 171, 172 and 173.
POST https://{{ip_address}}:443/restconf/data/Cisco-IOS-XE-native:native/vlan
Body:
{ "Cisco-IOS-XE-vlan:vlan-list": [ { "id": 171, "name": "CiscoForum" }, { "id": 172, "name": "DevTest" }, { "id": 173, "name": "Example" } ] }
Confirming the three new VLANs, plus the previously existing VLAN (4000), appear in the response body:
Via RESTCONF:
GET https://{{ip_address}}}:443/restconf/data/Cisco-IOS-XE-native:native/vlan
Response:
{ "Cisco-IOS-XE-native:vlan": { "Cisco-IOS-XE-vlan:vlan-list": [ { "id": 171, "name": "CiscoForum" }, { "id": 172, "name": "DevTest" }, { "id": 173, "name": "Example" }, { "id": 4000, "name": "AppHosting-VLAN" } ] } }
Via CLI:
cat9k#show vlan brief VLAN Name Status Ports ---- -------------------------------- --------- ------------------------------- <snip> 171 CiscoForum active 172 DevTest active VLAN Name Status Ports ---- -------------------------------- --------- ------------------------------- 173 Example active 4000 AppHosting-VLAN active Gi1/0/1
Is this what you were looking for?
06-17-2022 10:26 AM
Hei Andrea
Thats exactly what I'm looking for however the only real difference I can see between the URL you are using and the one I am using is the port 443, which is the default for https anyway. I was using software 17.3.4 when I posted this but I have since upgraded to 17.6.3. without any effect. I have even tried NETCONF as well. What I am not seeing which I assume you are, is if i send the follwoing url.
GET https://<ip address>/restconf/data/Cisco-IOS-XE-native:native
I should get back the entire configuration including the vlans, however I don't get the vlan sub section in the json response.
I have tried the same url on a cat 3650 and a cat 9200 and the url works, so I guess I'm hitting a bug og some other problem on my cat 9300. I am using a cat C9300-48P.
Peter
06-17-2022 11:34 AM
Peter,
I just tested out of my own curiosity without specifying port :443 in the URL thinking some odd bug indeed; however, my responses are still complete/correct.
I then tested the URL you shared (which returns the entire configuration) but in my case, I do see the VLAN DB as part of the JSON response. It is right after the VRF/DNS portions in the body:
"vlan": { "Cisco-IOS-XE-vlan:vlan-list": [ { "id": 171, "name": "CiscoForum" }, { "id": 172, "name": "DevTest" }, { "id": 173, "name": "Example" }, { "id": 4000, "name": "AppHosting-VLAN" } ] },
I'll upgrade my C9K to 17.6.3 to make sure there's no behavioral changes there. Having that said:
1 - What do your headers look like for the GET request?
2- Could you share your Python script and/or CURL/Postman outputs? (want to make sure we are apples to apples)
Below my sample:
import requests url = "https://10.10.20.100/restconf/data/Cisco-IOS-XE-native:native" payload={} headers = { 'Accept': 'application/yang-data+json, application/yang-data.errors+json', 'Authorization': 'Basic ZGV2ZWxvcGVyOkMxc2NvMTIzNDU=' } response = requests.request("GET", url, headers=headers, data=payload) print(response.text)
Thanks!
06-20-2022 12:31 AM
Hei Andrea
I have found the solution. It's not the url or restconf that's the problem. I tested on another switch and I noticed that vlans over 1005 where displayed in the configuration and the vlan container. Looking at my original switch the sh running on the switch doesn't show any vlans either. The solution appears to be to disable vtp og put it in transparent mode and then the vlans appear. The only issue I had after doing this was that the vlan names didn't display so I recommend disabling vtp before enabling restconf.
Do you know of a yang model that access the vlan database and not the configuration?
06-22-2022 06:30 AM
Peter,
GET https://{{ip_address}}/restconf/data/Cisco-IOS-XE-vlan-oper:vlans/vlan
C9K-Dev-Test#show vtp status VTP Version capable : 1 to 3 VTP version running : 1 VTP Domain Name : VTP Pruning Mode : Disabled VTP Traps Generation : Disabled Device ID : 701f.53b9.6d80 Configuration last modified by 10.201.168.181 at 6-22-22 12:43:37 Local updater ID is 10.201.168.181 on interface Gi0/0 (first layer3 interface found) Feature VLAN: -------------- VTP Operating Mode : Server Maximum VLANs supported locally : 1005 Number of existing VLANs : 7 Configuration Revision : 2 MD5 digest : 0x45 0x29 0x47 0xB6 0x5E 0x8B 0xF3 0xAF 0xE0 0x3E 0xE8 0xBE 0xB2 0xC8 0xD0 0x49
C9K-Dev-Test#show run | sec vlan vlan 1010 name Test-1010 vlan 1200 name Test-1200
C9K-Dev-Test#show vlan brief VLAN Name Status Ports ---- -------------------------------- --------- ------------------------------- <snip> 5 Test-5 active 7 Test-7 active 1002 fddi-default act/unsup 1003 token-ring-default act/unsup 1004 fddinet-default act/unsup 1005 trnet-default act/unsup 1010 Test-1010 active 1200 Test-1200 active
atestini@ATESTINI-M-26WU YANG % curl -k --request GET 'https://10.201.168.181/restconf/data/Cisco-IOS-XE-vlan-oper:vlans/vlan' \ --header 'Accept: application/yang-data+json, application/yang-data.errors+json' \ --header 'Authorization: Basic YWRtaW46Y2lzY28hMTIz' { "Cisco-IOS-XE-vlan-oper:vlan": [ { "id": 1, "name": "default", "status": "active", "vlan-interfaces": [ { "interface": "GigabitEthernet1/0/1", "subinterface": 0 ## snipping output here for brevity ## ] }, { "id": 5, "name": "Test-5", "status": "active" }, { "id": 7, "name": "Test-7", "status": "active" }, { "id": 1002, "name": "fddi-default", "status": "suspend" }, { "id": 1003, "name": "token-ring-default", "status": "suspend" }, { "id": 1004, "name": "fddinet-default", "status": "suspend" }, { "id": 1005, "name": "trnet-default", "status": "suspend" }, { "id": 1010, "name": "Test-1010", "status": "active" }, { "id": 1200, "name": "Test-1200", "status": "active" } ] }
06-22-2022 06:45 AM
Hei Andrea
Thanks for the info very useful if some what irritating. My purpose was to add a vlan to the configuration and the vlan-oper doesn't allow that as suggested by the name. What is also irritating is that if vlans don't appear in the configuration you can't post a request to the switch to update a vlan. If the switch is a vtp server (default) the you should be allowed to create vlans. I also noted that you can't turn off vtp using rest as being deafult the vtp section doesn't appear in the configuration.
Via cli you have the possibility to issue show configuration all which shows all the defaults and should at least include vtp. The Cisco-IOS-XE-native should ideally collect that configuration and not the non default config. This would make things a lot easier. It would be useful if the yang model mention it in the documentation or description field that vtp needs to be off or transparent mode.
Thanks again for the information.
Peter
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