def save(self, context=None): """Save updates to this VolumeMapping. Updates will be made column by column based on the result of self.what_changed(). :param context: Security context. NOTE: This should only be used internally by the indirection_api. Unfortunately, RPC requires context as the first argument, even though we don't use it. A context should be set when instantiating the object. """ updates = self.obj_get_changes() if 'container' in updates: raise exception.ObjectActionError(action='save', reason='container changed') if 'volume' in updates: raise exception.ObjectActionError(action='save', reason='volume changed') updates.pop('id', None) self._update_volume(context, updates) dbapi.update_volume_mapping(context, self.uuid, updates) self.obj_reset_changes()
def create(self, context): """Create a VolumeMapping record in the DB. :param context: Security context. NOTE: This should only be used internally by the indirection_api. Unfortunately, RPC requires context as the first argument, even though we don't use it. A context should be set when instantiating the object. """ if self.obj_attr_is_set('id'): raise exception.ObjectActionError(action='create', reason='already created') values = self.obj_get_changes() if 'container' in values: raise exception.ObjectActionError(action='create', reason='container assigned') if 'volume' in values: raise exception.ObjectActionError(action='create', reason='volume assigned') self._create_volume(context, values) db_volume = dbapi.create_volume_mapping(context, values) self._from_db_object(self, db_volume)
def obj_load_attr(self, attrname): if attrname not in CONTAINER_OPTIONAL_ATTRS: 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()) LOG.debug("Lazy-loading '%(attr)s' on %(name)s uuid %(uuid)s", { 'attr': attrname, 'name': self.obj_name(), 'uuid': self.uuid, }) # NOTE(danms): We handle some fields differently here so that we # can be more efficient if attrname == 'pci_devices': self._load_pci_devices() if attrname == 'exec_instances': self._load_exec_instances() if attrname == 'registry': self._load_registry() self.obj_reset_changes([attrname])
def obj_load_attr(self, attrname): if attrname not in VOLUME_MAPPING_OPTIONAL_ATTRS: 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()) LOG.debug("Lazy-loading '%(attr)s' on %(name)s", { 'attr': attrname, 'name': self.obj_name(), }) if attrname in VOLUME_ATTRS: value = getattr(self.volume, attrname) setattr(self, attrname, value) self.obj_reset_changes(fields=[attrname]) if attrname == 'container': self.container = container.ContainerBase.get_container_any_type( self._context, self.container_uuid) self.obj_reset_changes(fields=['container']) if attrname == 'volume': self.volume = volume_obj.Volume.get_by_id(self._context, self.volume_id) self.obj_reset_changes(fields=['volume'])
def destroy(self, context=None): """Delete the VolumeMapping from the DB. :param context: Security context. NOTE: This should only be used internally by the indirection_api. Unfortunately, RPC requires context as the first argument, even though we don't use it. A context should be set when instantiating the object. """ if not self.obj_attr_is_set('id'): raise exception.ObjectActionError(action='destroy', reason='already destroyed') dbapi.destroy_volume_mapping(context, self.uuid) delattr(self, 'id') self.obj_reset_changes()
def obj_load_attr(self, attrname): if attrname not in VOLUME_MAPPING_OPTIONAL_ATTRS: 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()) LOG.debug("Lazy-loading '%(attr)s' on %(name)s uuid %(uuid)s", { 'attr': attrname, 'name': self.obj_name(), 'uuid': self.uuid, }) self.container = container.Container.get_by_uuid( self._context, self.container_uuid) self.obj_reset_changes(fields=['container'])
def create(self, context): """Create a Container record in the DB. :param context: Security context. NOTE: This should only be used internally by the indirection_api. Unfortunately, RPC requires context as the first argument, even though we don't use it. A context should be set when instantiating the object, e.g.: Capsule(context) """ values = self.obj_get_changes() if 'containers' in values: raise exception.ObjectActionError(action='create', reason='containers assigned') db_capsule = dbapi.create_capsule(context, values) self._from_db_object(self, db_capsule)