Skip to content

Updated sandbox info with current info and added restconf examples #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions yang/netconf/get_capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 2 additions & 2 deletions yang/netconf/get_hostname.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 2 additions & 2 deletions yang/netconf/get_interfaces_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
48 changes: 48 additions & 0 deletions yang/restconf/create_loopback.py
Original file line number Diff line number Diff line change
@@ -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())
45 changes: 45 additions & 0 deletions yang/restconf/create_user.py
Original file line number Diff line number Diff line change
@@ -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())
31 changes: 31 additions & 0 deletions yang/restconf/delete_loopback.py
Original file line number Diff line number Diff line change
@@ -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())
30 changes: 30 additions & 0 deletions yang/restconf/get_capabilities.py
Original file line number Diff line number Diff line change
@@ -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())
30 changes: 30 additions & 0 deletions yang/restconf/get_configured_users.py
Original file line number Diff line number Diff line change
@@ -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())
31 changes: 31 additions & 0 deletions yang/restconf/get_hostname.py
Original file line number Diff line number Diff line change
@@ -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())
35 changes: 35 additions & 0 deletions yang/restconf/get_interfaces_config.py
Original file line number Diff line number Diff line change
@@ -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())

31 changes: 31 additions & 0 deletions yang/restconf/get_loopback.py
Original file line number Diff line number Diff line change
@@ -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())