HPE XP7 and P9500 disk array

API reference

class hpestorapi.Xp(cvae, svp, serialnum, username, password, gen='XP7', port=23451, ssl=True)[source]

XP7 / P9500 class implementation.

__init__(cvae, svp, serialnum, username, password, gen='XP7', port=23451, ssl=True)[source]

HPE XP constructor.

Parameters:
  • cvae (str) – Hostname or IP address of HPE Command View AE Configuration Manager.
  • svp (str) – Hostname or IP address of Service Processor (SVP).
  • serialnum (str) – Array serial number (5 or 6 digits)
  • username (str) – User name for HPE XP disk array. Creating a dedicated user with limited rights is recommended. Using “arrayadmin” account is a bad practice.
  • password (str) – Password for HPE XP disk array.
  • gen (str) – (optional) Disk array generation. Should be P9500 or XP7. Default value: XP7.
  • port (int) – (optional) Command View AE configuration manager port. Default value: 23451
  • ssl (bool) – (optional) Use secure https (True) or plain http ( False). Default value: True.
Returns:

None.

open()[source]

Open a new Rest API session for a HPE XP array.

Call it prior any other requests. Call Xp.close() if you do not plan to use session anymore.

Return type:bool
Returns:Return True, if disk array provides a valid session key.
close(passive=False)[source]

Close Rest API session.

Parameters:passive (bool) – (optional) Do not try to close session in the array. Revoke the client session key after session timed out. Use this parameter only for method overriding in subclasses. There is no need of using it, as class implementation manages the session life cycle. Default value: False.
Returns:None
get(url, **kwargs)[source]

Make a HTTP GET request to HPE XP array. Use this method to get information about array objects.

Parameters:
  • url (str) – URL address. Th static part of the URL address is generated automatically. Example ofvalid URL: ‘pools’, ‘parity-groups’, ‘ldevs’. All available URL’s and requests result are described in “HPE XP7 Command View Advanced Edition REST API Reference Guide”.
  • params (dict) – (optional) Dictionary with query filter parameters. Described in ‘Query parameters’ section of “HPE XP7 Command View Advanced Edition REST API Reference Guide”.
  • json (dict) – (optional) A JSON serializable object send in the request body.
  • timeout (float) – (optional) Number of seconds that Rest API client waits for a response from the Rest server before generating a timeout exception. Default value: Xp.timeout.
  • verify (bool) – (optional) Either a boolean, controlling the Rest server’s TLS certificate verification, or a string, where it is a path to a CA bundle. Default value: False (no certificate verification).
  • cert (str) – (optional) String with path to ssl client certificate file (.pem) or tuple pair (‘cert’, ‘key’).
Return type:

(int, {})

Returns:

Tuple with HTTP status code and dict with request result. For example: (200, {‘key’:’value’})

post(url, **kwargs)[source]

Make a HTTP POST request to HPE XP array. Use this method to create a new object.

Parameters:
  • json (dict) – (optional) A JSON serializable object to send in the body of request.
  • timeout (float) – (optional) Number of seconds that Rest API client waits for a response from the Rest server before generating a timeout exception. Default value: Xp.timeout.
  • verify (bool) – (optional) Either a boolean, controlling the Rest server’s TLS certificate verification, or a string, where it is a path to a CA bundle. Default value: False (no certificate verification).
  • cert (str) – (optional) String with path to ssl client certificate file (.pem) or tuple pair (‘cert’, ‘key’).
Return type:

(int, {})

Returns:

Tuple with HTTP status code and dict with request result. For example: (200, {‘key’:’value’})

delete(url, **kwargs)[source]

Make a HTTP DELETE request to HPE XP array. Use this method to remove objects.

Parameters:
  • json (dict) – (optional) A JSON serializable object send in the request body.
  • timeout (float) – (optional) Number of seconds that Rest API client waits for a response from the Rest server before generating a timeout exception. Default value: Xp.timeout.
  • verify (bool) – (optional) Either a boolean, controlling the Rest server’s TLS certificate verification, or a string, where it is a path to a CA bundle. Default value: False (no certificate verification).
  • cert (str) – (optional) String with path to ssl client certificate file (.pem) or tuple pair (‘cert’, ‘key’).
Return type:

(int, {})

Returns:

Tuple with HTTP status code and dict with request result. For example: (200, {‘key’:’value’})

put(url, **kwargs)[source]

Perform HTTP PUT request to HPE XP array.

Parameters:
  • json (dict) – (optional) A JSON serializable object to send in the body of request.
  • timeout (float) – (optional) Number of seconds that Rest API client waits for a response from the Rest server before generating a timeout exception. Default value: Xp.timeout.
  • verify (bool) – (optional) Either a boolean, controlling the Rest server’s TLS certificate verification, or a string, where it is a path to a CA bundle. Default value: False (no certificate verification).
  • cert (str) – (optional) String with path to ssl client certificate file (.pem) or tuple pair (‘cert’, ‘key’).
Return type:

(int, {})

Returns:

Tuple with HTTP status code and dict with request result. For example: (200, {‘key’:’value’})

timeout

Rest API client timeout.

Number of seconds that Rest API client waits for a response from Rest API server before generating a timeout exception. Different timeouts for connection setup and for getting first piece of data can be used. In this case, use tuple(float, float) with the first value being a connection delay and with the second value being a read delay. Alternatively, you can use one float value for both types of timeouts. ‘None’ value can be used instead not to limit the device response time. Default value: (1, None).

Usage examples

Session management

Open a Rest API session for an HPE XP array:

import hpestorapi

with hpestorapi.Xp('cvae.domain.com', 'svp.domain.com', '123456',
                   'arrayuser', 'arraypassword') as array:
    try:
        array.open()
    except Exception as error:
        print('Something went wrong:')
        raise error
    else:
        # Perform requests to array (get/post/put/delete)
        # ...

GET request

A simple GET request use. The following code prints a pool list from HPE XP array:

import hpestorapi

with hpestorapi.Xp('cvae.domain.com', 'svp.domain.com', '123456',
                   'arrayuser', 'arraypassword') as array:
    try:
        array.open()
        status, body = array.get('pools')
    except Exception as error:
        print('Something went wrong:')
        raise error
    else:
        if status == 200:
            for pool in body['data']:
                print('ID=%s ' % pool['poolId'],
                      'Name=%s ' % pool['poolName'],
                      'Type=%s' % pool['poolType']
                      )

POST request

The following code creates a new ldev on the XP array:

import hpestorapi

newvol = {'poolId': 1, 'byteFormatCapacity': '1G'}

with hpestorapi.Xp('cvae.domain.com', 'svp.domain.com', '123456',
                   'arrayuser', 'arraypassword') as array:
    try:
        array.open()
        status, body = array.post('ldevs', json=newvol)
    except Exception as error:
        print('Something went wrong:')
        raise error
    else:
        if status == 200:
            print('Success')
        else:
            print('Cannot create ldev')

DELETE request

The following code deletes an ldev 62:

import hpestorapi

ldevid=62

array = hpestorapi.Xp('cvae.domain.com', 'svp.domain.com', '123456',
                      'arrayuser', 'arraypassword') as array:
    try:
        array.open()
        status, body = array.post(f'ldevs/62')
    except Exception as error:
        print('Something went wrong:')
        raise error
    else:
        if status == 200:
            print('Success')
        else:
            print(f'Cannot delete ldev with id {ldevid}')

PUT request

The following code changes the label for an ldev 62:

import hpestorapi

ldevid = 62
settings = {'label': 'RestAPI_Test'}

with hpestorapi.Xp('cvae.domain.com', 'svp.domain.com', '123456',
                   'arrayuser', 'arraypassword') as array:
    try:
        array.open()
        status, body = array.put(f'ldevs/{ldevid}', json=settings)
    except Exception as error:
        print('Something went wrong:')
        raise error
    else:
        if status == 200:
            print('Success')
        else:
            print('Cannot create ldev')

Exception handling

import requests
import hpestorapi

with hpestorapi.Xp('cvae.domain.com', 'svp.domain.com', '123456',
                   'arrayuser', 'arraypassword') as array:
    try:
        array.open()
    except requests.exceptions.SSLError as error:
        print('Cannot connect to Configuration Manager. SSL cert '
              'cheking is enabled, but Rest API server has no '
              'valid SSL certificate.')
    except requests.exceptions.ReadTimeout:
        timeout = array.http_timeout
        print('Read timeout occured. The Rest server did not '
              'send any data in the allotted amount of time ',
              timeout)
    except requests.exceptions.ConnectTimeout as error:
        print('Connection timeout occured. The request timed out '
              'while trying to connect to the Rest server.')
    except hpestorapi.Xp.AuthError as error:
        print('Wrong username or password for the HPE XP array')
    except Exception as error:
        print(error)
    else:
        # Perform requests to array (get/post/put/delete)
        # ...