def _clean_volume_attachment(context, id): attachments = ( db.volume_attachment_get_all_by_volume_id(context, id)) for attachment in attachments: db.volume_detached(context, id, attachment.id) db.volume_admin_metadata_delete(context, id, 'attached_mode')
def _clean_volume_attachment(context, id): attachments = ( db.volume_attachment_get_all_by_volume_id(context, id)) for attachment in attachments: db.volume_detached(context.elevated(), id, attachment.id) db.volume_admin_metadata_delete(context.elevated(), id, 'attached_mode')
def get_all_by_volume_id(cls, context, volume_id): attachments = db.volume_attachment_get_all_by_volume_id(context, volume_id) return base.obj_make_list(context, cls(context), objects.VolumeAttachment, attachments)
def _reset_status(self, req, id, body): """Reset status on the volume.""" def _clean_volume_attachment(context, id): attachments = (db.volume_attachment_get_all_by_volume_id( context, id)) for attachment in attachments: db.volume_detached(context.elevated(), id, attachment.id) db.volume_admin_metadata_delete(context.elevated(), id, 'attached_mode') # any exceptions raised will be handled at the wsgi level update = self.validate_update(req, body=body) context = req.environ['cinder.context'] volume = objects.Volume.get_by_id(context, id) self.authorize(context, 'reset_status', target_obj=volume) # at this point, we still don't know if we're going to # reset the volume's state. Need to check what the caller # is requesting first. if update.get('status') in ('deleting', 'error_deleting' 'detaching'): msg = _("Cannot reset-state to %s" % update.get('status')) raise webob.exc.HTTPBadRequest(explanation=msg) if update.get('status') == 'in-use': attachments = (db.volume_attachment_get_all_by_volume_id( context, id)) if not attachments: msg = _("Cannot reset-state to in-use " "because volume does not have any attachments.") raise webob.exc.HTTPBadRequest(explanation=msg) msg = "Updating %(resource)s '%(id)s' with '%(update)r'" LOG.debug(msg, { 'resource': self.resource_name, 'id': id, 'update': update }) self._notify_reset_status(context, id, 'reset_status.start') self._update(context, id, update) self._remove_worker(context, id) if update.get('attach_status') == 'detached': _clean_volume_attachment(context, id) self._notify_reset_status(context, id, 'reset_status.end')
def _usage_from_volume(context, volume_ref, **kw): now = timeutils.utcnow() launched_at = volume_ref['launched_at'] or now created_at = volume_ref['created_at'] or now volume_status = volume_ref['status'] if volume_status == 'error_managing_deleting': volume_status = 'deleting' usage_info = dict( tenant_id=volume_ref['project_id'], host=volume_ref['host'], user_id=volume_ref['user_id'], availability_zone=volume_ref['availability_zone'], volume_id=volume_ref['id'], volume_type=volume_ref['volume_type_id'], display_name=volume_ref['display_name'], launched_at=launched_at.isoformat(), created_at=created_at.isoformat(), status=volume_status, snapshot_id=volume_ref['snapshot_id'], size=volume_ref['size'], replication_status=volume_ref['replication_status'], replication_extended_status=volume_ref['replication_extended_status'], replication_driver_data=volume_ref['replication_driver_data'], metadata=volume_ref.get('volume_metadata'), ) usage_info.update(kw) try: attachments = db.volume_attachment_get_all_by_volume_id( context, volume_ref['id']) usage_info['volume_attachment'] = attachments glance_meta = db.volume_glance_metadata_get(context, volume_ref['id']) if glance_meta: usage_info['glance_metadata'] = glance_meta except exception.GlanceMetadataNotFound: pass except exception.VolumeNotFound: LOG.debug("Can not find volume %s at notify usage", volume_ref['id']) return usage_info
def _usage_from_volume(context, volume_ref, **kw): now = timeutils.utcnow() launched_at = volume_ref['launched_at'] or now created_at = volume_ref['created_at'] or now volume_status = volume_ref['status'] if volume_status == 'error_managing_deleting': volume_status = 'deleting' usage_info = dict( tenant_id=volume_ref['project_id'], host=volume_ref['host'], user_id=volume_ref['user_id'], availability_zone=volume_ref['availability_zone'], volume_id=volume_ref['id'], volume_type=volume_ref['volume_type_id'], display_name=volume_ref['display_name'], launched_at=launched_at.isoformat(), created_at=created_at.isoformat(), status=volume_status, snapshot_id=volume_ref['snapshot_id'], size=volume_ref['size'], replication_status=volume_ref['replication_status'], replication_extended_status=volume_ref['replication_extended_status'], replication_driver_data=volume_ref['replication_driver_data'], metadata=volume_ref.get('volume_metadata'),) usage_info.update(kw) try: attachments = db.volume_attachment_get_all_by_volume_id( context, volume_ref['id']) usage_info['volume_attachment'] = attachments glance_meta = db.volume_glance_metadata_get(context, volume_ref['id']) if glance_meta: usage_info['glance_metadata'] = glance_meta except exception.GlanceMetadataNotFound: pass except exception.VolumeNotFound: LOG.debug("Can not find volume %s at notify usage", volume_ref['id']) return usage_info
def _usage_from_volume(context, volume_ref, **kw): now = timeutils.utcnow() launched_at = volume_ref["launched_at"] or now created_at = volume_ref["created_at"] or now usage_info = dict( tenant_id=volume_ref["project_id"], host=volume_ref["host"], user_id=volume_ref["user_id"], availability_zone=volume_ref["availability_zone"], volume_id=volume_ref["id"], volume_type=volume_ref["volume_type_id"], display_name=volume_ref["display_name"], launched_at=launched_at.isoformat(), created_at=created_at.isoformat(), status=volume_ref["status"], snapshot_id=volume_ref["snapshot_id"], size=volume_ref["size"], replication_status=volume_ref["replication_status"], replication_extended_status=volume_ref["replication_extended_status"], replication_driver_data=volume_ref["replication_driver_data"], metadata=volume_ref.get("volume_metadata"), ) usage_info.update(kw) try: attachments = db.volume_attachment_get_all_by_volume_id(context, volume_ref["id"]) usage_info["volume_attachment"] = attachments glance_meta = db.volume_glance_metadata_get(context, volume_ref["id"]) if glance_meta: usage_info["glance_metadata"] = glance_meta except exception.GlanceMetadataNotFound: pass except exception.VolumeNotFound: LOG.debug("Can not find volume %s at notify usage", volume_ref["id"]) return usage_info