diff --git a/PyPowerFlex/objects/volume.py b/PyPowerFlex/objects/volume.py index 7a997d1..8200da0 100644 --- a/PyPowerFlex/objects/volume.py +++ b/PyPowerFlex/objects/volume.py @@ -522,3 +522,64 @@ def set_volume_access_mode_limit(self, volume_id, access_mode_limit): raise exceptions.PowerFlexClientException(msg) return self.get(entity_id=volume_id) + + def migrate_vtree(self, + volume_id, + dest_sp_id, + ignore_dest_capacity=None, + queue_position=None, + vol_type_conversion=None, + allow_thick_non_zero=None, + compression_method=None): +""" + Migrates a volume from one storage pool (SP) to another. + + Args: + volume_id (str): The ID of the volume to be migrated. + dest_sp_id (str): The ID of the destination storage pool. + ignore_dest_capacity (bool, optional): Whether to ignore the destination storage pool's capacity. Defaults to None. + queue_position (int, optional): The position in the migration queue. Defaults to None. + vol_type_conversion (bool, optional): Whether to allow volume type conversion. Defaults to None. + allow_thick_non_zero (bool, optional): Whether to allow thick non-zero volumes. Defaults to None. + compression_method (str, optional): The compression method to use. Defaults to None. + + Raises: + InvalidInput: If either volume_id or dest_sp_id is not set. + PowerFlexClientException: If the migration fails. + + Returns: + dict: The updated volume information. + + """ + action = 'migrateVTree' + + if not all([volume_id, dest_sp_id]): + msg = 'Both volume_id and dest_sp_id must be set.' + raise exceptions.InvalidInput(msg) + + params = dict( + id=volume_id, + destSPId=dest_sp_id, + ignoreDestinationCapacity=ignore_dest_capacity, + queuePosition=queue_position, + volTypeConversion=vol_type_conversion, + allowThickNonZeroPaddedVTree=allow_thick_non_zero, + compressionMethod=compression_method + ) + + r, response = self.send_post_request(self.base_action_url, + action=action, + entity=self.entity, + entity_id=volume_id, + params=params) + + if r.status_code != requests.codes.ok: + msg = ('Failed to migrate PowerFlex {entity} with id {_id} ' + 'Error: {response}'.format(entity=self.entity,_id=volume_id, response=response)) + + LOG.error(msg) + + raise exceptions.PowerFlexClientException(msg) + + return self.get(entity_id=volume_id) +