コード例 #1
0
ファイル: test_db_api.py プロジェクト: niuzhenguo/cinder
    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))
コード例 #2
0
ファイル: test_db_api.py プロジェクト: CloudVPS/cinder
    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))
コード例 #3
0
ファイル: test_db_api.py プロジェクト: medlefsen/cinder
    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))
コード例 #4
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))
コード例 #5
0
    def _add_metadata(self, vol_meta=False, vol_glance_meta=False):
        if vol_meta:
            # Add some VolumeMetadata
            db.volume_metadata_update(self.ctxt, self.volume_id, {"fee": "fi"}, False)
            db.volume_metadata_update(self.ctxt, self.volume_id, {"fo": "fum"}, False)

        if vol_glance_meta:
            # Add some GlanceMetadata
            db.volume_glance_metadata_create(self.ctxt, self.volume_id, "disk_format", "bare")
            db.volume_glance_metadata_create(self.ctxt, self.volume_id, "container_type", "ovf")
コード例 #6
0
ファイル: api.py プロジェクト: amol/softlayer-cinder-driver
    def update_user_meta(self, vol_id, metadata, delete=False):
        """
        Update the user metadata of the given volume

        :param vol_id: OpenStack volume ID.
        :param metadata: dict containing metadata to be updated
        :param delete: True if update should result in deletion of existing
        """
        admin_context = context.get_admin_context()
        db.volume_metadata_update(admin_context, vol_id,
                                  metadata, delete)
コード例 #7
0
    def _add_metadata(self, vol_meta=False, vol_glance_meta=False):
        if vol_meta:
            # Add some VolumeMetadata
            db.volume_metadata_update(self.ctxt, self.volume_id,
                                      {'fee': 'fi'}, False)
            db.volume_metadata_update(self.ctxt, self.volume_id,
                                      {'fo': 'fum'}, False)

        if vol_glance_meta:
            # Add some GlanceMetadata
            db.volume_glance_metadata_create(self.ctxt, self.volume_id,
                                             'disk_format', 'bare')
            db.volume_glance_metadata_create(self.ctxt, self.volume_id,
                                             'container_type', 'ovf')
コード例 #8
0
    def _add_metadata(self, vol_meta=False, vol_glance_meta=False):
        if vol_meta:
            # Add some VolumeMetadata
            db.volume_metadata_update(self.ctxt, self.volume_id, {'fee': 'fi'},
                                      False)
            db.volume_metadata_update(self.ctxt, self.volume_id, {'fo': 'fum'},
                                      False)

        if vol_glance_meta:
            # Add some GlanceMetadata
            db.volume_glance_metadata_create(self.ctxt, self.volume_id,
                                             'disk_format', 'bare')
            db.volume_glance_metadata_create(self.ctxt, self.volume_id,
                                             'container_type', 'ovf')
コード例 #9
0
    def save(self):
        updates = self.cinder_obj_get_changes()
        if updates:
            if 'consistencygroup' in updates:
                raise exception.ObjectActionError(
                    action='save', reason=_('consistencygroup changed'))
            if 'glance_metadata' in updates:
                raise exception.ObjectActionError(
                    action='save', reason=_('glance_metadata changed'))
            if 'snapshots' in updates:
                raise exception.ObjectActionError(
                    action='save', reason=_('snapshots changed'))
            if 'metadata' in updates:
                # Metadata items that are not specified in the
                # self.metadata will be deleted
                metadata = updates.pop('metadata', None)
                self.metadata = db.volume_metadata_update(self._context,
                                                          self.id, metadata,
                                                          True)
            if self._context.is_admin and 'admin_metadata' in updates:
                metadata = updates.pop('admin_metadata', None)
                self.admin_metadata = db.volume_admin_metadata_update(
                    self._context, self.id, metadata, True)

            db.volume_update(self._context, self.id, updates)
            self.obj_reset_changes()
コード例 #10
0
ファイル: test_db_api.py プロジェクト: AsherBond/cinder
    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_meta = db.volume_metadata_update(self.ctxt, 1, metadata2, True)

        self.assertEqual(should_be, db_meta)
コード例 #11
0
    def save(self):
        # TODO: (Y release) Remove this online migration code
        # Pass self directly since it's a CinderObjectDictCompat
        self._ensure_use_quota_is_set(self)

        updates = self.cinder_obj_get_changes()
        if updates:
            # NOTE(xyang): Allow this to pass if 'consistencygroup' is
            # set to None. This is to support backward compatibility.
            # Also remove 'consistencygroup' from updates because
            # consistencygroup is the name of a relationship in the ORM
            # Volume model, so SQLA tries to do some kind of update of
            # the foreign key based on the provided updates if
            # 'consistencygroup' is in updates.
            if updates.pop('consistencygroup', None):
                raise exception.ObjectActionError(
                    action='save', reason=_('consistencygroup changed'))
            if 'group' in updates:
                raise exception.ObjectActionError(action='save',
                                                  reason=_('group changed'))
            if 'glance_metadata' in updates:
                raise exception.ObjectActionError(
                    action='save', reason=_('glance_metadata changed'))
            if 'snapshots' in updates:
                raise exception.ObjectActionError(
                    action='save', reason=_('snapshots changed'))
            if 'cluster' in updates:
                raise exception.ObjectActionError(action='save',
                                                  reason=_('cluster changed'))
            if 'metadata' in updates:
                # Metadata items that are not specified in the
                # self.metadata will be deleted
                metadata = updates.pop('metadata', None)
                self.metadata = db.volume_metadata_update(
                    self._context, self.id, metadata, True)
            if self._context.is_admin and 'admin_metadata' in updates:
                metadata = updates.pop('admin_metadata', None)
                self.admin_metadata = db.volume_admin_metadata_update(
                    self._context, self.id, metadata, True)

            # When we are creating a volume and we change from 'creating'
            # status to 'downloading' status we have to change the worker entry
            # in the DB to reflect this change, otherwise the cleanup will
            # not be performed as it will be mistaken for a volume that has
            # been somehow changed (reset status, forced operation...)
            if updates.get('status') == 'downloading':
                self.set_worker()

            # updates are changed after popping out metadata.
            if updates:
                db.volume_update(self._context, self.id, updates)
            self.obj_reset_changes()
コード例 #12
0
ファイル: volume.py プロジェクト: mahak/cinder
    def save(self):
        updates = self.cinder_obj_get_changes()
        if updates:
            # NOTE(xyang): Allow this to pass if 'consistencygroup' is
            # set to None. This is to support backward compatibility.
            # Also remove 'consistencygroup' from updates because
            # consistencygroup is the name of a relationship in the ORM
            # Volume model, so SQLA tries to do some kind of update of
            # the foreign key based on the provided updates if
            # 'consistencygroup' is in updates.
            if updates.pop('consistencygroup', None):
                raise exception.ObjectActionError(
                    action='save', reason=_('consistencygroup changed'))
            if 'group' in updates:
                raise exception.ObjectActionError(
                    action='save', reason=_('group changed'))
            if 'glance_metadata' in updates:
                raise exception.ObjectActionError(
                    action='save', reason=_('glance_metadata changed'))
            if 'snapshots' in updates:
                raise exception.ObjectActionError(
                    action='save', reason=_('snapshots changed'))
            if 'cluster' in updates:
                raise exception.ObjectActionError(
                    action='save', reason=_('cluster changed'))
            if 'metadata' in updates:
                # Metadata items that are not specified in the
                # self.metadata will be deleted
                metadata = updates.pop('metadata', None)
                self.metadata = db.volume_metadata_update(self._context,
                                                          self.id, metadata,
                                                          True)
            if self._context.is_admin and 'admin_metadata' in updates:
                metadata = updates.pop('admin_metadata', None)
                self.admin_metadata = db.volume_admin_metadata_update(
                    self._context, self.id, metadata, True)

            # When we are creating a volume and we change from 'creating'
            # status to 'downloading' status we have to change the worker entry
            # in the DB to reflect this change, otherwise the cleanup will
            # not be performed as it will be mistaken for a volume that has
            # been somehow changed (reset status, forced operation...)
            if updates.get('status') == 'downloading':
                self.set_worker()

            # updates are changed after popping out metadata.
            if updates:
                db.volume_update(self._context, self.id, updates)
            self.obj_reset_changes()
コード例 #13
0
    def save(self):
        updates = self.cinder_obj_get_changes()
        if updates:
            if 'metadata' in updates:
                # Metadata items that are not specified in the
                # self.metadata will be deleted
                metadata = updates.pop('metadata', None)
                self.metadata = db.volume_metadata_update(
                    self._context, self.id, metadata, True)
            if self._context.is_admin and 'admin_metadata' in updates:
                metadata = updates.pop('admin_metadata', None)
                self.admin_metadata = db.volume_admin_metadata_update(
                    self._context, self.id, metadata, True)

            db.volume_update(self._context, self.id, updates)
            self.obj_reset_changes()
コード例 #14
0
ファイル: volume.py プロジェクト: nikesh-mahalka/cinder
    def save(self):
        updates = self.cinder_obj_get_changes()
        if updates:
            if 'metadata' in updates:
                # Metadata items that are not specified in the
                # self.metadata will be deleted
                metadata = updates.pop('metadata', None)
                self.metadata = db.volume_metadata_update(self._context,
                                                          self.id, metadata,
                                                          True)
            if self._context.is_admin and 'admin_metadata' in updates:
                metadata = updates.pop('admin_metadata', None)
                self.admin_metadata = db.volume_admin_metadata_update(
                    self._context, self.id, metadata, True)

            db.volume_update(self._context, self.id, updates)
            self.obj_reset_changes()
コード例 #15
0
ファイル: volume.py プロジェクト: chaynika/cinder
    def save(self):
        updates = self.cinder_obj_get_changes()
        if updates:
            if 'consistencygroup' in updates:
                # NOTE(xyang): Allow this to pass if 'consistencygroup' is
                # set to None. This is to support backward compatibility.
                if updates.get('consistencygroup'):
                    raise exception.ObjectActionError(
                        action='save', reason=_('consistencygroup changed'))
            if 'group' in updates:
                raise exception.ObjectActionError(
                    action='save', reason=_('group changed'))
            if 'glance_metadata' in updates:
                raise exception.ObjectActionError(
                    action='save', reason=_('glance_metadata changed'))
            if 'snapshots' in updates:
                raise exception.ObjectActionError(
                    action='save', reason=_('snapshots changed'))
            if 'cluster' in updates:
                raise exception.ObjectActionError(
                    action='save', reason=_('cluster changed'))
            if 'metadata' in updates:
                # Metadata items that are not specified in the
                # self.metadata will be deleted
                metadata = updates.pop('metadata', None)
                self.metadata = db.volume_metadata_update(self._context,
                                                          self.id, metadata,
                                                          True)
            if self._context.is_admin and 'admin_metadata' in updates:
                metadata = updates.pop('admin_metadata', None)
                self.admin_metadata = db.volume_admin_metadata_update(
                    self._context, self.id, metadata, True)

            # When we are creating a volume and we change from 'creating'
            # status to 'downloading' status we have to change the worker entry
            # in the DB to reflect this change, otherwise the cleanup will
            # not be performed as it will be mistaken for a volume that has
            # been somehow changed (reset status, forced operation...)
            if updates.get('status') == 'downloading':
                self.set_worker()

            # updates are changed after popping out metadata.
            if updates:
                db.volume_update(self._context, self.id, updates)
            self.obj_reset_changes()
コード例 #16
0
    def save(self):
        updates = self.cinder_obj_get_changes()
        if updates:
            if 'consistencygroup' in updates:
                raise exception.ObjectActionError(
                    action='save', reason=_('consistencygroup changed'))
            if 'group' in updates:
                raise exception.ObjectActionError(
                    action='save', reason=_('group changed'))
            if 'glance_metadata' in updates:
                raise exception.ObjectActionError(
                    action='save', reason=_('glance_metadata changed'))
            if 'snapshots' in updates:
                raise exception.ObjectActionError(
                    action='save', reason=_('snapshots changed'))
            if 'cluster' in updates:
                raise exception.ObjectActionError(
                    action='save', reason=_('cluster changed'))
            if 'metadata' in updates:
                # Metadata items that are not specified in the
                # self.metadata will be deleted
                metadata = updates.pop('metadata', None)
                self.metadata = db.volume_metadata_update(self._context,
                                                          self.id, metadata,
                                                          True)
            if self._context.is_admin and 'admin_metadata' in updates:
                metadata = updates.pop('admin_metadata', None)
                self.admin_metadata = db.volume_admin_metadata_update(
                    self._context, self.id, metadata, True)

            # When we are creating a volume and we change from 'creating'
            # status to 'downloading' status we have to change the worker entry
            # in the DB to reflect this change, otherwise the cleanup will
            # not be performed as it will be mistaken for a volume that has
            # been somehow changed (reset status, forced operation...)
            if updates.get('status') == 'downloading':
                self.set_worker()

            # updates are changed after popping out metadata.
            if updates:
                db.volume_update(self._context, self.id, updates)
            self.obj_reset_changes()
コード例 #17
0
ファイル: volume.py プロジェクト: btreiber/cinder
    def save(self):
        updates = self.cinder_obj_get_changes()
        if updates:
            if "consistencygroup" in updates:
                raise exception.ObjectActionError(action="save", reason=_("consistencygroup changed"))
            if "glance_metadata" in updates:
                raise exception.ObjectActionError(action="save", reason=_("glance_metadata changed"))
            if "snapshots" in updates:
                raise exception.ObjectActionError(action="save", reason=_("snapshots changed"))
            if "metadata" in updates:
                # Metadata items that are not specified in the
                # self.metadata will be deleted
                metadata = updates.pop("metadata", None)
                self.metadata = db.volume_metadata_update(self._context, self.id, metadata, True)
            if self._context.is_admin and "admin_metadata" in updates:
                metadata = updates.pop("admin_metadata", None)
                self.admin_metadata = db.volume_admin_metadata_update(self._context, self.id, metadata, True)

            db.volume_update(self._context, self.id, updates)
            self.obj_reset_changes()
コード例 #18
0
class LunrRPC(object):
    def __init__(self):
        pass

    def create_consumer(self, *args, **kwargs):
        pass

    def consume_in_thread(self, *args, **kwargs):
        pass

    def _get_volume_type_id(self, volume_type_name):
        try:
            return volume_types.get_volume_type_by_name(
                get_admin_context(), volume_type_name)['id']
        except exception.VolumeTypeNotFoundByName:
            LOG.exception("Unknown volume type '%s';"
                          " not valid volume type?" % volume_type_name)
            raise

    def create_volume(self,
                      context,
                      volume_id,
                      snapshot_id=None,
                      image_id=None,
                      source_volid=None,
                      **kwargs):
        context = context.elevated()
        volume = db.volume_get(context, volume_id)
        LOG.info(_("volume %s: creating"), volume['name'])
        model_update = {'host': 'lunr'}
        volume['host'] = 'lunr'
        try:
            # Try to get the volume type name, else use the default volume type
            volume_type_name = volume['volume_type']['name']
        except (KeyError, TypeError):
            volume_type_name = CONF.lunr_default_volume_type
            # Using the default volume type name,
            # ask the db for the volume type id
            vtype_id = self._get_volume_type_id(volume_type_name)
            model_update['volume_type_id'] = vtype_id
            volume['volume_type_id'] = vtype_id

        db.volume_update(context, volume['id'], model_update)

        params = {
            'name': volume['id'],
            'size': volume['size'],
            'volume_type_name': volume_type_name,
        }

        # Copy image to volume!
        if image_id:
            params['image_id'] = image_id
            image_service, image_id = glance.get_remote_image_service(
                context, image_id)
            image_meta = image_service.show(context, image_id)
            if image_meta:
                db.volume_glance_metadata_create(context, volume['id'],
                                                 'image_id', image_id)
                name = image_meta.get('name', None)
                if name:
                    db.volume_glance_metadata_create(context, volume['id'],
                                                     'image_name', name)
                image_properties = image_meta.get('properties', {})
                for key, value in image_properties.items():
                    db.volume_glance_metadata_create(context, volume['id'],
                                                     key, value)

        # If this is a snapshot request, add the backup param
        if snapshot_id:
            params['backup'] = snapshot_id
            snapshot_ref = db.snapshot_get(context, snapshot_id)
            original_vref = db.volume_get(context, snapshot_ref['volume_id'])
            if original_vref['bootable']:
                db.volume_glance_metadata_copy_to_volume(
                    context, volume_id, snapshot_id)
                db.volume_update(context, volume_id, {'bootable': True})

        # If this is a clone request, add the source_volume_id param
        if source_volid:
            params['source_volume'] = source_volid
            source_vref = db.volume_get(context, source_volid)
            if source_vref['bootable']:
                db.volume_glance_metadata_copy_from_volume_to_volume(
                    context, source_volid, volume_id)
                db.volume_update(context, volume_id, {'bootable': True})

        try:
            resp = LunrClient(volume, logger=LOG).volumes.create(
                volume['id'], **params)
        except LunrError, e:
            LOG.debug('error creating volume %s', volume['id'])
            # Don't leave an error'd volume around, the raise here
            # will notify the caller of the error (See Github Issue #343)
            # Also, in Havana, TaskFlow will revert the quota increase.
            db.volume_destroy(context, volume['id'])
            raise e

        model_update = {}
        if image_id:
            model_update['bootable'] = True
        if resp.body['size'] != volume['size']:
            model_update['size'] = resp.body['size']
        if resp.body['status'] == 'ACTIVE':
            model_update['status'] = 'available'
        model_update['launched_at'] = timeutils.utcnow()

        db.volume_update(context, volume['id'], model_update)

        # Add storage-node to the volume metadata
        db.volume_metadata_update(context, volume['id'],
                                  {'storage-node': resp.body['node_id']},
                                  False)

        LOG.debug(_("volume %s: created successfully"), volume['name'])
        return volume