Recently I have posted a simple example of how to fetch storage related data from IBM Spectrum Control with the help of Python and REST API.
Now lets turn the power of Python to access IBM Storwize or SVC system directly with SSH and run “lssystem” command on it. In the example below I use a very nice “paramiko” module, which handles SSH protocol and simplifies the task.
As you can see, nothing difficult here:
#!/usr/bin/python3 # ----------------------------------------------------------------------------- # "THE BEER-WARE LICENSE" (Revision 42): # zmey20000@yahoo.com 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 target = '192.168.1.1' login = 'mylogin' password = 'mypassword' command = 'lssystem -delim \,' def ssh_exec(command, target, user, password, port=22): client = paramiko.SSHClient() client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) try: client.connect(target, username=user, password=password, port=port) except: print('FATAL: Unable to log in') exit(1) stdin, stdout, stderr = client.exec_command(command) error = stderr.read() if error: error = error.decode('US-ASCII') print('Error running the command:{}'.format(error)) client.close() return 0 data = stdout.read() client.close() return data.decode('US-ASCII') lssystem = ssh_exec(command, target, login, password) print(lssystem)