diff --git a/yang/netconf/get_capabilities.py b/yang/netconf/get_capabilities.py index 9244074..086f238 100644 --- a/yang/netconf/get_capabilities.py +++ b/yang/netconf/get_capabilities.py @@ -6,9 +6,9 @@ # the variables below assume the user is leveraging the # always on sandbox. -HOST = 'ios-xe-mgmt.cisco.com' +HOST = 'sandbox-iosxe-latest-1.cisco.com' # use the NETCONF port for your IOS-XE device -PORT = 10000 +PORT = 830 # use the user credentials for your IOS-XE device USER = 'developer' PASS = 'C1sco12345' diff --git a/yang/netconf/get_hostname.py b/yang/netconf/get_hostname.py index 3b56eec..3270390 100644 --- a/yang/netconf/get_hostname.py +++ b/yang/netconf/get_hostname.py @@ -8,9 +8,9 @@ # the variables below assume the user is leveraging the # always on sandbox. -HOST = 'ios-xe-mgmt.cisco.com' +HOST = 'sandbox-iosxe-latest-1.cisco.com' # use the NETCONF port for your IOS-XE device -PORT = 10000 +PORT = 830 # use the user credentials for your IOS-XE device USER = 'developer' PASS = 'C1sco12345' diff --git a/yang/netconf/get_interfaces_config.py b/yang/netconf/get_interfaces_config.py index b0e0d29..919c11c 100644 --- a/yang/netconf/get_interfaces_config.py +++ b/yang/netconf/get_interfaces_config.py @@ -12,9 +12,9 @@ # the variables below assume the user is leveraging the # always on sandbox. -HOST = 'ios-xe-mgmt.cisco.com' +HOST = 'sandbox-iosxe-latest-1.cisco.com' # use the NETCONF port for your IOS-XE device -PORT = 10000 +PORT = 830 # use the user credentials for your IOS-XE device USER = 'developer' PASS = 'C1sco12345' diff --git a/yang/restconf/create_loopback.py b/yang/restconf/create_loopback.py new file mode 100644 index 0000000..851c0db --- /dev/null +++ b/yang/restconf/create_loopback.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python + +import requests +import json +import sys + + +# the variables below assume the user is leveraging the +# always on sandbox. +HOST = 'sandbox-iosxe-latest-1.cisco.com' +# use the RESTCONF port for your IOS-XE device +PORT = 443 +# use the user credentials for your IOS-XE device +USER = 'developer' +PASS = 'C1sco12345' + + +def main(): + url = f"https://{HOST}:{PORT}/restconf/data/ietf-interfaces:interfaces" + headers = { + 'Accept': 'application/yang-data+json', + 'Content-Type': 'application/yang-data+json', + } + payload = json.dumps({ + "ietf-interfaces:interface": { + "name": "Loopback800", + "description": "Added using RESTCONF", + "type": "iana-if-type:softwareLoopback", + "enabled": True, + "ietf-ip:ipv4": { + "address": [ + { + "ip": "88.88.88.80", + "netmask": "255.255.255.255" + } + ] + } + } + }) + + response = requests.post(url, headers=headers, data=payload, auth=(USER,PASS), verify=False) + if response.ok: + print(response.status_code) + print("Loopback created. Use the get_loopback or get_interfaces_config module to verify.") + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/yang/restconf/create_user.py b/yang/restconf/create_user.py new file mode 100644 index 0000000..602ed14 --- /dev/null +++ b/yang/restconf/create_user.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python + +import requests +import json +import sys + + +# the variables below assume the user is leveraging the +# always on sandbox. +HOST = 'sandbox-iosxe-latest-1.cisco.com' +# use the RESTCONF port for your IOS-XE device +PORT = 443 +# use the user credentials for your IOS-XE device +USER = 'developer' +PASS = 'C1sco12345' + + +def main(): + url = f"https://{HOST}:{PORT}/restconf/data/Cisco-IOS-XE-native:native/" + headers = { + 'Content-Type': 'application/yang-data+json', + 'Accept': 'application/yang-data+json', + } + payload = json.dumps( + { + "Cisco-IOS-XE-native:username": [ + { + "name": "restconfuser", + "privilege": 15, + "password": { + "password": "rEStc0n4us3rpas$woRd!" + } + } + ] + } + ) + + response = requests.post(url, headers=headers, data=payload, verify=False, auth=(USER, PASS)) + if response.ok: + print(response.status_code) + print("User created. Use the get_configured_users module to verify.") + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/yang/restconf/delete_loopback.py b/yang/restconf/delete_loopback.py new file mode 100644 index 0000000..9d2c8c9 --- /dev/null +++ b/yang/restconf/delete_loopback.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python + +import requests +import sys + + +# the variables below assume the user is leveraging the +# always on sandbox. +HOST = 'sandbox-iosxe-latest-1.cisco.com' +# use the RESTCONF port for your IOS-XE device +PORT = 443 +# use the user credentials for your IOS-XE device +USER = 'developer' +PASS = 'C1sco12345' + + +def main(): + url = f"https://{HOST}:{PORT}/restconf/data/ietf-interfaces:interfaces/interface=Loopback800" + headers = { + 'Accept': 'application/yang-data+json', + 'Content-Type': 'application/yang-data+json', + } + + response = requests.delete(url, headers=headers, auth=(USER,PASS), verify=False) + if response.ok: + print(response.status_code) + print("Loopback deleted. Use the get_loopback or get_interfaces_config module to verify.") + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/yang/restconf/get_capabilities.py b/yang/restconf/get_capabilities.py new file mode 100644 index 0000000..9cda2c9 --- /dev/null +++ b/yang/restconf/get_capabilities.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python + +import requests +import json +import sys + + +# the variables below assume the user is leveraging the +# always on sandbox. +HOST = 'sandbox-iosxe-latest-1.cisco.com' +# use the RESTCONF port for your IOS-XE device +PORT = 443 +# use the user credentials for your IOS-XE device +USER = 'developer' +PASS = 'C1sco12345' + + +def main(): + url = f"https://{HOST}:{PORT}/restconf/data/netconf-state/capabilities" + headers = { + 'Content-Type': 'application/yang-data+json', + 'Accept': 'application/yang-data+json', + } + + response = requests.get(url, headers=headers, verify=False, auth=(USER, PASS)).json() + print(json.dumps(response, indent=2)) + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/yang/restconf/get_configured_users.py b/yang/restconf/get_configured_users.py new file mode 100644 index 0000000..4546ddc --- /dev/null +++ b/yang/restconf/get_configured_users.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python + +import requests +import json +import sys + + +# the variables below assume the user is leveraging the +# always on sandbox. +HOST = 'sandbox-iosxe-latest-1.cisco.com' +# use the RESTCONF port for your IOS-XE device +PORT = 443 +# use the user credentials for your IOS-XE device +USER = 'developer' +PASS = 'C1sco12345' + + +def main(): + url = f"https://{HOST}:{PORT}/restconf/data/Cisco-IOS-XE-native:native/username" + headers = { + 'Content-Type': 'application/yang-data+json', + 'Accept': 'application/yang-data+json', + } + + response = requests.get(url, headers=headers, verify=False, auth=(USER, PASS)).json() + print(json.dumps(response, indent=2)) + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/yang/restconf/get_hostname.py b/yang/restconf/get_hostname.py new file mode 100644 index 0000000..cc3bd56 --- /dev/null +++ b/yang/restconf/get_hostname.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python + +import requests +import json +import sys + + +# the variables below assume the user is leveraging the +# always on sandbox. +HOST = 'sandbox-iosxe-latest-1.cisco.com' +# use the RESTCONF port for your IOS-XE device +PORT = 443 +# use the user credentials for your IOS-XE device +USER = 'developer' +PASS = 'C1sco12345' + + +def main(): + url = f"https://{HOST}:{PORT}/restconf/data/Cisco-IOS-XE-native:native/hostname" + headers = { + 'Content-Type': 'application/yang-data+json', + 'Accept': 'application/yang-data+json', + } + + response = requests.get(url, headers=headers, verify=False, auth=(USER, PASS)).json() + print(json.dumps(response, indent=2)) + print(f"Hostname:", response["Cisco-IOS-XE-native:hostname"]) + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/yang/restconf/get_interfaces_config.py b/yang/restconf/get_interfaces_config.py new file mode 100644 index 0000000..10b2957 --- /dev/null +++ b/yang/restconf/get_interfaces_config.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python + +import requests +import json +import sys + + +# the variables below assume the user is leveraging the +# always on sandbox. +HOST = 'sandbox-iosxe-latest-1.cisco.com' +# use the RESTCONF port for your IOS-XE device +PORT = 443 +# use the user credentials for your IOS-XE device +USER = 'developer' +PASS = 'C1sco12345' + + +def main(): + url = f"https://{HOST}:{PORT}/restconf/data/ietf-interfaces:interfaces" + headers = { + 'Content-Type': 'application/yang-data+json', + 'Accept': 'application/yang-data+json', + } + + response = requests.get(url, headers=headers, verify=False, auth=(USER, PASS)).json() + print(json.dumps(response, indent=2)) + + interface_list = response["ietf-interfaces:interfaces"]["interface"] + for interface in interface_list: + print(interface["name"]) + + +if __name__ == '__main__': + sys.exit(main()) + diff --git a/yang/restconf/get_loopback.py b/yang/restconf/get_loopback.py new file mode 100644 index 0000000..dfc48ee --- /dev/null +++ b/yang/restconf/get_loopback.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python + +import requests +import json +import sys + + +# the variables below assume the user is leveraging the +# always on sandbox. +HOST = 'sandbox-iosxe-latest-1.cisco.com' +# use the RESTCONF port for your IOS-XE device +PORT = 443 +# use the user credentials for your IOS-XE device +USER = 'developer' +PASS = 'C1sco12345' + + +def main(): + url = f"https://{HOST}:{PORT}/restconf/data/ietf-interfaces:interfaces/interface=Loopback800" + headers = { + 'Accept': 'application/yang-data+json', + 'Content-Type': 'application/yang-data+json', + } + + response = requests.get(url, headers=headers, auth=(USER,PASS), verify=False) + if response.ok: + print(json.dumps(response.json(), indent=2)) + + +if __name__ == '__main__': + sys.exit(main())