HPE StoreOnce Gen 3 disk backup¶
API references¶
-
class
hpestorapi.
StoreOnceG3
(address, user, password, cookie_dir=None, port=443)[source]¶ HPE StoreOnce Gen 3 disk backup device implementation class.
-
__init__
(address, user, password, cookie_dir=None, port=443)[source]¶ HPE StoreOnceG3 constructor.
Parameters: - address (str) – Hostname or IP address of HPE StoreOnce disk backup device.
- user (str) – Username for HPE StoreOnce disk backup device.
- password (str) – Password for HPE StoreOnce disk backup device.
- cookie_dir (str) – (optional) Directory for authentication cookies.
- port (int) – (optional) Custom port number for StoreOnce device.
Returns: None.
Generate cookie file path.
Return type: str Returns: Cookie file path
-
get
(url, **kwargs)[source]¶ Make a HTTP GET request to HPE StoreOnce disk backup device.
Use this method to get information about objects.
Parameters: - url (str) – URL address. The static part of URL address is generated automatically. Example of valid URL: ‘cluster’ or ‘cluster/servicesets’. All available URLs and requests result are described in “HPE StoreOnce 3.18.2 REST API developer Guide”.
- filter (RequestsCookieJar) – (optional) Filter cookies, that were
generated by method
StoreOnceG3.filter()
- timeout (int) – (optional) Number of seconds that Rest API client
waits for a response from the Rest server before generating a
timeout exception. Default value:
StoreOnceG3.timeout
.
Return type: (int, string)
Returns: Tuple with HTTP status code and xml string with the request result. For example: (200, ‘<xml> … </xml>’).
-
post
(url, **kwargs)[source]¶ Make a HTTP POST request to HPE StoreOnce disk backup device.
Use this method to create new objects.
Parameters: - url (str) – URL address. Base static part of URL address is generated automatically. Example of valid url: ‘cluster’ or ‘cluster/servicesets’. All available URLs and requests result are described in “HPE StoreOnce 3.18.2 REST API developer Guide”.
- timeout (int) – (optional) Number of seconds that Rest API client
waits for a response from the Rest server before generating a
timeout exception. Default value:
StoreOnceG3.timeout
.
Return type: (int, string)
Returns: Tuple with HTTP status code and xml string with request result. For example: (200, ‘<xml> … </xml>’).
-
put
(url, **kwargs)[source]¶ Make a HTTP PUT request to HPE Storeonce disk backup device.
Method used to update objects.
Parameters: - url (str) – URL address. The static part of URL address is generated automatically. Example of valid URL: ‘cluster’ or ‘cluster/servicesets’. All available url’s and requests result are described in “HPE StoreOnce 3.18.2 REST API developer Guide”
- timeout (int) – (optional) Number of seconds that Rest API client
waits for a response from the Rest server before generating a
timeout exception. Default value:
StoreOnceG3.timeout
.
Return type: (int, string)
Returns: Tuple with HTTP status code and xml string with request result. For example: (200, ‘<xml> … </xml>’).
-
delete
(url, **kwargs)[source]¶ Make a HTTP DELETE request to HPE Storeonce disk backup device.
Use this method to delete objects.
Parameters: - url (str) – URL address. Base part of url address is generated automatically and you should not care about it. Example of valid url: ‘cluster’ or ‘cluster/servicesets’. All available url’s and requests result are described in “HPE StoreOnce 3.18.2 REST API developer Guide”
- timeout (int) – (optional) Number of seconds that Rest API client
waits for a response from the Rest server before generating a
timeout exception. Default value:
StoreOnceG3.timeout
.
Return type: (int, string)
Returns: Tuple with HTTP status code and xml string with request result. For example: (200, ‘<xml> … </xml>’).
-
open
(use_cookie_file=True)[source]¶ Open new Rest API session for HPE StoreOnce disk backup device.
- Call it prior any other requests. Call
StoreOnceG3.close()
if - you do not plan to use a session anymore.
Parameters: use_cookie_file (bool) – (optional) Try to load authentication cookie from cookie file. Returns: None - Call it prior any other requests. Call
-
filter
(url, parameters, **kwargs)[source]¶ Get cookies for query with filtering.
Parameters: url (str) – Filter URL address. Return type: requests.cookies.RequestsCookieJar() Returns: Filtering cookie
-
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 Rest API session for StoreOnce G3 disk backup device:
import hpestorapi
with hpestorapi.StoreOnceG3('10.0.0.1', 'Admin', 'password') as so:
try:
so.open()
except Exception as error:
print('Something went wrong:')
print(error)
else:
# Perform requests to StoreOnce (get/post/put/delete)
# ...
GET request¶
Simple GET request usage. This code print StoreOnce G3 Catalyst Stores:
import xml.etree.ElementTree
import hpestorapi
with hpestorapi.StoreOnceG3('10.0.0.1', 'Admin', 'password') as so:
try:
so.open()
except Exception as error:
print('Something went wrong:')
print(error)
else:
status, data = so.get('/cluster')
if status == 200:
tree = xml.etree.ElementTree.fromstring(data)
name = tree.find('./cluster/properties/applianceName').text
model = tree.find('./cluster/properties/productClass').text
print(f'SO Name = "{name}"')
print(f'SO Model = "{model}"')
POST request¶
POST request usage. This code activate license for StoreOnce G3:
import hpestorapi
body = {'key': 'demo', 'opcode': 'add'}
with hpestorapi.StoreOnceG3('10.0.0.1', 'Admin', 'password') as so:
try:
so.open()
status, data = so.post('/d2dlicenses', params=body)
except Exception as error:
print('Something went wrong:')
print(error)
else:
if status == 200:
print('Demo license activation success.')
else:
print('License activation failed.'
'Http code: %s. Response body: %s',
status, data)
DELETE request¶
This code remove from Service Set 1 Catalyst Store 0:
import hpestorapi
with hpestorapi.StoreOnceG3('10.0.0.1', 'Admin', 'password') as so:
try:
so.open()
except Exception as error:
print('Something went wrong:')
print(error)
else:
sset = 1
store = 0
status, data = so.delete(f'/cluster/servicesets/{sset}'
f'/services/cat/stores/{store}')
if status == 204:
print('Catalyst store deleted')
else:
print('Can not delete catalyst store.'
'Http code: %s. Response: %s',
status, data)
PUT request¶
This code add NTP server to StoreOnce G3 configuration:
import hpestorapi
with hpestorapi.StoreOnceG3('10.0.0.1', 'Admin', 'password') as so:
try:
print('Something went wrong:')
so.open()
except Exception as error:
print('Something went wrong:')
print(error)
else:
body = {'add': 'true', 'servers': '10.0.0.2'}
status, data = so.put('/d2dservices/clusterconf/ntp',
params=body)
if status == 200:
print('Catalyst store deleted')
else:
print('Can not delete catalyst store.'
'Http code: %s. Response body: %s',
status, data)
Iterate multipage objects¶
This code print all Catalyst items from all Catalyst stores:
from hpestorapi import StoreOnceG3
from hpestorapi.storeonce3 import Iterator
import xml.etree.ElementTree
with StoreOnceG3('10.0.0.1', 'Admin', 'password') as so:
try:
so.open()
except Exception as error:
print('Something went wrong:')
print(error)
else:
# Print table header row
print('%15s %8s %30s %15s' % ('Store', 'ID', 'Name', 'Status'))
# Iterate all ServiceSets
for sset_xml in Iterator(so, '/cluster/servicesets',
'./servicesets/serviceset'):
sset = xml.etree.ElementTree.fromstring(sset_xml)
ssid = sset.find('./properties/ssid').text
# Iterate all catalyst Stores
store_url = (f'/cluster/servicesets'
f'/{ssid}/services/cat/stores/')
for store_xml in Iterator(so, store_url, './stores/store'):
store = xml.etree.ElementTree.fromstring(store_xml)
store_id = store.find('./properties/id').text
store_name = store.find('./properties/name').text
# Iterate all Catalyst Items
item_url = (f'/cluster/servicesets/{ssid}'
f'/services/cat/stores/{store_id}/items/')
for item_xml in Iterator(so, item_url, './items/item'):
item = xml.etree.ElementTree.fromstring(item_xml)
item_id = item.find('./properties/id').text
item_name = item.find('./properties/name').text
item_status = item.find('./properties/status').text
print('%15s %8s %30s %15s' % (store_name, item_id,
item_name, item_status))