Accessing IBM SVC/Storwize devices with Python and SSH

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:


# -----------------------------------------------------------------------------
# "THE BEER-WARE LICENSE" (Revision 42):
# 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 = ''
login = 'mylogin'
password = 'mypassword'
command = 'lssystem -delim \,'

def ssh_exec(command, target, user, password, port=22):
    client = paramiko.SSHClient()

        client.connect(target, username=user, password=password, port=port)
        print('FATAL: Unable to log in')

    stdin, stdout, stderr = client.exec_command(command)

    error =
    if error:
        error = error.decode('US-ASCII')
        print('Error running the command:{}'.format(error))
        return 0

    data =

    return data.decode('US-ASCII')

lssystem = ssh_exec(command, target, login, password)


About mezzantrop

12+ years of experience in large SAN and storage environments: mainly Hitachi, HP and Brocade. Now I am a proud SAN/storage IBMer. Redbooks author. The BeaST – storage-system concept inventor. Empty – expect-like tool developer. FreeBSD enthusiast.
This entry was posted in Storage, Storage Automation, Tips & tricks and tagged , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.