File: tutorial.rst

package info (click to toggle)
python-hplefthandclient 1.0.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 276 kB
  • sloc: python: 1,306; makefile: 142
file content (68 lines) | stat: -rw-r--r-- 2,066 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
Tutorial
========

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

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

.. code-block:: bash

  >>> 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
:class:`~hplefthandclient.client.HPLeftHandClient` to the LeftHand drive array
and logging in to create the session.   You must :meth:`~hplefthandclient.client.HPLeftHandClient.login` prior to calling the other APIs to do work on the LeftHand.
Doing so is easy:

.. code-block:: python

  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.

.. code-block:: python

   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 :meth:`~hplefthandclient.client.HPLeftHandClient.getVolumes`.

.. code-block:: python

    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