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])
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])
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])
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])
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])
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])
def get_all(self, vol_id): """ Retrives the user metadata of the volume. :param vol_id: OpenStack Volume ID. """ admin_context = context.get_admin_context() metadata = db.volume_admin_metadata_get(admin_context, vol_id) return metadata
def get(self, vol_id, entry): """ Finds the corresponding SoftLayer SnapshotID of given OpenStack Snapshot. :param vol_id: OpenStack Volume ID. """ admin_context = context.get_admin_context() metadata = db.volume_admin_metadata_get(admin_context, vol_id) return metadata.get(entry, None)
def delete_entry(self, volume, entry): """ Remove snapshot's ID from the volume's admin metadata :param volume: OpenStack Volume Object. :param entry: OpenStack Volume ID. """ admin_context = context.get_admin_context() metadata = db.volume_admin_metadata_get(admin_context, volume['id']) if entry in metadata: del metadata[entry] db.volume_admin_metadata_update( admin_context, volume['id'], metadata, delete=True)
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])
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])