Skip to content

Commit 7507d09

Browse files
authored
Merge branch 'master' into f-rename-spark-to-webex
2 parents cc09093 + 67fe70f commit 7507d09

7 files changed

Lines changed: 197 additions & 19 deletions

File tree

env_lab.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,19 @@
4848
# Set the 'Environment Variables' based on the lab environment in use
4949
if ENVIRONMENT_IN_USE == "sandbox":
5050
DNA_CENTER = {
51-
"host": "sandboxdnac2.cisco.com",
52-
"username": "dnacdev",
53-
"password": "D3v93T@wK!"
51+
"host": "sandboxdnac.cisco.com",
52+
"username": "devnetuser",
53+
"password": "Cisco123!"
5454
}
5555

5656
# Values for the Always On IOS XE Sandbox
5757
IOS_XE_1 = {
58-
"host": "ios-xe-mgmt.cisco.com",
58+
"host": "sandbox-iosxe-recomm-1.cisco.com",
5959
"username": "developer",
6060
"password": "C1sco12345",
61-
"netconf_port": 10000,
62-
"restconf_port": 9443,
63-
"ssh_port": 8181
61+
"netconf_port": 830,
62+
"restconf_port": 443,
63+
"ssh_port": 22
6464
}
6565

6666
# Values for the Reservable IOS XE Sandbox
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
ansible_user: developer
2-
ansible_ssh_pass: C1sco12345
3-
ansible_port: 8181
4-
netconf_port: 10000
5-
1+
ansible_user: 'developer'
2+
ansible_ssh_pass: 'C1sco12345'
3+
ansible_port: 22
4+
netconf_port: 830

intro-ansible/hosts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ sandbox
2323
#express
2424

2525
[sandbox]
26-
ios-xe-mgmt.cisco.com ansible_port=8181
26+
sandbox-iosxe-recomm-1.cisco.com ansible_port=22
2727

2828
[express]
2929
198.18.134.11 # dcloud pod router #1
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env python
2+
from __future__ import print_function
3+
import sys
4+
import json
5+
from util import get_url
6+
7+
def list_single_device(ip):
8+
return get_url("network-device/ip-address/%s" % ip)
9+
10+
def list_network_devices():
11+
return get_url("network-device")
12+
13+
if __name__ == "__main__":
14+
if len(sys.argv) > 1:
15+
response = list_single_device(sys.argv[1])
16+
print(json.dumps(response, indent=2))
17+
else:
18+
response = list_network_devices()
19+
print("{0:42}{1:17}{2:12}{3:18}{4:12}{5:16}{6:15}".
20+
format("hostname","mgmt IP","serial",
21+
"platformId","SW Version","role","Uptime"))
22+
23+
for device in response['response']:
24+
uptime = "N/A" if device['upTime'] is None else device['upTime']
25+
26+
# this is for the case of switch stacks.. multiple serial and model numbers
27+
if device['serialNumber'] is not None and "," in device['serialNumber']:
28+
serialPlatformList = zip(device['serialNumber'].split(","), device['platformId'].split(","))
29+
else:
30+
serialPlatformList = [(device['serialNumber'], device['platformId'])]
31+
for (serialNumber,platformId) in serialPlatformList:
32+
print("{0:42}{1:17}{2:12}{3:18}{4:12}{5:16}{6:15}".
33+
format(device['hostname'],
34+
device['managementIpAddress'],
35+
serialNumber,
36+
platformId,
37+
device['softwareVersion'],
38+
device['role'],uptime))
39+

intro-dnac/04_Cmd_Runner/cmd_runner.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import requests
22
import json
3+
import logging
34
from requests.auth import HTTPBasicAuth
45
import os
56
import sys
@@ -31,7 +32,11 @@ def get_auth_token():
3132
"""
3233
url = 'https://{}/dna/system/api/v1/auth/token'.format(DNAC_URL) # Endpoint URL
3334
hdr = {'content-type' : 'application/json'} # Define request header
34-
resp = requests.post(url, auth=HTTPBasicAuth(DNAC_USER, DNAC_PASS), headers=hdr) # Make the POST Request
35+
try:
36+
logging.captureWarnings(True)
37+
resp = requests.post(url, auth=HTTPBasicAuth(DNAC_USER, DNAC_PASS), headers=hdr, verify=False) # Make the POST Request
38+
except Exception as e:
39+
print("Error: ", e)
3540
token = resp.json()['Token'] # Retrieve the Token
3641
return token # Create a return statement to send the token back for later use
3742

@@ -43,7 +48,8 @@ def get_device_list():
4348
token = get_auth_token() # Get Token
4449
url = "https://{}/api/v1/network-device/1/4".format(DNAC_URL)
4550
hdr = {'x-auth-token': token, 'content-type' : 'application/json'}
46-
resp = requests.get(url, headers=hdr) # Make the Get Request
51+
logging.captureWarnings(True)
52+
resp = requests.get(url, headers=hdr, verify=False) # Make the Get Request
4753
device_list = resp.json()
4854
print("{0:25}{1:25}".format("hostname", "id"))
4955
for device in device_list['response']:
@@ -62,7 +68,8 @@ def initiate_cmd_runner(token):
6268
}
6369
url = "https://{}/api/v1/network-device-poller/cli/read-request".format(DNAC_URL)
6470
header = {'content-type': 'application/json', 'x-auth-token': token}
65-
response = requests.post(url, data=json.dumps(param), headers=header)
71+
logging.captureWarnings(True)
72+
response = requests.post(url, data=json.dumps(param), headers=header, verify=False)
6673
task_id = response.json()['response']['taskId']
6774
print("Command runner Initiated! Task ID --> ", task_id)
6875
print("Retrieving Path Trace Results.... ")
@@ -72,7 +79,8 @@ def initiate_cmd_runner(token):
7279
def get_task_info(task_id, token):
7380
url = "https://{}/api/v1/task/{}".format(DNAC_URL, task_id)
7481
hdr = {'x-auth-token': token, 'content-type' : 'application/json'}
75-
task_result = requests.get(url, headers=hdr)
82+
logging.captureWarnings(True)
83+
task_result = requests.get(url, headers=hdr, verify=False)
7684
file_id = task_result.json()['response']['progress']
7785
if "fileId" in file_id:
7886
unwanted_chars = '{"}'
@@ -89,7 +97,8 @@ def get_task_info(task_id, token):
8997
def get_cmd_output(token,file_id):
9098
url = "https://{}/api/v1/file/{}".format(DNAC_URL, file_id)
9199
hdr = {'x-auth-token': token, 'content-type': 'application/json'}
92-
cmd_result = requests.get(url, headers=hdr)
100+
logging.captureWarnings(True)
101+
cmd_result = requests.get(url, headers=hdr, verify=False)
93102
print(json.dumps(cmd_result.json(), indent=4, sort_keys=True))
94103

95104

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
"""Set the Environment Information Needed to Access Your Lab!
2+
3+
The provided sample code in this repository will reference this file to get the
4+
information needed to connect to your lab backend. You provide this info here
5+
once and the scripts in this repository will access it as needed by the lab.
6+
7+
8+
Copyright (c) 2018-2022 Cisco and/or its affiliates.
9+
10+
Permission is hereby granted, free of charge, to any person obtaining a copy
11+
of this software and associated documentation files (the "Software"), to deal
12+
in the Software without restriction, including without limitation the rights
13+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14+
copies of the Software, and to permit persons to whom the Software is
15+
furnished to do so, subject to the following conditions:
16+
17+
The above copyright notice and this permission notice shall be included in all
18+
copies or substantial portions of the Software.
19+
20+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26+
SOFTWARE.
27+
"""
28+
29+
30+
# User Input
31+
32+
# Please select the lab environment that you will be using today
33+
# sandbox - Cisco DevNet Always-On / Reserved Sandboxes
34+
# express - Cisco DevNet Express Lab Backend
35+
# custom - Your Own "Custom" Lab Backend
36+
ENVIRONMENT_IN_USE = "sandbox"
37+
38+
# Custom Lab Backend
39+
DNA_CENTER = {
40+
"host": "",
41+
"username": "",
42+
"password": ""
43+
}
44+
45+
# End User Input
46+
47+
48+
# Set the 'Environment Variables' based on the lab environment in use
49+
if ENVIRONMENT_IN_USE == "sandbox":
50+
DNA_CENTER = {
51+
"host": "sandboxdnac.cisco.com",
52+
"username": "devnetuser",
53+
"password": "Cisco123!"
54+
}
55+
56+
# Values for the Always On IOS XE Sandbox
57+
IOS_XE_1 = {
58+
"host": "sandbox-iosxe-recomm-1.cisco.com",
59+
"username": "developer",
60+
"password": "C1sco12345",
61+
"netconf_port": 830,
62+
"restconf_port": 443,
63+
"ssh_port": 22
64+
}
65+
66+
# Values for the Reservable IOS XE Sandbox
67+
IOS_XE_2 = {
68+
"host": "10.10.20.48",
69+
"username": "developer",
70+
"password": "C1sco12345",
71+
"netconf_port": 830,
72+
"restconf_port": 443,
73+
"ssh_port": 22
74+
}
75+
76+
# Values for the Always On NX-OS Sandbox
77+
NXOS_1 = {
78+
"host": "sbx-nxos-mgmt.cisco.com",
79+
"username": "admin",
80+
"password": "Admin_1234!",
81+
"netconf_port": 10000,
82+
"restconf_port": 443,
83+
"nxapi_port": 80,
84+
"ssh_port": 8181
85+
}
86+
87+
elif ENVIRONMENT_IN_USE == "express":
88+
DNA_CENTER = {
89+
"host": "sandboxdnac2.cisco.com",
90+
"port": 443,
91+
"username": "dnacdev",
92+
"password": "D3v93T@wK!"
93+
}
94+
95+
NFVIS_SERVER = {
96+
"host": "198.18.134.46",
97+
"port": 443,
98+
"username": "admin",
99+
"password": "C1sco12345_"
100+
}
101+
102+
# Values for the CSR1 from the dCloud Pod
103+
IOS_XE_1 = {
104+
"host": "198.18.134.11",
105+
"username": "admin",
106+
"password": "C1sco12345",
107+
"netconf_port": 830,
108+
"restconf_port": 443,
109+
"ssh_port": 22
110+
}
111+
112+
# Values for the CSR2 from the dCloud Pod
113+
IOS_XE_2 = {
114+
"host": "198.18.134.12",
115+
"username": "admin",
116+
"password": "C1sco12345",
117+
"netconf_port": 830,
118+
"restconf_port": 443,
119+
"ssh_port": 22
120+
}
121+
122+
# Values for the Always On NX-OS Sandbox
123+
NXOS_1 = {
124+
"host": "sbx-nxos-mgmt.cisco.com",
125+
"username": "admin",
126+
"password": "Admin_1234!",
127+
"netconf_port": 10000,
128+
"restconf_port": 443,
129+
"nxapi_port": 80,
130+
"ssh_port": 8181
131+
}

intro-mdp/netconf/get_interface_list.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
# Create an XML filter for targeted NETCONF queries
4545
netconf_filter = """
46-
<filter>
46+
<filter xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
4747
<interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
4848
<interface></interface>
4949
</interfaces>

0 commit comments

Comments
 (0)