示例#1
0
    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
示例#2
0
    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
示例#3
0
    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
示例#4
0
    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
示例#5
0
    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
示例#6
0
    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
示例#7
0
 def on_post(self, req, res):
     helpers.validate_json_content_type(req)
     helpers.validate_authorization(req, self._default_authorized_roles)
     notification = helpers.read_http_resource(req)
     self._parse_and_validate_notification(notification)
     result = self._create_notification(req.project_id, notification, req.uri)
     res.body = helpers.dumpit_utf8(result)
     res.status = falcon.HTTP_201
示例#8
0
 def on_post(self, req, res):
     helpers.validate_json_content_type(req)
     helpers.validate_authorization(req, self._default_authorized_roles)
     notification = helpers.read_http_resource(req)
     self._parse_and_validate_notification(notification)
     result = self._create_notification(req.project_id, notification, req.uri)
     res.body = helpers.dumpit_utf8(result)
     res.status = falcon.HTTP_201
示例#9
0
 def on_put(self, req, res, notification_method_id):
     helpers.validate_json_content_type(req)
     helpers.validate_authorization(req, self._default_authorized_roles)
     notification = helpers.read_http_resource(req)
     self._parse_and_validate_notification(notification, require_all=True)
     tenant_id = helpers.get_tenant_id(req)
     result = self._update_notification(notification_method_id, tenant_id, notification, req.uri)
     res.body = helpers.dumpit_utf8(result)
     res.status = falcon.HTTP_200
示例#10
0
 def on_put(self, req, res, notification_method_id):
     helpers.validate_json_content_type(req)
     helpers.validate_authorization(req, self._default_authorized_roles)
     notification = helpers.read_http_resource(req)
     self._parse_and_validate_notification(notification, require_all=True)
     tenant_id = helpers.get_tenant_id(req)
     result = self._update_notification(notification_method_id, tenant_id,
                                        notification, req.uri)
     res.body = helpers.dumpit_utf8(result)
     res.status = falcon.HTTP_200
示例#11
0
 def on_post(self, req, res):
     helpers.validate_json_content_type(req)
     helpers.validate_authorization(req,
                                    self._post_metrics_authorized_roles)
     metrics = helpers.read_http_resource(req)
     self._validate_metrics(metrics)
     tenant_id = (helpers.get_x_tenant_or_tenant_id(
         req, self._delegate_authorized_roles))
     transformed_metrics = metrics_message.transform(
         metrics, tenant_id, self._region)
     self._send_metrics(transformed_metrics)
     res.status = falcon.HTTP_204
示例#12
0
 def on_post(self, req, res):
     helpers.validate_json_content_type(req)
     helpers.validate_authorization(req,
                                    self._post_metrics_authorized_roles)
     metrics = helpers.read_http_resource(req)
     self._validate_metrics(metrics)
     tenant_id = (
         helpers.get_x_tenant_or_tenant_id(req,
                                           self._delegate_authorized_roles))
     transformed_metrics = metrics_message.transform(
         metrics, tenant_id, self._region)
     self._send_metrics(transformed_metrics)
     res.status = falcon.HTTP_204
示例#13
0
    def on_post(self, req, res):
        helpers.validate_json_content_type(req)
        helpers.validate_authorization(req,
                                       self._post_metrics_authorized_roles)
        metrics = helpers.read_http_resource(req)
        try:
            metric_validation.validate(metrics)
        except Exception as ex:
            LOG.exception(ex)
            raise HTTPUnprocessableEntityError("Unprocessable Entity",
                                               ex.message)

        tenant_id = (helpers.get_x_tenant_or_tenant_id(
            req, self._delegate_authorized_roles))
        transformed_metrics = metrics_message.transform(
            metrics, tenant_id, self._region)
        self._send_metrics(transformed_metrics)
        res.status = falcon.HTTP_204
示例#14
0
    def on_post(self, req, res):
        helpers.validate_json_content_type(req)
        helpers.validate_authorization(req,
                                       self._post_metrics_authorized_roles)
        metrics = helpers.read_http_resource(req)
        try:
            metric_validation.validate(metrics)
        except Exception as ex:
            LOG.exception(ex)
            self._statsd_rejected_count.increment(1)
            raise HTTPUnprocessableEntityError("Unprocessable Entity", ex.message)

        tenant_id = (
            helpers.get_x_tenant_or_tenant_id(req,
                                              self._delegate_authorized_roles))
        transformed_metrics = metrics_message.transform(
            metrics, tenant_id, self._region)
        self._send_metrics(transformed_metrics)
        res.status = falcon.HTTP_204