Advertisement
Guest User

Untitled

a guest
Mar 1st, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. import sys
  2. import time
  3. import paramiko
  4. import os
  5. import cmd
  6. import datetime
  7.  
  8. now = datetime.datetime.now()
  9.  
  10. username = 'xxx'
  11. password = 'xxx'
  12.  
  13. from zenoss import Zenoss
  14. zenoss = Zenoss('http://x.x.x.x:8080/', 'xx', 'xx')
  15.  
  16. with open('/home/xxxx/hosts_all.txt', 'w') as f:
  17. for device in zenoss.get_devices()['devices']:
  18. print(device['name'], file=f)
  19. f.close()
  20.  
  21. f = open('/home/xxxx/hosts_all.txt', 'r')
  22. read_f = f.readlines()
  23. f.close()
  24. for i in range(1, len(read_f)):
  25.  
  26. remote_conn_pre = paramiko.SSHClient()
  27.  
  28.  
  29. remote_conn_pre.set_missing_host_key_policy(
  30. paramiko.AutoAddPolicy())
  31.  
  32. remote_conn_pre.connect(read_f[i], username=username, password=password, look_for_keys=False, allow_agent=False)
  33. print("SSH connection established to %s" % read_f[i])
  34.  
  35. remote_conn = remote_conn_pre.invoke_shell()
  36. print("Interactive SSH session established")
  37.  
  38. list_of_comm = ["environment no moren", "admin display-confign"]
  39.  
  40. for i in range(len(list_of_comm)):
  41. remote_conn.send(list_of_comm[i])
  42.  
  43. time.sleep(2)
  44.  
  45. output = remote_conn.recv(5000)
  46. filename = "%s_%.2i-%.2i-%i" % (read_f[i],now.day,now.month,now.year)
  47. print(str(output) + 'n', file=filename)
  48.  
  49. Traceback (most recent call last):
  50. File "conf_backup.py", line 43, in <module>
  51. remote_conn_pre.connect(read_f[i], username=username, password=password, look_for_keys=False, allow_agent=False)
  52. File "/usr/local/lib/python3.4/dist-packages/paramiko/client.py", line 283, in connect
  53. to_try = list(self._families_and_addresses(hostname, port))
  54. File "/usr/local/lib/python3.4/dist-packages/paramiko/client.py", line 187, in _families_and_addresses
  55. addrinfos = socket.getaddrinfo(hostname, port, socket.AF_UNSPEC, socket.SOCK_STREAM)
  56. File "/usr/lib/python3.4/socket.py", line 533, in getaddrinfo
  57. for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
  58. socket.gaierror: [Errno -2] Name or service not known
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement