Skip to content

Commit 22aa13e

Browse files
authored
Merge branch 'master' into master
2 parents 0b01413 + e2307c9 commit 22aa13e

File tree

7 files changed

+109
-9
lines changed

7 files changed

+109
-9
lines changed

RC-get-serial-numbers/RC-get-sns.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/usr/bin/env python
2+
#
3+
# Copyright (c) 2019 Joe Clarke <[email protected]>
4+
# All rights reserved.
5+
#
6+
# Redistribution and use in source and binary forms, with or without
7+
# modification, are permitted provided that the following conditions
8+
# are met:
9+
# 1. Redistributions of source code must retain the above copyright
10+
# notice, this list of conditions and the following disclaimer.
11+
# 2. Redistributions in binary form must reproduce the above copyright
12+
# notice, this list of conditions and the following disclaimer in the
13+
# documentation and/or other materials provided with the distribution.
14+
#
15+
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16+
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18+
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21+
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22+
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23+
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24+
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25+
# SUCH DAMAGE.
26+
#
27+
# This script retrieves inventory from devices with RESTCONF and prints all serial
28+
# numbers per device.
29+
#
30+
31+
import requests
32+
from argparse import ArgumentParser
33+
34+
35+
def main():
36+
37+
parser = ArgumentParser(description='Select options.')
38+
39+
# Input parameters
40+
parser.add_argument('-hosts', '--hosts', type=str, required=True,
41+
help="Comma-separated list of devices")
42+
parser.add_argument('-user', '--username', type=str, default='cisco',
43+
help="User credentials for the request")
44+
parser.add_argument('-passwd', '--password', type=str, default='cisco',
45+
help="It's the password")
46+
47+
args = parser.parse_args()
48+
url = 'https://{}/restconf/data/Cisco-IOS-XE-device-hardware-oper:device-hardware-data/device-hardware'
49+
inv_cache = {}
50+
51+
hosts = args.hosts.split(',')
52+
53+
for host in hosts:
54+
55+
u = url.format(host)
56+
57+
headers = {
58+
'Accept': "application/yang-data+json",
59+
}
60+
61+
response = None
62+
63+
try:
64+
response = requests.request('GET', u, auth=(
65+
args.username, args.password), headers=headers, verify=False)
66+
response.raise_for_status()
67+
except Exception as e:
68+
print('Failed to get inventory from device: {}'.format(e))
69+
continue
70+
71+
inv = response.json()
72+
73+
for asset in inv['Cisco-IOS-XE-device-hardware-oper:device-hardware']['device-inventory']:
74+
if host not in inv_cache:
75+
inv_cache[host] = []
76+
77+
if asset['serial-number'] == '':
78+
continue
79+
80+
inv_cache[host].append(
81+
{'sn': asset['serial-number'], 'pn': asset['part-number']})
82+
83+
for host, comps in inv_cache.items():
84+
print('Host {} serial numbers:'.format(host))
85+
for comp in comps:
86+
print('\t{}'.format(comp['sn']))
87+
88+
89+
if __name__ == '__main__':
90+
main()

RC-get-serial-numbers/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# RESTCONF get-serial-numbers
2+
3+
This is an example Python script that retrieves the serial numbers of IOS-XE devices and prints
4+
each device with its collection of serial numbers.
5+
6+
# requirements
7+
-- IOS-XE running >/= 16.3.1 also enabled for RESTCONF
8+
9+
# running
10+
-- Can run on-box or off-box.

acitoolkit_show_tenants/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ To run this script, you'll need to have installed the ACI Toolkit in your workin
1212

1313
This script targets the Always On ACI Simulator DevNet Sandbox.
1414

15-
Find details on the Sandbox [here](https://developer.cisco.com/site/devnet/sandbox/available-labs/data-center/index.gsp).
15+
Find details on the Sandbox [here](https://developer.cisco.com/docs/sandbox/#!data-center).
1616

1717
To execute this script against a different device, update the variables that list the URL, User and Password for the APIC.
1818

@@ -26,7 +26,7 @@ To execute this script against a different device, update the variables that lis
2626
* Clone the Python Examples and change into the directory.
2727

2828
```bash
29-
git clone //github.com/CiscoDevNet/python_code_samples_network
29+
git clone https://github.com/CiscoDevNet/python_code_samples_network
3030
cd acitoolkit_show_tenants
3131
```
3232

acitoolkit_show_tenants/aci-show-tenants.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
of the Tenants.
55
66
Leverages the DevNet Sandbox - APIC Simulator Always On
7-
Information at https://developer.cisco.com/site/devnet/sandbox/available-labs/data-center/index.gsp
7+
Information at https://developer.cisco.com/docs/sandbox/#!data-center
88
99
Code sample based off the ACI-Toolkit Code sample
1010
@@ -41,4 +41,4 @@ def main():
4141
print(tenant.name)
4242

4343
if __name__ == '__main__':
44-
main()
44+
main()

apic-em_get_hosts/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This script has been tested with Python 3.5, however may work with other version
88

99
This script targets the Always On APIC-EM DevNet Sandbox.
1010

11-
Find details on the Sandbox [here](https://developer.cisco.com/site/devnet/sandbox/available-labs/networking/).
11+
Find details on the Sandbox [here](https://developer.cisco.com/docs/sandbox/#!networking).
1212

1313
To execute this script against a different device, update the variables that list the APIC-EM IP, User and Password.
1414

@@ -23,7 +23,7 @@ Python
2323
* Clone the Python Examples and change into the directory.
2424

2525
```bash
26-
git clone //github.com/CiscoDevNet/python_code_samples_network
26+
git clone https://github.com/CiscoDevNet/python_code_samples_network
2727
cd apic-em_get_hosts
2828
```
2929

apic-em_get_hosts/gethosts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
of the clients connected.
55
66
Leverages the DevNet Sandbox - APIC-EM Always On
7-
Information at https://developer.cisco.com/site/devnet/sandbox/available-labs/networking/
7+
Information at https://developer.cisco.com/docs/sandbox/#!networking
88
99
"""
1010

restconf_update_ipaddress/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ This script has been tested with Python 3.5, however may work with other version
1616

1717
This script targets the RESTCONF DevNet Sandbox that leverages a CSR1000v as a target.
1818

19-
Find details on the Sandbox [here](https://developer.cisco.com/site/devnet/sandbox/available-labs/networking/).
19+
Find details on the Sandbox [here](https://developer.cisco.com/docs/sandbox/#!networking).
2020

2121
To execute this script against a different device, update the variables that list the connectivity, management interface, and url_base for RESTCONF.
2222

@@ -31,7 +31,7 @@ Python
3131
* Clone the Python Examples and change into the directory.
3232

3333
```bash
34-
git clone //github.com/CiscoDevNet/python_code_samples_network
34+
git clone https://github.com/CiscoDevNet/python_code_samples_network
3535
cd restconf_update_ipaddress
3636
```
3737

0 commit comments

Comments
 (0)