def obj_load_attr(self, attrname):
        if attrname not in OPTIONAL_FIELDS:
            raise exception.ObjectActionError(
                action='obj_load_attr',
                reason=_('attribute %s not lazy-loadable') % attrname)
        if not self._context:
            raise exception.OrphanedObjectError(method='obj_load_attr',
                                                objtype=self.obj_name())

        if attrname == 'metadata':
            self.metadata = db.volume_metadata_get(self._context, self.id)
        elif attrname == 'admin_metadata':
            with self.obj_as_admin():
                self.admin_metadata = db.volume_admin_metadata_get(
                    self._context, self.id)
        elif attrname == 'volume_type':
            self.volume_type = objects.VolumeType.get_by_id(
                self._context, self.volume_type_id)
        elif attrname == 'volume_attachment':
            attachments = (
                objects.VolumeAttachmentList.get_all_by_volume_id(
                    self._context, self.id))
            self.volume_attachment = attachments.objects

        self.obj_reset_changes(fields=[attrname])
Пример #2
0
    def obj_load_attr(self, attrname):
        if attrname not in OPTIONAL_FIELDS:
            raise exception.ObjectActionError(
                action='obj_load_attr',
                reason=_('attribute %s not lazy-loadable') % attrname)
        if not self._context:
            raise exception.OrphanedObjectError(method='obj_load_attr',
                                                objtype=self.obj_name())

        if attrname == 'metadata':
            self.metadata = db.volume_metadata_get(self._context, self.id)
        elif attrname == 'admin_metadata':
            self.admin_metadata = {}
            if self._context.is_admin:
                self.admin_metadata = db.volume_admin_metadata_get(
                    self._context, self.id)
        elif attrname == 'volume_type':
            self.volume_type = objects.VolumeType.get_by_id(
                self._context, self.volume_type_id)
        elif attrname == 'volume_attachment':
            attachments = (objects.VolumeAttachmentList.get_all_by_volume_id(
                self._context, self.id))
            self.volume_attachment = attachments.objects

        self.obj_reset_changes(fields=[attrname])
Пример #3
0
    def obj_load_attr(self, attrname):
        if attrname not in self.OPTIONAL_FIELDS:
            raise exception.ObjectActionError(
                action='obj_load_attr',
                reason=_('attribute %s not lazy-loadable') % attrname)
        if not self._context:
            raise exception.OrphanedObjectError(method='obj_load_attr',
                                                objtype=self.obj_name())

        if attrname == 'metadata':
            self.metadata = db.volume_metadata_get(self._context, self.id)
        elif attrname == 'admin_metadata':
            self.admin_metadata = {}
            if self._context.is_admin:
                self.admin_metadata = db.volume_admin_metadata_get(
                    self._context, self.id)
        elif attrname == 'glance_metadata':
            self.glance_metadata = db.volume_glance_metadata_get(
                self._context, self.id)
        elif attrname == 'volume_type':
            self.volume_type = objects.VolumeType.get_by_id(
                self._context, self.volume_type_id)
        elif attrname == 'volume_attachment':
            attachments = objects.VolumeAttachmentList.get_all_by_volume_id(
                self._context, self.id)
            self.volume_attachment = attachments
        elif attrname == 'consistencygroup':
            consistencygroup = objects.ConsistencyGroup.get_by_id(
                self._context, self.consistencygroup_id)
            self.consistencygroup = consistencygroup
        elif attrname == 'snapshots':
            self.snapshots = objects.SnapshotList.get_all_for_volume(
                self._context, self.id)

        self.obj_reset_changes(fields=[attrname])
Пример #4
0
    def obj_load_attr(self, attrname):
        if attrname not in self.OPTIONAL_FIELDS:
            raise exception.ObjectActionError(
                action="obj_load_attr", reason=_("attribute %s not lazy-loadable") % attrname
            )
        if not self._context:
            raise exception.OrphanedObjectError(method="obj_load_attr", objtype=self.obj_name())

        if attrname == "metadata":
            self.metadata = db.volume_metadata_get(self._context, self.id)
        elif attrname == "admin_metadata":
            self.admin_metadata = {}
            if self._context.is_admin:
                self.admin_metadata = db.volume_admin_metadata_get(self._context, self.id)
        elif attrname == "glance_metadata":
            self.glance_metadata = db.volume_glance_metadata_get(self._context, self.id)
        elif attrname == "volume_type":
            self.volume_type = objects.VolumeType.get_by_id(self._context, self.volume_type_id)
        elif attrname == "volume_attachment":
            attachments = objects.VolumeAttachmentList.get_all_by_volume_id(self._context, self.id)
            self.volume_attachment = attachments
        elif attrname == "consistencygroup":
            consistencygroup = objects.ConsistencyGroup.get_by_id(self._context, self.consistencygroup_id)
            self.consistencygroup = consistencygroup
        elif attrname == "snapshots":
            self.snapshots = objects.SnapshotList.get_all_for_volume(self._context, self.id)

        self.obj_reset_changes(fields=[attrname])
Пример #5
0
    def obj_load_attr(self, attrname):
        if attrname not in self.OPTIONAL_FIELDS:
            raise exception.ObjectActionError(
                action='obj_load_attr',
                reason=_('attribute %s not lazy-loadable') % attrname)
        if not self._context:
            raise exception.OrphanedObjectError(method='obj_load_attr',
                                                objtype=self.obj_name())

        if attrname == 'metadata':
            self.metadata = db.volume_metadata_get(self._context, self.id)
        elif attrname == 'admin_metadata':
            self.admin_metadata = {}
            if self._context.is_admin:
                self.admin_metadata = db.volume_admin_metadata_get(
                    self._context, self.id)
        elif attrname == 'glance_metadata':
            try:
                # NOTE(dulek): We're using alias here to have conversion from
                # list to dict done there.
                self.volume_glance_metadata = db.volume_glance_metadata_get(
                    self._context, self.id)
            except exception.GlanceMetadataNotFound:
                # NOTE(dulek): DB API raises when volume has no
                # glance_metadata. Silencing this because at this level no
                # metadata is a completely valid result.
                self.glance_metadata = {}
        elif attrname == 'volume_type':
            # If the volume doesn't have volume_type, VolumeType.get_by_id
            # would trigger a db call which raise VolumeTypeNotFound exception.
            self.volume_type = (objects.VolumeType.get_by_id(
                self._context, self.volume_type_id) if self.volume_type_id
                else None)
        elif attrname == 'volume_attachment':
            attachments = objects.VolumeAttachmentList.get_all_by_volume_id(
                self._context, self.id)
            self.volume_attachment = attachments
        elif attrname == 'consistencygroup':
            consistencygroup = objects.ConsistencyGroup.get_by_id(
                self._context, self.consistencygroup_id)
            self.consistencygroup = consistencygroup
        elif attrname == 'snapshots':
            self.snapshots = objects.SnapshotList.get_all_for_volume(
                self._context, self.id)
        elif attrname == 'cluster':
            # If this volume doesn't belong to a cluster (cluster_name is
            # empty), then cluster field will be None.
            if self.cluster_name:
                self.cluster = objects.Cluster.get_by_id(
                    self._context, name=self.cluster_name)
            else:
                self.cluster = None
        elif attrname == 'group':
            group = objects.Group.get_by_id(
                self._context, self.group_id)
            self.group = group

        self.obj_reset_changes(fields=[attrname])
Пример #6
0
    def test_volume_metadata_update_delete(self):
        metadata1 = {'a': '1', 'c': '2'}
        metadata2 = {'a': '3', 'd': '4'}
        should_be = metadata2

        db.volume_create(self.ctxt, {'id': 1, 'metadata': metadata1})
        db.volume_metadata_update(self.ctxt, 1, metadata2, True)

        self.assertEqual(should_be, db.volume_metadata_get(self.ctxt, 1))
Пример #7
0
    def test_volume_metadata_update_delete(self):
        metadata1 = {'a': '1', 'c': '2'}
        metadata2 = {'a': '3', 'd': '4'}
        should_be = metadata2

        db.volume_create(self.ctxt, {'id': 1, 'metadata': metadata1})
        db.volume_metadata_update(self.ctxt, 1, metadata2, True)

        self.assertEquals(should_be, db.volume_metadata_get(self.ctxt, 1))
Пример #8
0
    def test_volume_metadata_update(self):
        metadata1 = {'a': '1', 'c': '2'}
        metadata2 = {'a': '3', 'd': '5'}
        should_be = {'a': '3', 'c': '2', 'd': '5'}

        db.volume_create(self.ctxt, {'id': 1, 'metadata': metadata1})
        db.volume_metadata_update(self.ctxt, 1, metadata2, False)

        self.assertEquals(should_be, db.volume_metadata_get(self.ctxt, 1))
Пример #9
0
    def test_volume_metadata_update(self):
        metadata1 = {'a': '1', 'c': '2'}
        metadata2 = {'a': '3', 'd': '5'}
        should_be = {'a': '3', 'c': '2', 'd': '5'}

        db.volume_create(self.ctxt, {'id': 1, 'metadata': metadata1})
        db.volume_metadata_update(self.ctxt, 1, metadata2, False)

        self.assertEqual(should_be, db.volume_metadata_get(self.ctxt, 1))
Пример #10
0
    def obj_load_attr(self, attrname):
        if attrname not in self.OPTIONAL_FIELDS:
            raise exception.ObjectActionError(
                action='obj_load_attr',
                reason=_('attribute %s not lazy-loadable') % attrname)
        if not self._context:
            raise exception.OrphanedObjectError(method='obj_load_attr',
                                                objtype=self.obj_name())

        if attrname == 'metadata':
            self.metadata = db.volume_metadata_get(self._context, self.id)
        elif attrname == 'admin_metadata':
            self.admin_metadata = {}
            if self._context.is_admin:
                self.admin_metadata = db.volume_admin_metadata_get(
                    self._context, self.id)
        elif attrname == 'glance_metadata':
            try:
                # NOTE(dulek): We're using alias here to have conversion from
                # list to dict done there.
                self.volume_glance_metadata = db.volume_glance_metadata_get(
                    self._context, self.id)
            except exception.GlanceMetadataNotFound:
                # NOTE(dulek): DB API raises when volume has no
                # glance_metadata. Silencing this because at this level no
                # metadata is a completely valid result.
                self.glance_metadata = {}
        elif attrname == 'volume_type':
            # If the volume doesn't have volume_type, VolumeType.get_by_id
            # would trigger a db call which raise VolumeTypeNotFound exception.
            self.volume_type = (objects.VolumeType.get_by_id(
                self._context, self.volume_type_id)
                                if self.volume_type_id else None)
        elif attrname == 'volume_attachment':
            attachments = objects.VolumeAttachmentList.get_all_by_volume_id(
                self._context, self.id)
            self.volume_attachment = attachments
        elif attrname == 'consistencygroup':
            consistencygroup = objects.ConsistencyGroup.get_by_id(
                self._context, self.consistencygroup_id)
            self.consistencygroup = consistencygroup
        elif attrname == 'snapshots':
            self.snapshots = objects.SnapshotList.get_all_for_volume(
                self._context, self.id)
        elif attrname == 'cluster':
            # If this volume doesn't belong to a cluster (cluster_name is
            # empty), then cluster field will be None.
            if self.cluster_name:
                self.cluster = objects.Cluster.get_by_id(
                    self._context, name=self.cluster_name)
            else:
                self.cluster = None
        elif attrname == 'group':
            group = objects.Group.get_by_id(self._context, self.group_id)
            self.group = group

        self.obj_reset_changes(fields=[attrname])
Пример #11
0
    def get_user_meta(self, vol_id):
        """
        Retrive the user metadata of the volume.

        :param vol_id: OpenStack Volume ID.
        """
        admin_context = context.get_admin_context()
        metadata = db.volume_metadata_get(admin_context, vol_id)
        return metadata
Пример #12
0
    def obj_load_attr(self, attrname):
        if attrname not in self.OPTIONAL_FIELDS:
            raise exception.ObjectActionError(
                action="obj_load_attr", reason=_("attribute %s not lazy-loadable") % attrname
            )
        if not self._context:
            raise exception.OrphanedObjectError(method="obj_load_attr", objtype=self.obj_name())

        if attrname == "metadata":
            self.metadata = db.volume_metadata_get(self._context, self.id)
        elif attrname == "admin_metadata":
            self.admin_metadata = {}
            if self._context.is_admin:
                self.admin_metadata = db.volume_admin_metadata_get(self._context, self.id)
        elif attrname == "glance_metadata":
            try:
                # NOTE(dulek): We're using alias here to have conversion from
                # list to dict done there.
                self.volume_glance_metadata = db.volume_glance_metadata_get(self._context, self.id)
            except exception.GlanceMetadataNotFound:
                # NOTE(dulek): DB API raises when volume has no
                # glance_metadata. Silencing this because at this level no
                # metadata is a completely valid result.
                self.glance_metadata = {}
        elif attrname == "volume_type":
            # If the volume doesn't have volume_type, VolumeType.get_by_id
            # would trigger a db call which raise VolumeTypeNotFound exception.
            self.volume_type = (
                objects.VolumeType.get_by_id(self._context, self.volume_type_id) if self.volume_type_id else None
            )
        elif attrname == "volume_attachment":
            attachments = objects.VolumeAttachmentList.get_all_by_volume_id(self._context, self.id)
            self.volume_attachment = attachments
        elif attrname == "consistencygroup":
            consistencygroup = objects.ConsistencyGroup.get_by_id(self._context, self.consistencygroup_id)
            self.consistencygroup = consistencygroup
        elif attrname == "snapshots":
            self.snapshots = objects.SnapshotList.get_all_for_volume(self._context, self.id)

        self.obj_reset_changes(fields=[attrname])
Пример #13
0
    def obj_load_attr(self, attrname):
        if attrname not in self.OPTIONAL_FIELDS:
            raise exception.ObjectActionError(
                action='obj_load_attr',
                reason=_('attribute %s not lazy-loadable') % attrname)
        if not self._context:
            raise exception.OrphanedObjectError(method='obj_load_attr',
                                                objtype=self.obj_name())

        if attrname == 'metadata':
            self.metadata = db.volume_metadata_get(self._context, self.id)
        elif attrname == 'admin_metadata':
            self.admin_metadata = {}
            if self._context.is_admin:
                self.admin_metadata = db.volume_admin_metadata_get(
                    self._context, self.id)
        elif attrname == 'glance_metadata':
            self.glance_metadata = db.volume_glance_metadata_get(
                self._context, self.id)
        elif attrname == 'volume_type':
            # If the volume doesn't have volume_type, VolumeType.get_by_id
            # would trigger a db call which raise VolumeTypeNotFound exception.
            self.volume_type = (objects.VolumeType.get_by_id(
                self._context, self.volume_type_id) if self.volume_type_id
                else None)
        elif attrname == 'volume_attachment':
            attachments = objects.VolumeAttachmentList.get_all_by_volume_id(
                self._context, self.id)
            self.volume_attachment = attachments
        elif attrname == 'consistencygroup':
            consistencygroup = objects.ConsistencyGroup.get_by_id(
                self._context, self.consistencygroup_id)
            self.consistencygroup = consistencygroup
        elif attrname == 'snapshots':
            self.snapshots = objects.SnapshotList.get_all_for_volume(
                self._context, self.id)

        self.obj_reset_changes(fields=[attrname])
Пример #14
0
 def test_volume_metadata_delete(self):
     metadata = {'a': 'b', 'c': 'd'}
     db.volume_create(self.ctxt, {'id': 1, 'metadata': metadata})
     db.volume_metadata_delete(self.ctxt, 1, 'c')
     metadata.pop('c')
     self.assertEquals(metadata, db.volume_metadata_get(self.ctxt, 1))
Пример #15
0
    def test_volume_metadata_get(self):
        metadata = {'a': 'b', 'c': 'd'}
        db.volume_create(self.ctxt, {'id': 1, 'metadata': metadata})

        self.assertEquals(metadata, db.volume_metadata_get(self.ctxt, 1))
Пример #16
0
 def test_volume_metadata_delete(self):
     metadata = {"a": "b", "c": "d"}
     db.volume_create(self.ctxt, {"id": 1, "metadata": metadata})
     db.volume_metadata_delete(self.ctxt, 1, "c")
     metadata.pop("c")
     self.assertEqual(metadata, db.volume_metadata_get(self.ctxt, 1))