Skip to content

Instantly share code, notes, and snippets.

@mezantrop
Created August 31, 2017 13:05
Show Gist options
  • Save mezantrop/fcdf70670f9725290f3edff74b24a907 to your computer and use it in GitHub Desktop.
Save mezantrop/fcdf70670f9725290f3edff74b24a907 to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
# -----------------------------------------------------------------------------
# "THE BEER-WARE LICENSE" (Revision 42):
# [email protected] wrote this file. As long as you retain this notice you
# can do whatever you want with this stuff. If we meet some day, and you think
# this stuff is worth it, you can buy me a beer in return Mikhail Zakharov
# -----------------------------------------------------------------------------
import paramiko
def ssh_exec(host, user, password, port, command):
"""Execute a command via SSH and read results"""
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(hostname=host, username=user, password=password, port=port)
stdin, stdout, stderr = client.exec_command(command)
data = stdout.read()
# TO-DO: Check error = stderr.read() for errors
client.close()
data = data.decode('utf-8')
return data
def split_colon(ln):
"""Split the string 'ln' by colon and return the second part"""
return ln.split(':')[1].strip()
showsys_raw = ssh_exec('hp3par001', 'monitor', 'monitor', 22, 'showsys -d')
for ln in showsys_raw.splitlines():
if 'System Name' in ln:
system_name = split_colon(ln)
continue
if 'System Model' in ln:
system_model = split_colon(ln)
continue
if 'Serial Number' in ln:
serial_number = split_colon(ln)
continue
if 'System ID' in ln:
system_id = split_colon(ln)
continue
if 'Number of Nodes' in ln:
number_of_nodes = split_colon(ln)
continue
if 'Master Node' in ln:
master_node = split_colon(ln)
continue
if 'Total Capacity' in ln:
total_capacity = split_colon(ln)
continue
if 'Allocated Capacity' in ln:
allocated_capacity = split_colon(ln)
continue
if 'Free Capacity' in ln:
free_capacity = split_colon(ln)
continue
if 'Failed Capacity' in ln:
failed_capacity = split_colon(ln)
continue
if 'Location' in ln:
location = split_colon(ln)
continue
if 'Owner' in ln:
owner = split_colon(ln)
continue
if 'Contact' in ln:
contact = split_colon(ln)
continue
if 'Comment' in ln:
comment = split_colon(ln)
print('showsys -d ------------------------------------------------------------',
'\nSystem Name:', system_name,
'\nSystem Model:', system_model,
'\nSerial Number:', serial_number,
'\nSystem ID:', system_id,
'\nNumber of Nodes:', number_of_nodes,
'\nMaster Node:', master_node,
'\nTotal Capacity:', total_capacity,
'\nAllocated Capacity:', allocated_capacity,
'\nFree Capacity:', free_capacity,
'\nFailed Capacity:', failed_capacity,
'\nLocation:', location,
'\nOwner:', owner,
'\nContact:', contact,
'\nComment:', comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment