def on_patch(self, req, res, alarm_id): helpers.validate_authorization(req, self._default_authorized_roles) tenant_id = helpers.get_tenant_id(req) alarm = helpers.read_http_resource(req) schema_alarm.validate(alarm) old_alarm = self._alarms_repo.get_alarm(tenant_id, alarm_id)[0] # if a field is not present or is None, replace it with the old value if 'state' not in alarm or not alarm['state']: alarm['state'] = old_alarm['state'] if 'lifecycle_state' not in alarm or alarm['lifecycle_state'] is None: alarm['lifecycle_state'] = old_alarm['lifecycle_state'] if 'link' not in alarm or alarm['link'] is None: alarm['link'] = old_alarm['link'] self._alarm_patch(tenant_id, alarm_id, alarm['state'], alarm['lifecycle_state'], alarm['link']) result = self._alarm_show(req.uri, tenant_id, alarm_id) res.body = helpers.dumpit_utf8(result) res.status = falcon.HTTP_200
def on_put(self, req, res, alarm_id): helpers.validate_authorization(req, ['api:alarms:put']) alarm = helpers.from_json(req) schema_alarm.validate(alarm) # Validator makes state optional, so check it here if 'state' not in alarm or not alarm['state']: raise HTTPUnprocessableEntityError('Unprocessable Entity', "Field 'state' is required") if 'lifecycle_state' not in alarm or not alarm['lifecycle_state']: raise HTTPUnprocessableEntityError( 'Unprocessable Entity', "Field 'lifecycle_state' is required") if 'link' not in alarm or not alarm['link']: raise HTTPUnprocessableEntityError('Unprocessable Entity', "Field 'link' is required") self._alarm_update(req.project_id, alarm_id, alarm['state'], alarm['lifecycle_state'], alarm['link']) result = self._alarm_show(req.uri, req.project_id, alarm_id) res.body = helpers.to_json(result) res.status = falcon.HTTP_200
def on_patch(self, req, res, alarm_id): helpers.validate_authorization(req, self._default_authorized_roles) tenant_id = helpers.get_tenant_id(req) alarm = helpers.read_http_resource(req) schema_alarm.validate(alarm) old_alarm = self._alarms_repo.get_alarm(tenant_id, alarm_id)[0] # if a field is not present or is None, replace it with the old value if 'state' not in alarm or not alarm['state']: alarm['state'] = old_alarm['state'] if 'lifecycle_state' not in alarm or alarm['lifecycle_state'] is None: alarm['lifecycle_state'] = old_alarm['lifecycle_state'] if 'link' not in alarm or alarm['link'] is None: alarm['link'] = old_alarm['link'] self._alarm_patch(tenant_id, alarm_id, alarm['state'], alarm['lifecycle_state'], alarm['link']) result = self._alarm_show(req.uri, tenant_id, alarm_id) res.body = helpers.dumpit_utf8(result) res.status = falcon.HTTP_200
def on_put(self, req, res, alarm_id): helpers.validate_authorization(req, self._default_authorized_roles) tenant_id = helpers.get_tenant_id(req) alarm = helpers.read_http_resource(req) schema_alarm.validate(alarm) # Validator makes state optional, so check it here if 'state' not in alarm or not alarm['state']: raise HTTPUnprocessableEntityError('Unprocessable Entity', "Field 'state' is required") if 'lifecycle_state' not in alarm or not alarm['lifecycle_state']: raise HTTPUnprocessableEntityError( 'Unprocessable Entity', "Field 'lifecycle_state' is required") if 'link' not in alarm or not alarm['link']: raise HTTPUnprocessableEntityError('Unprocessable Entity', "Field 'link' is required") self._alarm_update(tenant_id, alarm_id, alarm['state'], alarm['lifecycle_state'], alarm['link']) result = self._alarm_show(req.uri, tenant_id, alarm_id) res.body = helpers.dumpit_utf8(result) res.status = falcon.HTTP_200
def on_put(self, req, res, alarm_id): helpers.validate_authorization(req, self._default_authorized_roles) tenant_id = helpers.get_tenant_id(req) alarm = helpers.read_http_resource(req) schema_alarm.validate(alarm) # Validator makes state optional, so check it here if 'state' not in alarm or not alarm['state']: raise HTTPUnprocessableEntityError('Unprocessable Entity', "Field 'state' is required") if 'lifecycle_state' not in alarm or not alarm['lifecycle_state']: raise HTTPUnprocessableEntityError('Unprocessable Entity', "Field 'lifecycle_state' is required") if 'link' not in alarm or not alarm['link']: raise HTTPUnprocessableEntityError('Unprocessable Entity', "Field 'link' is required") self._alarm_update(tenant_id, alarm_id, alarm['state'], alarm['lifecycle_state'], alarm['link']) result = self._alarm_show(req.uri, tenant_id, alarm_id) res.body = helpers.dumpit_utf8(result) res.status = falcon.HTTP_200
def on_put(self, req, res, alarm_id): helpers.validate_authorization(req, self._default_authorized_roles) tenant_id = helpers.get_tenant_id(req) alarm = helpers.read_http_resource(req) schema_alarm.validate(alarm) # Validator makes state optional, so check it here if 'state' not in alarm or not alarm['state']: raise falcon.HTTPBadRequest('Bad request', "Field 'state' is required") # Assume these fields are null if not provided if 'lifecycle_state' not in alarm: alarm['lifecycle_state'] = None if 'link' not in alarm: alarm['link'] = None self._alarm_update(tenant_id, alarm_id, alarm['state'], alarm['lifecycle_state'], alarm['link']) result = self._alarm_show(req.uri, tenant_id, alarm_id) res.body = helpers.dumpit_utf8(result) res.status = falcon.HTTP_200
def on_put(self, req, res, alarm_id): helpers.validate_authorization(req, ['api:alarms:put']) alarm = helpers.from_json(req) schema_alarm.validate(alarm) # Validator makes state optional, so check it here if 'state' not in alarm or not alarm['state']: raise HTTPUnprocessableEntityError('Unprocessable Entity', "Field 'state' is required") if 'lifecycle_state' not in alarm or not alarm['lifecycle_state']: raise HTTPUnprocessableEntityError('Unprocessable Entity', "Field 'lifecycle_state' is required") if 'link' not in alarm or not alarm['link']: raise HTTPUnprocessableEntityError('Unprocessable Entity', "Field 'link' is required") self._alarm_update(req.project_id, alarm_id, alarm['state'], alarm['lifecycle_state'], alarm['link']) result = self._alarm_show(req.uri, req.project_id, alarm_id) res.body = helpers.to_json(result) res.status = falcon.HTTP_200
def on_put(self, req, res, alarm_id): helpers.validate_authorization(req, self._default_authorized_roles) tenant_id = helpers.get_tenant_id(req) alarm = helpers.read_http_resource(req) schema_alarm.validate(alarm) # Validator makes state optional, so check it here if 'state' not in alarm or not alarm['state']: raise falcon.HTTPBadRequest('Bad request', "Field 'state' is required") # Assume these fields are null if not provided if 'lifecycle_state' not in alarm: alarm['lifecycle_state'] = None if 'link' not in alarm: alarm['link'] = None self._alarm_update(tenant_id, alarm_id, alarm['state'], alarm['lifecycle_state'], alarm['link']) result = self._alarm_show(req.uri, tenant_id, alarm_id) res.body = helpers.dumpit_utf8(result) res.status = falcon.HTTP_200
def on_patch(self, req, res, alarm_id): helpers.validate_authorization(req, ['api:alarms:patch']) alarm = helpers.from_json(req) schema_alarm.validate(alarm) old_alarm = self._alarms_repo.get_alarm(req.project_id, alarm_id)[0] # if a field is not present or is None, replace it with the old value if 'state' not in alarm or not alarm['state']: alarm['state'] = old_alarm['state'] if 'lifecycle_state' not in alarm or alarm['lifecycle_state'] is None: alarm['lifecycle_state'] = old_alarm['lifecycle_state'] if 'link' not in alarm or alarm['link'] is None: alarm['link'] = old_alarm['link'] self._alarm_patch(req.project_id, alarm_id, alarm['state'], alarm['lifecycle_state'], alarm['link']) result = self._alarm_show(req.uri, req.project_id, alarm_id) res.body = helpers.to_json(result) res.status = falcon.HTTP_200
def on_patch(self, req, res, alarm_id): helpers.validate_authorization(req, ['api:alarms:patch']) alarm = helpers.from_json(req) schema_alarm.validate(alarm) old_alarm = self._alarms_repo.get_alarm(req.project_id, alarm_id)[0] # if a field is not present or is None, replace it with the old value if 'state' not in alarm or not alarm['state']: alarm['state'] = old_alarm['state'] if 'lifecycle_state' not in alarm or alarm['lifecycle_state'] is None: alarm['lifecycle_state'] = old_alarm['lifecycle_state'] if 'link' not in alarm or alarm['link'] is None: alarm['link'] = old_alarm['link'] self._alarm_patch(req.project_id, alarm_id, alarm['state'], alarm['lifecycle_state'], alarm['link']) result = self._alarm_show(req.uri, req.project_id, alarm_id) res.body = helpers.to_json(result) res.status = falcon.HTTP_200