Advertisement
Guest User

Untitled

a guest
Sep 13th, 2016
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. import pexpect
  2. import sys
  3. import argparse
  4.  
  5. parser = argparse.ArgumentParser()
  6. parser.add_argument('config', help='you must supply the name of an ine config set')
  7. args = parser.parse_args()
  8. selectedConfig = args.config
  9. print('You have selected '+selectedConfig)
  10.  
  11. routers = [
  12. ('R1','192.168.1.11'),
  13. ('R2','192.168.1.12'),
  14. ('R3','192.168.1.13'),
  15. ('R4','192.168.1.14'),
  16. ('R5','192.168.1.15'),
  17. ('R6','192.168.1.16'),
  18. ('R7','192.168.1.17'),
  19. ('R8','192.168.1.18'),
  20. ('R9','192.168.1.19'),
  21. ('R10','192.168.1.20')]
  22.  
  23. username = 'testuser'
  24. password = 'testpass'
  25. enablePass = 'cisco'
  26.  
  27. for routerName,ipaddr in routers:
  28. child = pexpect.spawn('ssh '+username+'@'+ipaddr, encoding='utf8', logfile=None)
  29. child.expect('Password:')
  30. child.sendline(password)
  31. child.expect('>')
  32. child.sendline('enable')
  33. child.expect('Password:')
  34. child.sendline(enablePass)
  35. child.expect('#')
  36. child.sendline('configure replace flash:base.cfg force')
  37. child.expect('Rollback Done')
  38. print('Rolled back to base.cfg on '+routerName)
  39.  
  40. configPath = 'testconfig/'+selectedConfig+'/'+routerName+'.txt'
  41. configFile = open(configPath, 'r')
  42. configList = []
  43. for line in configFile:
  44. line = line.strip()
  45. configList.append(line)
  46. for command in configList:
  47. child.sendline(command)
  48. child.expect('#')
  49. child.close()
  50. print('Applied config: '+configPath+' on '+routerName)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement