deb-python-hplefthandclient/docs/tutorial.rst

2.0 KiB

Tutorial

This tutorial is intended as an introduction to working with HPLeftHandClient.

Prerequisites

Before we start, make sure that you have the HPLeftHandClient distribution installed <installation>. In the Python shell, the following should run without raising an exception:

>>> import hplefthandclient

This tutorial also assumes that a LeftHand array is up and running and the LeftHand OS is running.

Create the Client and login

The first step when working with HPLeftHandClient is to create a ~hplefthandclient.client.HPLeftHandClient to the LeftHand drive array and logging in to create the session. You must ~hplefthandclient.client.HPLeftHandClient.login prior to calling the other APIs to do work on the LeftHand. Doing so is easy:

from hplefthandclient import client, exceptions
#this creates the client object and sets the url to the
#LeftHand server with IP 10.10.10.10 on port 8008.
cl = client.HPLeftHandClient("https://10.10.10.10:8008/api/v1")

try:
    cl.login(username, password)
    print "Login worked!"
except exceptions.HTTPUnauthorized as ex:
    print "Login failed."

When you are done with the the client, it's a good idea to logout from the LeftHand so there isn't a stale session sitting around.

cl.logout()
print "logout worked"

Getting a list of Volumes

After you have logged in, you can start making calls to the LeftHand APIs. A simple example is getting a list of existing volumes on the array with a call to ~hplefthandclient.client.HPLeftHandClient.getVolumes.

import pprint
try:
   volumes = cl.getVolumes()
   pprint.pprint(volumes)
except exceptions.HTTPUnauthorized as ex:
   print "You must login first"
except Exception as ex:
   #something unexpected happened
   print ex

Note

volumes is an array of volumes in the above call