Skip to content

Commit ae29d63

Browse files
committed
Update for SBX and 8040
2 parents 46471fb + 920fb3d commit ae29d63

File tree

7 files changed

+69
-26
lines changed

7 files changed

+69
-26
lines changed

NC-edit-config/NC-edit-config-hostname.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
data = '''
3636
<config>
37-
<native xmlns="http://cisco.com/ns/yang/ned/ios">
37+
<native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">
3838
<hostname>NC-WAS-HERE</hostname>
3939
</native>
4040
</config>
@@ -59,4 +59,4 @@
5959
device_params={'name':"csr"})
6060
# Pretty print the XML reply
6161
xmlDom = xml.dom.minidom.parseString( str( m.edit_config(data, target='running') ) )
62-
print xmlDom.toprettyxml( indent = " " )
62+
print xmlDom.toprettyxml( indent = " " )

NC-edit-config/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ For fun, you'll realize the script reconfigures the hostname of your network ele
99
# requirements
1010
-- ncclient
1111

12-
-- IOS-XE running >/= 16.3.1 also enabled for NETCONF
12+
-- IOS-XE running >/= 16.5(1) also enabled for NETCONF
1313

1414
# running
15-
-- Can run on-box or off-box.
15+
-- Can run on-box or off-box.

NC-get-config/NC-get-config.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2525
# SUCH DAMAGE.
2626
#
27-
# This script retrieves entire configuration from a network element via NETCONF
27+
# This script retrieves entire configuration from a network element via NETCONF
2828
# prints it out in a "pretty" XML tree.
2929

3030
import sys
@@ -44,14 +44,20 @@
4444
parser.add_argument('--port', type=int, default=830,
4545
help="Specify this if you want a non-default port")
4646
args = parser.parse_args()
47-
47+
4848
m = manager.connect(host=args.host,
4949
port=args.port,
5050
username=args.username,
5151
password=args.password,
5252
device_params={'name':"csr"})
53-
# Pretty print the XML reply
54-
xmlDom = xml.dom.minidom.parseString( str( m.get_config(source='running')))
55-
print xmlDom.toprettyxml( indent = " " )
5653

54+
hostname_filter = '''
55+
<filter>
56+
<native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">
57+
</native>
58+
</filter>
59+
'''
5760

61+
# Pretty print the XML reply
62+
xmlDom = xml.dom.minidom.parseString( str( m.get_config('running', hostname_filter)))
63+
print(xmlDom.toprettyxml( indent = " " ))

RC-get-config/RC-get-config.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
# prints it out in a "pretty" XML tree.
2929

3030
from argparse import ArgumentParser
31-
from ncclient import manager
3231
import requests
3332

3433
if __name__ == '__main__':
@@ -42,7 +41,7 @@
4241
help="User credentials for the request")
4342
parser.add_argument('-passwd', '--password', type=str, default='cisco',
4443
help="It's the password")
45-
parser.add_argument('-port', '--port', type=int, default=830,
44+
parser.add_argument('-port', '--port', type=int, default=443,
4645
help="Specify this if you want a non-default port")
4746

4847
args = parser.parse_args()
@@ -52,12 +51,12 @@
5251
host = args.host
5352
port = str(args.port)
5453

55-
url = "http://" + host + ":" + port + "/restconf/api/running/"
54+
url = "https://" + host + ":" + port + "/restconf/api/running/"
5655

5756
headers = {
5857
"Content-Type": "application/vnd.yang.datastore+json",
5958
"Accept": "application/vnd.yang.datastore+json",
6059
}
61-
response = requests.request("GET", url, headers=headers, auth=(username,password))
60+
response = requests.request("GET", url, headers=headers, auth=(username,password), verify=False)
6261

63-
print(response.text)
62+
print(response.text)

eem_configdiff_to_spark/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,33 @@ Then type the following in `EXEC` mode:
1818
guestshell enable
1919
```
2020

21+
Guestshell may not include the needed `requests` module. Enter guestshell with the following command:
22+
23+
```
24+
guestshell
25+
```
26+
27+
From the guestshell prompt, run the following command:
28+
29+
```
30+
sudo pip install requests
31+
```
32+
33+
If this returns an error about not being able to establish a connection to download the module, you
34+
may need to update your DNS settings within guestshell. If you know your DNS server, you can use
35+
that address. If you don't, just use 8.8.8.8. Run the command:
36+
37+
```
38+
sudo echo 'nameserver DNSSERVER' > /etc/resolv.conf
39+
```
40+
41+
Where DNSSERVER is the IP address of your DNS server (or 8.8.8.8). After doing that, repeat
42+
the `pip` command, and it should install successfully. If `pip` tells you `requests` is already
43+
installed, then your guestshell environment is good. You can type `exit` to return to IOS-XE.
44+
45+
**NOTE** The guestshell environment will persist across reboots. It will not revert to the default
46+
state unless you do a `guestshell destory` followed by another `guestshell enable`.
47+
2148
Next, define the following EEM environment. Be sure **NOT** to put quotes around the variable
2249
values:
2350

eem_configdiff_to_spark/sl_config_diff_to_spark.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@
2828
#
2929
# spark_token : Bearer token for your Spark user/bot
3030
# spark_room : Spark room name to which messages will be sent
31+
# device_name : Device name from which the messages will be sent
3132
#
3233
# E.g.:
3334
#
3435
# event manager environment spark_token Bearer 1234abd...
3536
# event manager environment spark_room Network Operators
37+
# event manager environment device_name C3850
3638
#
3739

3840
import eem
@@ -58,6 +60,10 @@
5860
eem.action_syslog(
5961
'Environment variable "spark_room" must be set', priority='3')
6062
sys.exit(1)
63+
if 'device_name' not in arr_envinfo:
64+
eem.action_syslog(
65+
'Environment variable "device_name" must be set', priority='3')
66+
sys.exit(1)
6167

6268
# Get a CLI handle
6369
cli = eem.cli_open()
@@ -98,7 +104,9 @@
98104
# No differences found
99105
sys.exit(0)
100106

101-
msg = 'Configuration differences between the running config and last backup:\n'
107+
device_name = arr_envinfo['device_name']
108+
msg = '### Alert: Config changed on ' + device_name + '\n'
109+
msg += 'Configuration differences between the running config and last backup:\n'
102110
msg += '```{}```'.format('\n'.join(diff_lines[:-1]))
103111

104112
headers = {

restconf_update_ipaddress/updateip.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import json
2525
import requests
2626
import sys
27+
from argparse import ArgumentParser
2728
from collections import OrderedDict
2829
import urllib3
2930

@@ -58,7 +59,7 @@ def get_configured_interfaces():
5859
auth=(USER, PASS),
5960
headers=headers,
6061
verify=False
61-
)
62+
)
6263

6364
# return the json as text
6465
return response.json()["ietf-interfaces:interfaces"]["interface"]
@@ -78,9 +79,9 @@ def configure_ip_address(interface, ip):
7879
('ietf-ip:ipv4',
7980
OrderedDict([
8081
('address', [OrderedDict([
81-
('ip',ip["address"]),
82-
('netmask',ip["mask"])
83-
])]
82+
('ip', ip["address"]),
83+
('netmask', ip["mask"])
84+
])]
8485
)
8586
])
8687
),
@@ -93,7 +94,7 @@ def configure_ip_address(interface, ip):
9394
headers=headers,
9495
verify=False,
9596
json=data
96-
)
97+
)
9798
print(response.text)
9899

99100

@@ -106,7 +107,7 @@ def print_interface_details(interface):
106107
auth=(USER, PASS),
107108
headers=headers,
108109
verify=False
109-
)
110+
)
110111

111112
intf = response.json()["ietf-interfaces:interface"]
112113
# return the json as text
@@ -129,9 +130,9 @@ def interface_selection(interfaces):
129130

130131
# Validate interface input
131132
# Must be an interface on the device AND NOT be the Management Interface
132-
while sel == MANAGEMENT_INTERFACE or not sel in [intf["name"] for intf in interfaces]:
133+
while sel == args.interface or not sel in [intf["name"] for intf in interfaces]:
133134
print("INVALID: Select an available interface.")
134-
print(" " + MANAGEMENT_INTERFACE + " is used for management.")
135+
print(" " + args.interface + " is used for management.")
135136
print(" Choose another Interface")
136137
sel = input("Which Interface do you want to configure? ")
137138

@@ -142,12 +143,14 @@ def interface_selection(interfaces):
142143
def get_ip_info():
143144
# Ask User for IP and Mask
144145
ip = {}
145-
ip["address"] = input("What IP address do you want to set? ")
146-
ip["mask"] = input("What Subnet Mask do you want to set? ")
146+
ip["address"] = do_input("What IP address do you want to set? ")
147+
ip["mask"] = do_input("What Subnet Mask do you want to set? ")
147148
return(ip)
148149

149150

150151
def main():
152+
global do_input
153+
151154
"""
152155
Simple main method calling our function.
153156
"""
@@ -166,7 +169,7 @@ def main():
166169

167170
# Print Starting Interface Details
168171
print("Starting Interface Configuration")
169-
print_interface_details(selected_interface)
172+
print_interface_details(args, selected_interface)
170173

171174
# As User for IP Address to set
172175
ip = get_ip_info()

0 commit comments

Comments
 (0)