示例#1
0
    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)

        return self.resource_class(self, body[response_key], resp=resp)
示例#2
0
    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
        """

        # NOTE(wanghao): According the API schema in cinder side, client
        # should NOT specify the group_snapshot_id and source_group_id at
        # same time, even one of them is None.
        if group_snapshot_id:
            create_key = 'group_snapshot_id'
            create_value = group_snapshot_id
        elif source_group_id:
            create_key = 'source_group_id'
            create_value = source_group_id

        body = {'create-from-src': {'name': name,
                                    'description': description,
                                    create_key: create_value}}

        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)
示例#3
0
    def create_from_src(self,
                        cgsnapshot_id,
                        source_cgid,
                        name=None,
                        description=None,
                        user_id=None,
                        project_id=None):
        """Creates a consistency group 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)
示例#4
0
    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)
示例#5
0
 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)
示例#6
0
    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)
示例#7
0
    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 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)
示例#9
0
    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)
示例#10
0
    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)
示例#11
0
    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)
示例#12
0
    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)