HPE 3PAR StoreServ disk array¶
API reference¶
-
class
hpestorapi.
StoreServ
(address, username, password, port=None, ssl=True, verify=True)[source]¶ HPE 3PAR array implementation class.
-
__init__
(address, username, password, port=None, ssl=True, verify=True)[source]¶ HPE 3PAR object constructor.
Parameters: - address (str) – Hostname or IP address of HPE 3PAR array management interface. Web Services API should be enabled for this array (disabled by default). To enable Web Services API check 3PAR OS command: ‘showwsapi’.
- username (str) – User name for 3PAR Web Services API. Creating a dedicated user with limited rights recommended. For example, if you do not need to create/modify/delete objects on a disk array, create a new user with a “browse” role. Running a script with a “3paradm” user is not recommended. To create a new user, check 3PAR OS command: ‘createuser’.
- password (str) – Password for 3PAR Web Services API.
- port (int) – (optional) Custom port number for 3PAR Web Services API.
- ssl (bool) – (optional) Use secure https (True) or plain text http (False).
- verify (bool|string) – (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: True.
Returns: None
-
open
() → None[source]¶ Open new Rest API session for HPE 3PAR array.
Call it prior any other requests. Call
StoreServ.close()
if you do not plan to use a session anymore, because 3PAR array has an active sessions limit.Should any trouble occur, please manually check that:
- 3PAR Web services API are enabled on the array (3PAR OS command: ‘showwsapi’)
- Array credentials (username and password)
- 3PAR array management address is correct and available
- Debug logs generated by a python logging module
Returns: None
-
close
() → None[source]¶ Close Rest API session.
No need to run it manually when context manager is used (block
with .. as ..:
).Returns: None
-
get
(url, query=None)[source]¶ Make a HTTP GET request to HPE 3PAR array. Method used to get information about objects.
Parameters: - url (str) – URL address. The static part of the URL address is generated automatically. Example of a valid URL: ‘system’ or ‘volumes’. All available URLs and requests results are described in “HPE 3PAR Web Services API Developer’s Guide”.
- query (str) – (optional) Query filter specification (see “WSAPI query syntax” in “HPE 3PAR Web Services API Developer’s Guide”).
Return type: tuple(int, dict)
Returns: Tuple with HTTP status code and dict with request result. For example: (200, {‘key’:’value’}).
-
post
(url, body)[source]¶ Make a HTTP POST request to HPE 3PAR array. Method used to create new objects.
Parameters: - url (str) – URL address. The static part of the URL address is generated automatically. Example of a valid URL: ‘system’ or ‘volumes’. All available URLs, request parameters and results are described in “HPE 3PAR Web Services API Developer’s Guide”.
- body (dict) – Request parameter, used to create new array object.
Return type: tuple (int, dict)
Returns: Tuple with HTTP status code and dict with request result. For example: (201, {‘key’:’value’}). Second value may be None if 3PAR array returns no message body.
-
delete
(url)[source]¶ Make a HTTP DELETE request to HPE 3PAR array.
Parameters: url (str) – URL address. The static part of the URL address is generated automatically. Example of a valid URL: ‘system’ or ‘volumes’. All available URLs, request parameters and results are described in “HPE 3PAR Web Services API Developer’s Guide”. Returns: Tuple with HTTP status code and dict with request result. For example: (200, {‘key’:’value’}). Second value may be None if 3PAR array returns no message body.
-
put
(url, body)[source]¶ Make a HTTP PUT request to HPE 3PAR array.
Parameters: - url (str) – URL address. The static part of the URL address is generated automatically. Example of a valid URL: ‘system’ or ‘volumes’. All available URLs, request parameters and results are described in “HPE 3PAR Web Services API Developer’s Guide”.
- body (dict) – Request parameter, used to modify an array object.
Return type: tuple(int, dict)
Returns: Tuple with HTTP status code and dict with request result. For example: (200, {‘key’:’value’}). Second value may be None if 3PAR array returns no message body.
-
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¶
A simple way to open a Rest API session for StoreServ 3PAR arrays (with exception handling and session auto-closing):
from hpestorapi import StoreServ
with StoreServ('10.0.0.1', '3paruser', '3parpass') as array:
try:
array.open()
# Perform requests to array (get/post/put/delete)
# ...
except Exception as error:
print(error)
else:
# Analyze array response
# ...
GET request¶
Simple GET request usage. This following code prints storage system information (name, serial number and IP address):
from hpestorapi import StoreServ
with StoreServ('10.0.0.1', '3paruser', '3parpass') as array:
try:
array.open()
status, data = array.get('system')
except Exception as error:
print('Something went wrong:')
raise error
else:
if status == 200:
print('Name=%s; ' % data['name'],
'SerialNumber=%s; ' % data['serialNumber'],
'Address=%s' % data['IPv4Addr']
)
GET request can also contain filter parameter (query=’…’). Filter specifications are described in “HPE 3PAR Web Services API Developer’s Guide” (see section “WSAPI query syntax”). The following code prints Remote Copy Groups names beginning with “dfs”.
from hpestorapi import StoreServ
with StoreServ('10.0.0.1', '3paruser', '3parpass') as array:
try:
array.open()
status, data = array.get('remotecopygroups', query='name LIKE dfs*')
except Exception as error:
print('Something went wrong:')
raise error
else:
if status == 200:
for rc_group in data['members']:
print('RC group name = ', rc_group['name'])
POST request¶
The following code creates a new host on the 3PAR array:
from hpestorapi import StoreServ
newhost = {
'name': 'restapi-test',
'persona': 2,
'FCWWNs': ['50:01:55:55:55:55:55:55',
'50:01:66:66:66:66:66:66']
}
with StoreServ('10.0.0.1', '3paruser', '3parpass') as array:
try:
array.open()
status, data = array.post('hosts', newhost)
except Exception as error:
print('Something went wrong:')
raise error
else:
if status == 201:
print('Success')
else:
print('Failed! Device response: ', data)
DELETE request¶
The following code deletes a host from the HP 3PAR array:
from hpestorapi import StoreServ
with StoreServ('10.0.0.1', '3paruser', '3parpass') as array:
hostname = 'restapi-test'
try:
array.open()
status, data = array.delete(f'hosts/{hostname}')
except Exception as error:
print('Something went wrong:')
raise error
else:
if status == 200:
print('Success')
else:
print('Fail! StoreServ 3PAR response: ', data)
PUT request¶
The following code modifies a host on the HPE 3PAR array (change host persona and location description):
from hpestorapi import StoreServ
hostname = 'restapi-test'
modify = {
'persona': 1,
'descriptors': {'location': 'Rack 2/42, Unit 34'}
}
with StoreServ('10.0.0.1', '3paruser', '3parpass') as array:
try:
array.open()
status, data = array.put(f'hosts/{hostname}', body=modify)
except Exception as error:
print('Something went wrong:')
raise error
else:
if status == 200:
print('Success')
else:
print('Fail! Device response: ', data)
Exception handling¶
Almost all methods that perform interaction with the HPE StoreServ 3PAR array can generate exceptions. The best practice is to handle these exceptions.
List of method that can raise exceptions:
StoreServ.open()
StoreServ.get()
StoreServ.post()
StoreServ.delete()
StoreServ.put()
Note
StoreServ class object constructor does not make any requests to an array; therefore, StoreServ object initilization cannot raise exceptions.
Exception handling example:
import requests
from hpestorapi import StoreServ
with StoreServ('10.0.0.1', '3paruser', '3parpass') as array:
try:
array.open()
status, data = array.get('system')
except requests.exceptions.SSLError as error:
print('SSL error occured. Please check SSL connection '
'options.')
except requests.exceptions.ReadTimeout:
print('Read timeout occured. The StoreServ 3PAR array did '
'not send any data in the alloted amount of time.')
except requests.exceptions.ConnectTimeout as error:
print('Connection timeout occured. The request timed out '
'while trying to connect to the StoreServ 3PAR '
'array.')
except hpestorapi.storeserv.AuthError as error:
print('Wrong user name or password for the StoreServ 3PAR '
'array.')
except Exception as error:
print(error)
else:
# We are successfully received response from array. You can
# safely analyze array response (status and data variables)
# ...