def save(self): updates = self.cinder_obj_get_changes() if updates: if 'volume' in updates: raise exception.ObjectActionError(action='save', reason=_('volume changed')) if 'cgsnapshot' in updates: raise exception.ObjectActionError( action='save', reason=_('cgsnapshot 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.snapshot_metadata_update(self._context, self.id, metadata, True) db.snapshot_update(self._context, self.id, updates) self.obj_reset_changes()
def save(self): updates = self.cinder_obj_get_changes() if updates: if 'volume' in updates: raise exception.ObjectActionError(action='save', reason=_('volume changed')) if 'cgsnapshot' in updates: # NOTE(xyang): Allow this to pass if 'cgsnapshot' is # set to None. This is to support backward compatibility. if updates.get('cgsnapshot'): raise exception.ObjectActionError( action='save', reason=_('cgsnapshot changed')) if 'group_snapshot' in updates: raise exception.ObjectActionError( action='save', reason=_('group_snapshot 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.snapshot_metadata_update( self._context, self.id, metadata, True) db.snapshot_update(self._context, self.id, updates) self.obj_reset_changes()
def save(self): updates = self.cinder_obj_get_changes() if updates: if 'volume' in updates: raise exception.ObjectActionError(action='save', reason=_('volume changed')) if 'cgsnapshot' in updates: # NOTE(xyang): Allow this to pass if 'cgsnapshot' is # set to None. This is to support backward compatibility. if updates.get('cgsnapshot'): raise exception.ObjectActionError( action='save', reason=_('cgsnapshot changed')) if 'group_snapshot' in updates: raise exception.ObjectActionError( action='save', reason=_('group_snapshot 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.snapshot_metadata_update(self._context, self.id, metadata, True) db.snapshot_update(self._context, self.id, updates) self.obj_reset_changes()
def save(self): updates = self.cinder_obj_get_changes() if updates: if 'volume' in updates: raise exception.ObjectActionError(action='save', reason=_('volume changed')) if 'cgsnapshot' in updates: raise exception.ObjectActionError( action='save', reason=_('cgsnapshot changed')) if 'group_snapshot' in updates: raise exception.ObjectActionError( action='save', reason=_('group_snapshot 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.snapshot_metadata_update(self._context, self.id, metadata, True) db.snapshot_update(self._context, self.id, updates) self.obj_reset_changes()
def _update_snapshot_status(self, req, id, body): """Update database fields related to status of a snapshot. Intended for creation of snapshots, so snapshot state must start as 'creating' and be changed to 'available', 'creating', or 'error'. """ context = req.environ['cinder.context'] authorize(context, 'update_snapshot_status') LOG.debug("body: %s" % body) try: status = body['os-update_snapshot_status']['status'] except KeyError: msg = _("'status' must be specified.") raise webob.exc.HTTPBadRequest(explanation=msg) # Allowed state transitions status_map = {'creating': ['creating', 'available', 'error'], 'deleting': ['deleting', 'error_deleting']} current_snapshot = db.snapshot_get(context, id) if current_snapshot['status'] not in status_map: msg = _("Snapshot status %(cur)s not allowed for " "update_snapshot_status") % { 'cur': current_snapshot['status']} raise webob.exc.HTTPBadRequest(explanation=msg) if status not in status_map[current_snapshot['status']]: msg = _("Provided snapshot status %(provided)s not allowed for " "snapshot with status %(current)s.") % \ {'provided': status, 'current': current_snapshot['status']} raise webob.exc.HTTPBadRequest(explanation=msg) update_dict = {'id': id, 'status': status} progress = body['os-update_snapshot_status'].get('progress', None) if progress: # This is expected to be a string like '73%' msg = _('progress must be an integer percentage') try: integer = int(progress[:-1]) except ValueError: raise webob.exc.HTTPBadRequest(explanation=msg) if integer < 0 or integer > 100 or progress[-1] != '%': raise webob.exc.HTTPBadRequest(explanation=msg) update_dict.update({'progress': progress}) LOG.info("Updating snapshot %(id)s with info %(dict)s" % {'id': id, 'dict': update_dict}) db.snapshot_update(context, id, update_dict) return webob.Response(status_int=202)
def _update_progress(self, req, id, body): """Update snapshot progress.""" context = req.environ['cinder.context'] authorize(context) progress = body['os-update_progress'] msg = _("Updating snapshot '%(id)s' with '%(progress)r'") LOG.debug(msg, {'id': id, 'progress': progress}) try: db.snapshot_update(context, id, {'progress': progress}) except exception.NotFound, e: raise exc.HTTPNotFound(e)
def _update_snapshot_status(self, req, id, body): """Update database fields related to status of a snapshot. Intended for creation of snapshots, so snapshot state must start as 'creating' and be changed to 'available', 'creating', or 'error'. """ context = req.environ['cinder.context'] authorize(context, 'update_snapshot_status') LOG.debug("body: %s" % body) status = body['os-update_snapshot_status']['status'] # Allowed state transitions status_map = {'creating': ['creating', 'available', 'error'], 'deleting': ['deleting', 'error_deleting']} current_snapshot = db.snapshot_get(context, id) if current_snapshot['status'] not in status_map: msg = _("Snapshot status %(cur)s not allowed for " "update_snapshot_status") % { 'cur': current_snapshot['status']} raise webob.exc.HTTPBadRequest(explanation=msg) if status not in status_map[current_snapshot['status']]: msg = _("Provided snapshot status %(provided)s not allowed for " "snapshot with status %(current)s.") % \ {'provided': status, 'current': current_snapshot['status']} raise webob.exc.HTTPBadRequest(explanation=msg) update_dict = {'id': id, 'status': status} progress = body['os-update_snapshot_status'].get('progress', None) if progress: # This is expected to be a string like '73%' msg = _('progress must be an integer percentage') try: integer = int(progress[:-1]) except ValueError: raise webob.exc.HTTPBadRequest(explanation=msg) if integer < 0 or integer > 100 or progress[-1] != '%': raise webob.exc.HTTPBadRequest(explanation=msg) update_dict.update({'progress': progress}) LOG.info("Updating snapshot %(id)s with info %(dict)s" % {'id': id, 'dict': update_dict}) db.snapshot_update(context, id, update_dict) return webob.Response(status_int=202)
def _update_snapshot_status(self, req, id, body): """Update database fields related to status of a snapshot. Intended for creation of snapshots, so snapshot state must start as 'creating' and be changed to 'available', 'creating', or 'error'. """ context = req.environ["cinder.context"] authorize(context, "update_snapshot_status") LOG.debug("body: %s" % body) status = body["os-update_snapshot_status"]["status"] # Allowed state transitions status_map = {"creating": ["creating", "available", "error"], "deleting": ["deleting", "error_deleting"]} current_snapshot = db.snapshot_get(context, id) if current_snapshot["status"] not in status_map: msg = _("Snapshot status %(cur)s not allowed for " "update_snapshot_status") % { "cur": current_snapshot["status"] } raise webob.exc.HTTPBadRequest(explanation=msg) if status not in status_map[current_snapshot["status"]]: msg = _("Provided snapshot status %(provided)s not allowed for " "snapshot with status %(current)s.") % { "provided": status, "current": current_snapshot["status"], } raise webob.exc.HTTPBadRequest(explanation=msg) update_dict = {"id": id, "status": status} progress = body["os-update_snapshot_status"].get("progress", None) if progress: # This is expected to be a string like '73%' msg = _("progress must be an integer percentage") try: integer = int(progress[:-1]) except ValueError: raise webob.exc.HTTPBadRequest(explanation=msg) if integer < 0 or integer > 100 or progress[-1] != "%": raise webob.exc.HTTPBadRequest(explanation=msg) update_dict.update({"progress": progress}) LOG.info("Updating snapshot %(id)s with info %(dict)s" % {"id": id, "dict": update_dict}) db.snapshot_update(context, id, update_dict) return webob.Response(status_int=202)
def save(self): updates = self.obj_get_changes() if updates: if "volume" in updates: raise exception.ObjectActionError(action="save", reason=_("volume 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.snapshot_metadata_update(self._context, self.id, metadata, True) db.snapshot_update(self._context, self.id, updates) self.obj_reset_changes()
def delete_snapshot(self, context, snapshot_id): snapshot = db.snapshot_get(context, snapshot_id) context = context.elevated() LOG.debug(_("snapshot %s: deleting"), snapshot['name']) reserve_opts = {'snapshots': -1} volume = db.volume_get(context, snapshot['volume_id']) try: QUOTAS.add_volume_type_opts(context, reserve_opts, volume.get('volume_type_id')) reservations = QUOTAS.reserve(context, **reserve_opts) except Exception: reservations = None LOG.exception(_("Failed to update usages deleting snapshot")) client = LunrClient(snapshot, logger=LOG) try: client.backups.delete(snapshot['id']) except LunrError, e: # ignore Not Found on delete_snapshot. Don't wait on status. if e.code == 404: db.snapshot_destroy(context, snapshot['id']) LOG.debug(_("snapshot %s: deleted successfully"), snapshot['name']) elif e.code == 409: db.snapshot_update(context, snapshot['id'], {'status': 'available'}) LOG.debug(_("snapshot %s: snapshot is busy"), snapshot['name']) if reservations: QUOTAS.rollback(context, reservations) raise else: LOG.debug(_('error deleting snapshot %s'), snapshot['id']) db.snapshot_update(context, snapshot['id'], {'status': 'error_deleting'}) if reservations: QUOTAS.rollback(context, reservations) raise
def _update(self, *args, **kwargs): db.snapshot_update(*args, **kwargs)