def clone(self, new_vol_name, resource_uri, sync, synctimeout=0): """Makes REST API call to clone volume. :param new_vol_name: name of volume :param resource_uri: uri of source volume :param sync : synchronous request :param synctimeout : Query for task status for "synctimeout" secs. If the task doesn't complete in synctimeout secs, an exception is thrown :returns: Created task details in JSON response payload """ is_snapshot_clone = False clone_full_uri = None # consistency group if resource_uri.find("BlockConsistencyGroup") > 0: clone_full_uri = Volume.URI_CG_CLONE.format(resource_uri) elif resource_uri.find("BlockSnapshot") > 0: is_snapshot_clone = True clone_full_uri = ( Volume.URI_SNAPSHOT_PROTECTION_FULLCOPIES.format(resource_uri)) else: clone_full_uri = ( Volume.URI_VOLUME_PROTECTION_FULLCOPIES.format(resource_uri)) request = { 'name': new_vol_name, 'type': None, 'count': 1 } request["count"] = 1 body = oslo_serialization.jsonutils.dumps(request) (s, h) = common.service_json_request(self.ipaddr, self.port, "POST", clone_full_uri, body) o = common.json_decode(s) if sync: task = o["task"][0] if is_snapshot_clone: return ( common.block_until_complete( "block", task["resource"]["id"], task["id"], self.ipaddr, self.port) ) else: return self.check_for_sync(task, sync, synctimeout) else: return o
def check_for_sync(self, result, sync, synctimeout=0): if len(result["resource"]) > 0: resource = result["resource"] return (common.block_until_complete("consistencygroup", resource["id"], result["id"], self.ipaddr, self.port, synctimeout)) else: raise common.CoprHdError( common.CoprHdError.SOS_FAILURE_ERR, _("error: task list is empty, no task response found"))
def check_for_sync(self, result, sync, synctimeout=0): if len(result["resource"]) > 0: resource = result["resource"] return ( common.block_until_complete("consistencygroup", resource["id"], result["id"], self.ipaddr, self.port, synctimeout) ) else: raise common.CoprHdError( common.CoprHdError.SOS_FAILURE_ERR, _("error: task list is empty, no task response found"))
def clone(self, new_vol_name, resource_uri, sync, synctimeout=0): """Makes REST API call to clone volume. :param new_vol_name: name of volume :param resource_uri: uri of source volume :param sync: synchronous request :param synctimeout: Query for task status for 'synctimeout' secs. If the task doesn't complete in synctimeout secs, an exception is thrown :returns: Created task details in JSON response payload """ is_snapshot_clone = False clone_full_uri = None # consistency group if resource_uri.find("BlockConsistencyGroup") > 0: clone_full_uri = Volume.URI_CG_CLONE.format(resource_uri) elif resource_uri.find("BlockSnapshot") > 0: is_snapshot_clone = True clone_full_uri = ( Volume.URI_SNAPSHOT_PROTECTION_FULLCOPIES.format(resource_uri)) else: clone_full_uri = ( Volume.URI_VOLUME_PROTECTION_FULLCOPIES.format(resource_uri)) request = {'name': new_vol_name, 'type': None, 'count': 1} request["count"] = 1 body = oslo_serialization.jsonutils.dumps(request) (s, h) = common.service_json_request(self.ipaddr, self.port, "POST", clone_full_uri, body) o = common.json_decode(s) if sync: task = o["task"][0] if is_snapshot_clone: return (common.block_until_complete("block", task["resource"]["id"], task["id"], self.ipaddr, self.port)) else: return self.check_for_sync(task, sync, synctimeout) else: return o
def snapshot_delete_uri(self, otype, resource_uri, suri, sync, synctimeout=0): """Delete a snapshot by uri. :param otype : block :param resource_uri: uri of the source resource :param suri : Uri of the Snapshot :param sync : To perform operation synchronously :param synctimeout : Query for task status for "synctimeout" secs. If the task doesn't complete in synctimeout secs, an exception is thrown """ s = None if resource_uri.find("Volume") > 0: (s, h) = common.service_json_request( self.ipaddr, self.port, "POST", Snapshot.URI_RESOURCE_DEACTIVATE.format( Snapshot.URI_BLOCK_SNAPSHOTS.format(suri)), None) elif resource_uri.find("BlockConsistencyGroup") > 0: (s, h) = common.service_json_request( self.ipaddr, self.port, "POST", Snapshot.URI_CONSISTENCY_GROUPS_SNAPSHOT_DEACTIVATE.format( resource_uri, suri), None) o = common.json_decode(s) task = o["task"][0] if sync: return ( common.block_until_complete( otype, task['resource']['id'], task["id"], self.ipaddr, self.port, synctimeout) ) else: return o
def snapshot_delete_uri(self, otype, resource_uri, suri, sync, synctimeout=0): """Delete a snapshot by uri. :param otype : block :param resource_uri: uri of the source resource :param suri : Uri of the Snapshot :param sync : To perform operation synchronously :param synctimeout : Query for task status for "synctimeout" secs. If the task doesn't complete in synctimeout secs, an exception is thrown """ s = None if resource_uri.find("Volume") > 0: (s, h) = common.service_json_request( self.ipaddr, self.port, "POST", Snapshot.URI_RESOURCE_DEACTIVATE.format( Snapshot.URI_BLOCK_SNAPSHOTS.format(suri)), None) elif resource_uri.find("BlockConsistencyGroup") > 0: (s, h) = common.service_json_request( self.ipaddr, self.port, "POST", Snapshot.URI_CONSISTENCY_GROUPS_SNAPSHOT_DEACTIVATE.format( resource_uri, suri), None) o = common.json_decode(s) task = o["task"][0] if sync: return (common.block_until_complete(otype, task['resource']['id'], task["id"], self.ipaddr, self.port, synctimeout)) else: return o
def snapshot_create(self, otype, typename, ouri, snaplabel, inactive, sync, readonly=False, synctimeout=0): """New snapshot is created, for a given volume. :param otype : block type should be provided :param typename : either volume or consistency-groups should be provided :param ouri : uri of volume :param snaplabel : name of the snapshot :param inactive : if true, the snapshot will not activate the synchronization between source and target volumes :param sync : synchronous request :param synctimeout : Query for task status for "synctimeout" secs. If the task doesn't complete in synctimeout secs, an exception is thrown """ # check snapshot is already exist is_snapshot_exist = True try: self.snapshot_query(otype, typename, ouri, snaplabel) except common.CoprHdError as e: if e.err_code == common.CoprHdError.NOT_FOUND_ERR: is_snapshot_exist = False else: raise if is_snapshot_exist: raise common.CoprHdError( common.CoprHdError.ENTRY_ALREADY_EXISTS_ERR, (_("Snapshot with name %(snaplabel)s" " already exists under %(typename)s") % { 'snaplabel': snaplabel, 'typename': typename })) parms = { 'name': snaplabel, # if true, the snapshot will not activate the synchronization # between source and target volumes 'create_inactive': inactive } if readonly is True: parms['read_only'] = readonly body = oslo_serialization.jsonutils.dumps(parms) # REST api call (s, h) = common.service_json_request( self.ipaddr, self.port, "POST", Snapshot.URI_SNAPSHOT_LIST.format(otype, typename, ouri), body) o = common.json_decode(s) task = o["task"][0] if sync: return (common.block_until_complete(otype, task['resource']['id'], task["id"], self.ipaddr, self.port, synctimeout)) else: return o
def snapshot_create(self, otype, typename, ouri, snaplabel, inactive, sync, readonly=False, synctimeout=0): """New snapshot is created, for a given volume. :param otype : block type should be provided :param typename : either volume or consistency-groups should be provided :param ouri : uri of volume :param snaplabel : name of the snapshot :param inactive : if true, the snapshot will not activate the synchronization between source and target volumes :param sync : synchronous request :param synctimeout : Query for task status for "synctimeout" secs. If the task doesn't complete in synctimeout secs, an exception is thrown """ # check snapshot is already exist is_snapshot_exist = True try: self.snapshot_query(otype, typename, ouri, snaplabel) except common.CoprHdError as e: if e.err_code == common.CoprHdError.NOT_FOUND_ERR: is_snapshot_exist = False else: raise if is_snapshot_exist: raise common.CoprHdError( common.CoprHdError.ENTRY_ALREADY_EXISTS_ERR, (_("Snapshot with name %(snaplabel)s" " already exists under %(typename)s") % {'snaplabel': snaplabel, 'typename': typename })) parms = { 'name': snaplabel, # if true, the snapshot will not activate the synchronization # between source and target volumes 'create_inactive': inactive } if readonly is True: parms['read_only'] = readonly body = oslo_serialization.jsonutils.dumps(parms) # REST api call (s, h) = common.service_json_request( self.ipaddr, self.port, "POST", Snapshot.URI_SNAPSHOT_LIST.format(otype, typename, ouri), body) o = common.json_decode(s) task = o["task"][0] if sync: return ( common.block_until_complete( otype, task['resource']['id'], task["id"], self.ipaddr, self.port, synctimeout) ) else: return o