def create_from_src(self, cgsnapshot_id, source_cgid, name=None, description=None, user_id=None, project_id=None): """Creates a consistencygroup from a cgsnapshot or a source CG. :param cgsnapshot_id: UUID of a CGSnapshot :param source_cgid: UUID of a source CG :param name: Name of the ConsistencyGroup :param description: Description of the ConsistencyGroup :param user_id: User id derived from context :param project_id: Project id derived from context :rtype: A dictionary containing Consistencygroup metadata """ body = { 'consistencygroup-from-src': { 'name': name, 'description': description, 'cgsnapshot_id': cgsnapshot_id, 'source_cgid': source_cgid, 'user_id': user_id, 'project_id': project_id, 'status': "creating", } } self.run_hooks('modify_body_for_update', body, 'consistencygroup-from-src') resp, body = self.api.client.post("/consistencygroups/create_from_src", body=body) return common_base.DictWithMeta(body['consistencygroup'], resp)
def test_dict_with_meta(self): resp = create_response_obj_with_header() obj = common_base.DictWithMeta([], resp) self.assertEqual({}, obj) # Check request_ids attribute is added to obj self.assertTrue(hasattr(obj, 'request_ids')) self.assertEqual([REQUEST_ID], obj.request_ids)
def create_from_src(self, group_snapshot_id, source_group_id, name=None, description=None, user_id=None, project_id=None): """Creates a group from a group snapshot or a source group. :param group_snapshot_id: UUID of a GroupSnapshot :param source_group_id: UUID of a source Group :param name: Name of the Group :param description: Description of the Group :param user_id: User id derived from context :param project_id: Project id derived from context :rtype: A dictionary containing Group metadata """ body = { 'create-from-src': { 'name': name, 'description': description, 'group_snapshot_id': group_snapshot_id, 'source_group_id': source_group_id, 'user_id': user_id, 'project_id': project_id, 'status': "creating", } } self.run_hooks('modify_body_for_action', body, 'create-from-src') resp, body = self.api.client.post("/groups/action", body=body) return common_base.DictWithMeta(body['group'], resp)
def export_record(self, backup_id): """Export volume backup metadata record. :param backup_id: The ID of the backup to export. :rtype: A dictionary containing 'backup_url' and 'backup_service'. """ resp, body = \ self.api.client.get("/backups/%s/export_record" % backup_id) return common_base.DictWithMeta(body['backup-record'], resp)
def get_encryption_metadata(self, volume_id): """ Retrieve the encryption metadata from the desired volume. :param volume_id: the id of the volume to query :return: a dictionary of volume encryption metadata """ metadata = self._get("/volumes/%s/encryption" % volume_id) return common_base.DictWithMeta(metadata._info, metadata.request_ids)
def initialize_connection(self, volume, connector): """Initialize a volume connection. :param volume: The :class:`Volume` (or its ID). :param connector: connector dict from nova. """ resp, body = self._action('os-initialize_connection', volume, {'connector': connector}) return common_base.DictWithMeta(body['connection_info'], resp)
def _create(self, url, body, response_key, return_raw=False, **kwargs): self.run_hooks('modify_body_for_create', body, **kwargs) resp, body = self.api.client.post(url, body=body) if return_raw: return common_base.DictWithMeta(body[response_key], resp) with self.completion_cache('human_id', self.resource_class, mode="a"): with self.completion_cache('uuid', self.resource_class, mode="a"): return self.resource_class(self, body[response_key], resp=resp)
def migrate_volume_completion(self, old_volume, new_volume, error): """Complete the migration from the old volume to the temp new one. :param old_volume: The original :class:`Volume` in the migration :param new_volume: The new temporary :class:`Volume` in the migration :param error: Inform of an error to cause migration cleanup """ new_volume_id = base.getid(new_volume) resp, body = self._action('os-migrate_volume_completion', old_volume, {'new_volume': new_volume_id, 'error': error}) return common_base.DictWithMeta(body, resp)
def import_record(self, backup_service, backup_url): """Import volume backup metadata record. :param backup_service: Backup service to use for importing the backup :param backup_url: Backup URL for importing the backup metadata :rtype: A dictionary containing volume backup metadata. """ body = {'backup-record': {'backup_service': backup_service, 'backup_url': backup_url}} self.run_hooks('modify_body_for_update', body, 'backup-record') resp, body = self.api.client.post("/backups/import_record", body=body) return common_base.DictWithMeta(body['backup'], resp)
def _update(self, url, body, response_key=None, **kwargs): self.run_hooks('modify_body_for_update', body, **kwargs) resp, body = self.api.client.put(url, body=body, **kwargs) if response_key: return self.resource_class(self, body[response_key], loaded=True, resp=resp) # (NOTE)ankit: In case of qos_specs.unset_keys method, None is # returned back to the caller and in all other cases dict is # returned but in order to return request_ids to the caller, it's # not possible to return None so returning DictWithMeta for all cases. body = body or {} return common_base.DictWithMeta(body, resp)