Adds an API for retrieving snapshot parent name

Adds a new API for retrieving a snapshot's parent volume name.

SSH is used as there is currently no way to get this
information from the LH REST API.

Change-Id: I92921eb2eaaa0a18633b0883dfe990ae1d2cde0d
This commit is contained in:
Anthony Lee 2016-01-06 17:16:30 -08:00
parent 85134064ab
commit 68a2bd6f02
5 changed files with 82 additions and 4 deletions

View File

@ -20,6 +20,7 @@
.. automethod:: getSnapshots
.. automethod:: getSnapshot
.. automethod:: getSnapshotByName
.. automethod:: getSnapshotParentVolume
.. automethod:: createSnapshot
.. automethod:: deleteSnapshot
.. automethod:: cloneSnapshot

View File

@ -107,3 +107,8 @@ Changes in Version 2.0.1
- startRemoteSnapshotSchedule
- doesRemoteSnapshotScheduleExist
- getIPFromCluster
Changes in Version 2.0.2
------------------------
* Adds a new API for getting a snapshot's parent volume name.

View File

@ -1,6 +1,6 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
# (c) Copyright 2013-2015 Hewlett Packard Enterprise Development LP
# (c) Copyright 2013-2016 Hewlett Packard Enterprise Development LP
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@ -24,7 +24,7 @@ HPE LeftHand REST Client
"""
version_tuple = (2, 0, 1)
version_tuple = (2, 0, 2)
def get_version_string():

View File

@ -1,6 +1,6 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
# (c) Copyright 2012-2015 Hewlett Packard Enterprise Development LP
# (c) Copyright 2012-2016 Hewlett Packard Enterprise Development LP
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@ -29,6 +29,8 @@ This client requires and works with version 11.5 of the LeftHand firmware
"""
import re
try:
# For Python 3.0 and later
from urllib.parse import quote
@ -305,6 +307,44 @@ class HPELeftHandClient(object):
response, body = self.http.get('/snapshots?name=%s' % name)
return body
def getSnapshotParentVolume(self, name):
"""
Get the parent volume for a Snapshot
:param name: The name of the snapshot
:type name: str
:returns: parent volume
:raises: :class:`~hpelefthandclient.exceptions.HTTPNotFound`
- Snapshot not found.
:raises: :class:`~hpelefthandclient.exceptions.HTTPNotFound`
- NON_EXISTENT_VOL - volume doesn't exist
"""
cmd = ['getSnapshotInfo',
'snapshotName=' + name]
output = self._run(cmd)
output = "\n".join(output)
# Extract the results from the command output.
# Use regex to find the result line and then make
# capture group #1 the value so it can be extracted.
# Do the same process to extract the description if
# an error occured.
m = re.search(r"result\s*(.*)", output)
result = m.group(1)
if int(result) != 0:
m = re.search(r"description\s*(.*)", output)
desc = m.group(1)
raise exceptions.HTTPNotFound(desc)
# Extract the parent volume name from the command output.
# Use regex to find only the volumeName line and then
# make capture group #1 the name so it can be extracted.
m = re.search(r"volumeName\s*(.*)", output)
parent_vol_name = m.group(1)
return self.getVolumeByName(parent_vol_name)
def createSnapshot(self, name, source_volume_id, optional=None):
"""
Create a snapshot of an existing Volume

View File

@ -1,4 +1,4 @@
# (c) Copyright 2015 Hewlett Packard Enterprise Development LP
# (c) Copyright 2015-2016 Hewlett Packard Enterprise Development LP
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ -489,6 +489,38 @@ class HPELeftHandClientVolumeTestCase(test_HPELeftHandClient_base.
self.printFooter('modify_snapshot_nonExistSnapshot')
@unittest.skipIf(not is_live_test(), "Only runs on live array.")
def test_6_get_snapshot_parent_volume(self):
self.printHeader('get_snapshot_parent_volume')
self.cl.createVolume(VOLUME_NAME1, self.cluster_id,
self.GB_TO_BYTES)
volume_info = self.cl.getVolumeByName(VOLUME_NAME1)
option = {'inheritAccess': True}
self.cl.createSnapshot(SNAP_NAME1, volume_info['id'], option)
parent_vol = self.cl.getSnapshotParentVolume(SNAP_NAME1)
self.assertEqual(VOLUME_NAME1, parent_vol['name'])
self.printFooter('get_snapshot_parent_volume')
@unittest.skipIf(not is_live_test(), "Only runs on live array.")
def test_6_get_snapshot_parent_volume_snapshot_invalid(self):
self.printHeader('get_snapshot_parent_volume_snapshot_invalid')
self.cl.createVolume(VOLUME_NAME1, self.cluster_id,
self.GB_TO_BYTES)
volume_info = self.cl.getVolumeByName(VOLUME_NAME1)
option = {'inheritAccess': True}
self.cl.createSnapshot(SNAP_NAME1, volume_info['id'], option)
self.assertRaises(exceptions.HTTPNotFound,
self.cl.getSnapshotParentVolume,
"fake_snap")
self.printFooter('get_snapshot_parent_volume_snapshot_invalid')
def test_7_get_ip_from_cluster(self):
self.printHeader('get_ip_from_cluster')