Skip to content

Commit

Permalink
Merge pull request #1 from dell/release_1.1.0
Browse files Browse the repository at this point in the history
Release version 1.1.0
  • Loading branch information
dattaarindam authored Mar 24, 2021
2 parents a95bb74 + 2303c8f commit 0bc8f5c
Show file tree
Hide file tree
Showing 9 changed files with 387 additions and 63 deletions.
19 changes: 12 additions & 7 deletions PyPowerFlex/base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def _create_entity(self, params=None):
params=params
)
if r.status_code != requests.codes.ok:
exc = exceptions.PowerFlexFailCreating(self.entity)
exc = exceptions.PowerFlexFailCreating(self.entity, response)
LOG.error(exc.message)
raise exc

Expand All @@ -169,7 +169,8 @@ def _delete_entity(self, entity_id, params=None):
entity_id=entity_id,
params=params)
if r.status_code != requests.codes.ok:
exc = exceptions.PowerFlexFailDeleting(self.entity, entity_id)
exc = exceptions.PowerFlexFailDeleting(self.entity, entity_id,
response)
LOG.error(exc.message)
raise exc

Expand All @@ -180,7 +181,8 @@ def _rename_entity(self, action, entity_id, params=None):
entity_id=entity_id,
params=params)
if r.status_code != requests.codes.ok:
exc = exceptions.PowerFlexFailRenaming(self.entity, entity_id)
exc = exceptions.PowerFlexFailRenaming(self.entity, entity_id,
response)
LOG.error(exc.message)
raise exc

Expand All @@ -199,7 +201,8 @@ def get(self, entity_id=None, filter_fields=None, fields=None):

r, response = self.send_get_request(url, **url_params)
if r.status_code != requests.codes.ok:
exc = exceptions.PowerFlexFailQuerying(self.entity, entity_id)
exc = exceptions.PowerFlexFailQuerying(self.entity, entity_id,
response)
LOG.error(exc.message)
raise exc
if filter_fields:
Expand All @@ -220,9 +223,11 @@ def get_related(self, entity_id, related, filter_fields=None, fields=None):
if r.status_code != requests.codes.ok:
msg = (
'Failed to query related {related} entities for PowerFlex '
'{entity} with id {_id}.'.format(related=related,
entity=self.entity,
_id=entity_id)
'{entity} with id {_id}.'
' Error: {response}'.format(related=related,
entity=self.entity,
_id=entity_id,
response=response)
)
LOG.error(msg)
raise exceptions.PowerFlexClientException(msg)
Expand Down
38 changes: 32 additions & 6 deletions PyPowerFlex/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@


class PowerFlexClientException(Exception):
def __init__(self, message):
def __init__(self, message, response=None):
self.message = message
self.response = response

def __str__(self):
return self.message
Expand Down Expand Up @@ -45,31 +46,56 @@ class InvalidInput(PowerFlexClientException):
class PowerFlexFailCreating(PowerFlexClientException):
base = 'Failed to create PowerFlex {entity}.'

def __init__(self, entity):
def __init__(self, entity, response=None):
self.message = self.base.format(entity=entity)
self.response = response
if response:
self.message = '{msg} Error: ' \
'{response}'.format(msg=self.message,
response=response)


class PowerFlexFailDeleting(PowerFlexClientException):
base = 'Failed to delete PowerFlex {entity} with id {_id}.'

def __init__(self, entity, entity_id):
def __init__(self, entity, entity_id, response=None):
self.message = self.base.format(entity=entity, _id=entity_id)
self.response = response
if response:
self.message = '{msg} Error: ' \
'{response}'.format(msg=self.message,
response=response)


class PowerFlexFailQuerying(PowerFlexClientException):
base = 'Failed to query PowerFlex {entity}'

def __init__(self, entity, entity_id=None):
def __init__(self, entity, entity_id=None, response=None):
base = self.base.format(entity=entity)
if entity_id:
self.response = response
if entity_id and response is None:
self.message = '{base} with id {_id}.'.format(base=base,
_id=entity_id)
elif entity is None and response:
self.message = '{base} Error: ' \
'{response}'.format(base=base,
response=response)
elif entity and response:
self.message = '{base} with id {_id}.' \
' Error: {response}'.format(base=base,
_id=entity_id,
response=response)
else:
self.message = '{base}.'.format(base=base)


class PowerFlexFailRenaming(PowerFlexClientException):
base = 'Failed to rename PowerFlex {entity} with id {_id}.'

def __init__(self, entity, entity_id):
def __init__(self, entity, entity_id, response=None):
self.message = self.base.format(entity=entity, _id=entity_id)
self.response = response
if response:
self.message = '{msg} Error: ' \
'{response}'.format(msg=self.message,
response=response)
27 changes: 27 additions & 0 deletions PyPowerFlex/objects/sdc.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,30 @@ def rename(self, sdc_id, name):
)

return self._rename_entity(action, sdc_id, params)

def set_performance_profile(self, sdc_id, perf_profile):
"""Apply a performance profile to the specified SDC.
:type sdc_id: str
:type perf_profile: str
:rtype: dict
"""

action = 'setSdcPerformanceParameters'

params = dict(
perfProfile=perf_profile
)

r, response = self.send_post_request(self.base_action_url, action, sdc_id, params)

if r.status_code != requests.codes.ok:
msg = ('Failed to set Performance Profile on '
'PowerFlex {entity} with id {_id} '
'. Error: {response}'.format(entity=self.entity,
_id=sdc_id,
response=response))
LOG.error(msg)
raise exceptions.PowerFlexClientException(msg)

return self.get(entity_id=sdc_id)
32 changes: 20 additions & 12 deletions PyPowerFlex/objects/snapshot_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ def add_source_volume(self, snapshot_policy_id, volume_id):
params=params)
if r.status_code != requests.codes.ok:
msg = ('Failed to add source volume to PowerFlex {entity} '
'with id {_id}.'.format(entity=self.entity,
_id=snapshot_policy_id))
'with id {_id}. '
'Error: {response}'.format(entity=self.entity,
_id=snapshot_policy_id,
response=response))
LOG.error(msg)
raise exceptions.PowerFlexClientException(msg)

Expand Down Expand Up @@ -118,8 +120,10 @@ def modify(self,
params=params)
if r.status_code != requests.codes.ok:
msg = ('Failed to modify PowerFlex {entity} '
'with id {_id}.'.format(entity=self.entity,
_id=snapshot_policy_id))
'with id {_id}. '
'Error: {response}'.format(entity=self.entity,
_id=snapshot_policy_id,
response=response))
LOG.error(msg)
raise exceptions.PowerFlexClientException(msg)

Expand All @@ -139,9 +143,10 @@ def pause(self, snapshot_policy_id):
entity=self.entity,
entity_id=snapshot_policy_id)
if r.status_code != requests.codes.ok:
msg = ('Failed to pause PowerFlex {entity} '
'with id {_id}.'.format(entity=self.entity,
_id=snapshot_policy_id))
msg = ('Failed to pause PowerFlex {entity} with id {_id}.'
' Error: {response}'.format(entity=self.entity,
_id=snapshot_policy_id,
response=response))
LOG.error(msg)
raise exceptions.PowerFlexClientException(msg)

Expand Down Expand Up @@ -178,8 +183,10 @@ def remove_source_volume(self,
params=params)
if r.status_code != requests.codes.ok:
msg = ('Failed to remove source volume from PowerFlex {entity} '
'with id {_id}.'.format(entity=self.entity,
_id=snapshot_policy_id))
'with id {_id}. '
'Error: {response}'.format(entity=self.entity,
_id=snapshot_policy_id,
response=response))
LOG.error(msg)
raise exceptions.PowerFlexClientException(msg)

Expand Down Expand Up @@ -215,9 +222,10 @@ def resume(self, snapshot_policy_id):
entity=self.entity,
entity_id=snapshot_policy_id)
if r.status_code != requests.codes.ok:
msg = ('Failed to resume PowerFlex {entity} '
'with id {_id}.'.format(entity=self.entity,
_id=snapshot_policy_id))
msg = ('Failed to resume PowerFlex {entity} with id {_id}. '
'Error: {response}'.format(entity=self.entity,
_id=snapshot_policy_id,
response=response))
LOG.error(msg)
raise exceptions.PowerFlexClientException(msg)

Expand Down
56 changes: 38 additions & 18 deletions PyPowerFlex/objects/storage_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,9 @@ def set_checksum_enabled(self, storage_pool_id, checksum_enabled):
params=params)
if r.status_code != requests.codes.ok:
msg = ('Failed to enable/disable checksum for PowerFlex {entity} '
'with id {_id}.'.format(entity=self.entity,
_id=storage_pool_id))
'with id {_id}. Error: {response}'.format(entity=self.entity,
_id=storage_pool_id,
response=response))
LOG.error(msg)
raise exceptions.PowerFlexClientException(msg)

Expand All @@ -245,8 +246,9 @@ def set_compression_method(self, storage_pool_id, compression_method):
params=params)
if r.status_code != requests.codes.ok:
msg = ('Failed to set compression method for PowerFlex {entity} '
'with id {_id}.'.format(entity=self.entity,
_id=storage_pool_id))
'with id {_id}. Error: {response}'.format(entity=self.entity,
_id=storage_pool_id,
response=response))
LOG.error(msg)
raise exceptions.PowerFlexClientException(msg)

Expand Down Expand Up @@ -289,8 +291,9 @@ def set_external_acceleration_type(
params=params)
if r.status_code != requests.codes.ok:
msg = ('Failed to set external acceleration type for PowerFlex '
'{entity} with id {_id}.'.format(entity=self.entity,
_id=storage_pool_id))
'{entity} with id {_id}. Error: {response}'.format(entity=self.entity,
_id=storage_pool_id,
response=response))
LOG.error(msg)
raise exceptions.PowerFlexClientException(msg)

Expand Down Expand Up @@ -323,8 +326,11 @@ def set_media_type(self,
params=params)
if r.status_code != requests.codes.ok:
msg = ('Failed to set media type for PowerFlex {entity} '
'with id {_id}.'.format(entity=self.entity,
_id=storage_pool_id))
'with id {_id}. Error: {response}'.format(
entity=self.entity,
_id=storage_pool_id,
response=response))

LOG.error(msg)
raise exceptions.PowerFlexClientException(msg)

Expand All @@ -351,8 +357,10 @@ def set_rebalance_enabled(self, storage_pool_id, rebalance_enabled):
params=params)
if r.status_code != requests.codes.ok:
msg = ('Failed to enable/disable rebalance for PowerFlex {entity} '
'with id {_id}.'.format(entity=self.entity,
_id=storage_pool_id))
'with id {_id}. Error: {response}'.format(
entity=self.entity,
_id=storage_pool_id,
response=response))
LOG.error(msg)
raise exceptions.PowerFlexClientException(msg)

Expand Down Expand Up @@ -407,8 +415,11 @@ def set_spare_percentage(self, storage_pool_id, spare_percentage):
params=params)
if r.status_code != requests.codes.ok:
msg = ('Failed to set spare percentage for PowerFlex {entity} '
'with id {_id}.'.format(entity=self.entity,
_id=storage_pool_id))
'with id {_id}. Error: {response}'.format(
entity=self.entity,
_id=storage_pool_id,
response=response))

LOG.error(msg)
raise exceptions.PowerFlexClientException(msg)

Expand All @@ -432,8 +443,11 @@ def set_use_rfcache(self, storage_pool_id, use_rfcache):
entity_id=storage_pool_id)
if r.status_code != requests.codes.ok:
msg = ('Failed to set Rfcache usage for PowerFlex {entity} '
'with id {_id}.'.format(entity=self.entity,
_id=storage_pool_id))
'with id {_id}. Error: {response}'.format(
entity=self.entity,
_id=storage_pool_id,
response=response))

LOG.error(msg)
raise exceptions.PowerFlexClientException(msg)

Expand All @@ -460,9 +474,13 @@ def set_use_rmcache(self, storage_pool_id, use_rmcache):
params=params)
if r.status_code != requests.codes.ok:
msg = ('Failed to set Rmcache usage for PowerFlex {entity} '
'with id {_id}.'.format(entity=self.entity,
_id=storage_pool_id))
'with id {_id}. Error: {response}'.format(
entity=self.entity,
_id=storage_pool_id,
response=response))

LOG.error(msg)

raise exceptions.PowerFlexClientException(msg)

return self.get(entity_id=storage_pool_id)
Expand All @@ -488,8 +506,10 @@ def set_zero_padding_policy(self, storage_pool_id, zero_padding_enabled):
params=params)
if r.status_code != requests.codes.ok:
msg = ('Failed to set Zero Padding policy for PowerFlex {entity} '
'with id {_id}.'.format(entity=self.entity,
_id=storage_pool_id))
'with id {_id}. Error: {response}'.format(
entity=self.entity,
_id=storage_pool_id,
response=response))
LOG.error(msg)
raise exceptions.PowerFlexClientException(msg)

Expand Down
20 changes: 15 additions & 5 deletions PyPowerFlex/objects/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,10 @@ def remove_cg_snapshots(self, system_id, cg_id, allow_ext_managed=None):
params=params)
if r.status_code != requests.codes.ok:
msg = ('Failed to remove consistency group snapshots from '
'PowerFlex {entity} with '
'id {_id}.'.format(entity=self.entity, _id=system_id))
'PowerFlex {entity} with id {_id}. '
'Error: {response}'.format(entity=self.entity,
_id=system_id,
response=response))
LOG.error(msg)
raise exceptions.PowerFlexClientException(msg)

Expand All @@ -115,9 +117,13 @@ def remove_cg_snapshots(self, system_id, cg_id, allow_ext_managed=None):
def snapshot_volumes(self,
system_id,
snapshot_defs,
access_mode=None,
retention_period=None,
allow_ext_managed=None):
"""Create snapshots of PowerFlex volumes.
:type retention_period: str
:type access_mode: str
:type system_id: str
:type snapshot_defs: list[dict]
:type allow_ext_managed: bool
Expand All @@ -128,7 +134,9 @@ def snapshot_volumes(self,

params = dict(
snapshotDefs=snapshot_defs,
allowOnExtManagedVol=allow_ext_managed
allowOnExtManagedVol=allow_ext_managed,
accessModeLimit=access_mode,
retentionPeriodInMin=retention_period
)

r, response = self.send_post_request(self.base_action_url,
Expand All @@ -138,8 +146,10 @@ def snapshot_volumes(self,
params=params)
if r.status_code != requests.codes.ok:
msg = ('Failed to snapshot volumes on PowerFlex {entity} '
'with id {_id}.'.format(entity=self.entity,
_id=system_id))
'with id {_id}.'
' Error: {response}'.format(entity=self.entity,
_id=system_id,
response=response))
LOG.error(msg)
raise exceptions.PowerFlexClientException(msg)

Expand Down
Loading

0 comments on commit 0bc8f5c

Please sign in to comment.