Advertisement
Guest User

Untitled

a guest
Aug 31st, 2017
513
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. #!/usr/bin/python3
  2.  
  3. # -----------------------------------------------------------------------------
  4. # "THE BEER-WARE LICENSE" (Revision 42):
  5. # zmey20000@yahoo.com wrote this file. As long as you retain this notice you
  6. # can do whatever you want with this stuff. If we meet some day, and you think
  7. # this stuff is worth it, you can buy me a beer in return Mikhail Zakharov
  8. # -----------------------------------------------------------------------------
  9.  
  10.  
  11. import paramiko
  12.  
  13.  
  14. def ssh_exec(host, user, password, port, command):
  15. """Execute a command via SSH and read results"""
  16.  
  17. client = paramiko.SSHClient()
  18. client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  19. client.connect(hostname=host, username=user, password=password, port=port)
  20. stdin, stdout, stderr = client.exec_command(command)
  21.  
  22. data = stdout.read()
  23. # TO-DO: Check error = stderr.read() for errors
  24. client.close()
  25.  
  26. data = data.decode('utf-8')
  27.  
  28. return data
  29.  
  30.  
  31. def split_colon(ln):
  32. """Split the string 'ln' by colon and return the second part"""
  33. return ln.split(':')[1].strip()
  34.  
  35. showsys_raw = ssh_exec('hp3par001', 'monitor', 'monitor', 22, 'showsys -d')
  36.  
  37. for ln in showsys_raw.splitlines():
  38. if 'System Name' in ln:
  39. system_name = split_colon(ln)
  40. continue
  41. if 'System Model' in ln:
  42. system_model = split_colon(ln)
  43. continue
  44. if 'Serial Number' in ln:
  45. serial_number = split_colon(ln)
  46. continue
  47. if 'System ID' in ln:
  48. system_id = split_colon(ln)
  49. continue
  50. if 'Number of Nodes' in ln:
  51. number_of_nodes = split_colon(ln)
  52. continue
  53. if 'Master Node' in ln:
  54. master_node = split_colon(ln)
  55. continue
  56. if 'Total Capacity' in ln:
  57. total_capacity = split_colon(ln)
  58. continue
  59. if 'Allocated Capacity' in ln:
  60. allocated_capacity = split_colon(ln)
  61. continue
  62. if 'Free Capacity' in ln:
  63. free_capacity = split_colon(ln)
  64. continue
  65. if 'Failed Capacity' in ln:
  66. failed_capacity = split_colon(ln)
  67. continue
  68. if 'Location' in ln:
  69. location = split_colon(ln)
  70. continue
  71. if 'Owner' in ln:
  72. owner = split_colon(ln)
  73. continue
  74. if 'Contact' in ln:
  75. contact = split_colon(ln)
  76. continue
  77. if 'Comment' in ln:
  78. comment = split_colon(ln)
  79.  
  80. print('showsys -d ------------------------------------------------------------',
  81. '\nSystem Name:', system_name,
  82. '\nSystem Model:', system_model,
  83. '\nSerial Number:', serial_number,
  84. '\nSystem ID:', system_id,
  85. '\nNumber of Nodes:', number_of_nodes,
  86. '\nMaster Node:', master_node,
  87. '\nTotal Capacity:', total_capacity,
  88. '\nAllocated Capacity:', allocated_capacity,
  89. '\nFree Capacity:', free_capacity,
  90. '\nFailed Capacity:', failed_capacity,
  91. '\nLocation:', location,
  92. '\nOwner:', owner,
  93. '\nContact:', contact,
  94. '\nComment:', comment)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement