Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pexpect
- import sys
- import argparse
- parser = argparse.ArgumentParser()
- parser.add_argument('config', help='you must supply the name of an ine config set')
- args = parser.parse_args()
- selectedConfig = args.config
- print('You have selected '+selectedConfig)
- routers = [
- ('R1','192.168.1.11'),
- ('R2','192.168.1.12'),
- ('R3','192.168.1.13'),
- ('R4','192.168.1.14'),
- ('R5','192.168.1.15'),
- ('R6','192.168.1.16'),
- ('R7','192.168.1.17'),
- ('R8','192.168.1.18'),
- ('R9','192.168.1.19'),
- ('R10','192.168.1.20')]
- username = 'testuser'
- password = 'testpass'
- enablePass = 'cisco'
- for routerName,ipaddr in routers:
- child = pexpect.spawn('ssh '+username+'@'+ipaddr, encoding='utf8', logfile=None)
- child.expect('Password:')
- child.sendline(password)
- child.expect('>')
- child.sendline('enable')
- child.expect('Password:')
- child.sendline(enablePass)
- child.expect('#')
- child.sendline('configure replace flash:base.cfg force')
- child.expect('Rollback Done')
- print('Rolled back to base.cfg on '+routerName)
- configPath = 'testconfig/'+selectedConfig+'/'+routerName+'.txt'
- configFile = open(configPath, 'r')
- configList = []
- for line in configFile:
- line = line.strip()
- configList.append(line)
- for command in configList:
- child.sendline(command)
- child.expect('#')
- child.close()
- print('Applied config: '+configPath+' on '+routerName)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement