def _delete(self, req, id): """Deletes an existing volume type.""" context = req.environ['manila.context'] authorize(context) try: vol_type = volume_types.get_volume_type(context, id) volume_types.destroy(context, vol_type['id']) notifier_info = dict(volume_types=vol_type) notifier_api.notify(context, 'volumeType', 'volume_type.delete', notifier_api.INFO, notifier_info) except exception.VolumeTypeInUse as err: notifier_err = dict(id=id, error_message=str(err)) self._notify_volume_type_error(context, 'volume_type.delete', notifier_err) msg = 'Target volume type is still in use.' raise webob.exc.HTTPBadRequest(explanation=msg) except exception.NotFound as err: notifier_err = dict(id=id, error_message=str(err)) self._notify_volume_type_error(context, 'volume_type.delete', notifier_err) raise webob.exc.HTTPNotFound() return webob.Response(status_int=202)
def delete(self, req, type_id, id): """Deletes an existing extra spec.""" context = req.environ['manila.context'] self._check_type(context, type_id) authorize(context) try: db.volume_type_extra_specs_delete(context, type_id, id) except exception.VolumeTypeExtraSpecsNotFound as error: raise webob.exc.HTTPNotFound(explanation=error.msg) notifier_info = dict(type_id=type_id, id=id) notifier_api.notify(context, 'volumeTypeExtraSpecs', 'volume_type_extra_specs.delete', notifier_api.INFO, notifier_info) return webob.Response(status_int=202)
def create(self, req, type_id, body=None): context = req.environ['manila.context'] authorize(context) if not self.is_valid_body(body, 'extra_specs'): raise webob.exc.HTTPBadRequest() self._check_type(context, type_id) self._verify_extra_specs(body) specs = body['extra_specs'] self._check_key_names(specs.keys()) db.volume_type_extra_specs_update_or_create(context, type_id, specs) notifier_info = dict(type_id=type_id, specs=specs) notifier_api.notify(context, 'volumeTypeExtraSpecs', 'volume_type_extra_specs.create', notifier_api.INFO, notifier_info) return body
def _set_share_error_state_and_notify(self, method, context, ex, request_spec): LOG.warning(_("Failed to schedule_%(method)s: %(ex)s") % locals()) share_state = {'status': 'error'} properties = request_spec.get('share_properties', {}) share_id = request_spec.get('share_id', None) if share_id: db.share_update(context, share_id, share_state) payload = dict(request_spec=request_spec, share_properties=properties, share_id=share_id, state=share_state, method=method, reason=ex) notifier.notify(context, notifier.publisher_id("scheduler"), 'scheduler.' + method, notifier.ERROR, payload)
def update(self, req, type_id, id, body=None): context = req.environ['manila.context'] authorize(context) if not body: expl = _('Request body empty') raise webob.exc.HTTPBadRequest(explanation=expl) self._check_type(context, type_id) if id not in body: expl = _('Request body and URI mismatch') raise webob.exc.HTTPBadRequest(explanation=expl) if len(body) > 1: expl = _('Request body contains too many items') raise webob.exc.HTTPBadRequest(explanation=expl) self._verify_extra_specs(body) db.volume_type_extra_specs_update_or_create(context, type_id, body) notifier_info = dict(type_id=type_id, id=id) notifier_api.notify(context, 'volumeTypeExtraSpecs', 'volume_type_extra_specs.update', notifier_api.INFO, notifier_info) return body
def _create(self, req, body): """Creates a new volume type.""" context = req.environ['manila.context'] authorize(context) if not self.is_valid_body(body, 'volume_type'): raise webob.exc.HTTPBadRequest() vol_type = body['volume_type'] name = vol_type.get('name', None) specs = vol_type.get('extra_specs', {}) if name is None or name == "" or len(name) > 255: raise webob.exc.HTTPBadRequest() try: volume_types.create(context, name, specs) vol_type = volume_types.get_volume_type_by_name(context, name) notifier_info = dict(volume_types=vol_type) notifier_api.notify(context, 'volumeType', 'volume_type.create', notifier_api.INFO, notifier_info) except exception.VolumeTypeExists as err: notifier_err = dict(volume_types=vol_type, error_message=str(err)) self._notify_volume_type_error(context, 'volume_type.create', notifier_err) raise webob.exc.HTTPConflict(explanation=str(err)) except exception.NotFound as err: notifier_err = dict(volume_types=vol_type, error_message=str(err)) self._notify_volume_type_error(context, 'volume_type.create', notifier_err) raise webob.exc.HTTPNotFound() return self._view_builder.show(req, vol_type)
def _notify(self, ctxt, event_type, payload, priority): notifier_api.notify(ctxt, self.publisher_id, event_type, priority, payload)
def _notify_volume_type_error(self, context, method, payload): notifier_api.notify(context, 'volumeType', method, notifier_api.ERROR, payload)