-
Notifications
You must be signed in to change notification settings - Fork 0
/
automate-l1.py
52 lines (42 loc) · 1.3 KB
/
automate-l1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python
from __future__ import print_function, unicode_literals
# this script adds new local user for all devices included ipListOfNodes file
import logging
# Netmiko is the same as ConnectHandler
from netmiko import ConnectHandler, redispatch
from netmiko import Netmiko
from getpass import getpass
# logging for troubleshooting purposes
logging.basicConfig(filename='test.log', level=logging.DEBUG)
logger = logging.getLogger("netmiko")
hostFile = open ('ipListOfNodes','r')
hostList = hostFile.readlines()
hostFile.close()
# admin password
mypass = getpass()
# new password for the new local user
adpass = getpass()
# adjust aaa settings and save
for device in hostList:
huawei = {
"host": device,
"username": "username",
"password": mypass,
"device_type": "huawei",
}
net_connect = Netmiko(**huawei)
output = net_connect.send_config_from_file("change_file.txt")
print(output)
net_connect.disconnect()
# verify admin user and pwd
for device in hostList:
huawei = {
"host": device,
"username": "admin",
"password": adpass,
"device_type": "huawei",
}
net_connect = Netmiko(**huawei)
output = net_connect.send_config_from_file("verification")
print(output)
net_connect.disconnect()