Advertisement
Guest User

Untitled

a guest
Apr 19th, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. def policy_options_collector_juniper(device_name,tacacs_password):
  2. print "Capturing device policy options config for " + device_name
  3. device_config = {}
  4. config = []
  5. contents = StringIO()
  6. output_config = ""
  7. remote_conn_pre = paramiko.SSHClient()
  8. remote_conn_pre.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  9. remote_conn_pre.connect(device_name.strip(), port=22, username=getpass.getuser(), password=tacacs_password,look_for_keys=False, allow_agent=False, timeout=None)
  10. channel = remote_conn_pre.invoke_shell()
  11. channel.send('\n')
  12. time.sleep(1)
  13. channel.send('show configuration | display set | match policy-options | no-more\n')
  14. time.sleep(5)
  15. i = 0
  16. while i < 5:
  17. if channel.recv_ready():
  18. output_config += channel.recv(65535)
  19. contents.write(output_config)
  20. else:
  21. break
  22. i += 1
  23. print "This is " + str(i)
  24. print contents.getvalue()
  25.  
  26. for line in output_config.splitlines():
  27. if 'set' in line:
  28. config.append(line.strip())
  29. device_config['policy_options'] = config
  30. return device_config
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement