コード例 #1
0
ファイル: watch.py プロジェクト: samstav/heat
    def set_alarm_state(self, req):
        """
        Implements SetAlarmState API action
        """
        self._enforce(req, "SetAlarmState")

        # Map from AWS state names to those used in the engine
        state_map = {
            "OK": engine_api.WATCH_STATE_OK,
            "ALARM": engine_api.WATCH_STATE_ALARM,
            "INSUFFICIENT_DATA": engine_api.WATCH_STATE_NODATA,
        }

        con = req.context
        parms = dict(req.params)

        # Get mandatory parameters
        name = api_utils.get_param_value(parms, "AlarmName")
        state = api_utils.get_param_value(parms, "StateValue")

        if state not in state_map:
            msg = _("Invalid state %(state)s, " "expecting one of %(expect)s") % {
                "state": state,
                "expect": state_map.keys(),
            }
            logger.error(msg)
            return exception.HeatInvalidParameterValueError(msg)

        logger.debug(_("setting %(name)s to %(state)s") % {"name": name, "state": state_map[state]})
        try:
            self.rpc_client.set_watch_state(con, watch_name=name, state=state_map[state])
        except rpc_common.RemoteError as ex:
            return exception.map_remote_error(ex)

        return api_utils.format_response("SetAlarmState", "")
コード例 #2
0
ファイル: watch.py プロジェクト: COSHPC/heat
    def set_alarm_state(self, req):
        """
        Implements SetAlarmState API action
        """
        self._enforce(req, 'SetAlarmState')

        # Map from AWS state names to those used in the engine
        state_map = {'OK': engine_api.WATCH_STATE_OK,
                     'ALARM': engine_api.WATCH_STATE_ALARM,
                     'INSUFFICIENT_DATA': engine_api.WATCH_STATE_NODATA}

        con = req.context
        parms = dict(req.params)

        # Get mandatory parameters
        name = api_utils.get_param_value(parms, 'AlarmName')
        state = api_utils.get_param_value(parms, 'StateValue')

        if state not in state_map:
            msg = _('Invalid state %(state)s, '
                    'expecting one of %(expect)s') % {
                        'state': state,
                        'expect': state_map.keys()}
            LOG.error(msg)
            return exception.HeatInvalidParameterValueError(msg)

        LOG.debug("setting %(name)s to %(state)s" % {
                  'name': name, 'state': state_map[state]})
        try:
            self.rpc_client.set_watch_state(con, watch_name=name,
                                            state=state_map[state])
        except messaging.RemoteError as ex:
            return exception.map_remote_error(ex)

        return api_utils.format_response("SetAlarmState", "")
コード例 #3
0
ファイル: watch.py プロジェクト: rs-randallburt/heat
    def set_alarm_state(self, req):
        """
        Implements SetAlarmState API action
        """
        self._enforce(req, 'SetAlarmState')

        # Map from AWS state names to those used in the engine
        state_map = {'OK': engine_api.WATCH_STATE_OK,
                     'ALARM': engine_api.WATCH_STATE_ALARM,
                     'INSUFFICIENT_DATA': engine_api.WATCH_STATE_NODATA}

        con = req.context
        parms = dict(req.params)

        # Get mandatory parameters
        name = api_utils.get_param_value(parms, 'AlarmName')
        state = api_utils.get_param_value(parms, 'StateValue')

        if state not in state_map:
            msg = _('Invalid state %(state)s, '
                    'expecting one of %(expect)s') % {
                        'state': state,
                        'expect': state_map.keys()}
            logger.error(msg)
            return exception.HeatInvalidParameterValueError(msg)

        logger.debug("setting %(name)s to %(state)s" % {
                     'name': name, 'state': state_map[state]})
        try:
            self.rpc_client.set_watch_state(con, watch_name=name,
                                            state=state_map[state])
        except rpc_common.RemoteError as ex:
            return exception.map_remote_error(ex)

        return api_utils.format_response("SetAlarmState", "")
コード例 #4
0
ファイル: watch.py プロジェクト: anotherjesse/heat
    def put_metric_data(self, req):
        """
        Implements PutMetricData API action
        """

        con = req.context
        parms = dict(req.params)
        namespace = api_utils.get_param_value(parms, 'Namespace')

        # Extract data from the request so we can pass it to the engine
        # We have to do this in two passes, because the AWS
        # query format nests the dimensions within the MetricData
        # query-parameter-list (see AWS PutMetricData docs)
        # extract_param_list gives a list-of-dict, which we then
        # need to process (each dict) for dimensions
        metric_data = api_utils.extract_param_list(parms, prefix='MetricData')
        if not len(metric_data):
            logger.error("Request does not contain required MetricData")
            return exception.HeatMissingParameterError("MetricData list")

        watch_name = None
        dimensions = []
        for p in metric_data:
            dimension = api_utils.extract_param_pairs(p,
                                                      prefix='Dimensions',
                                                      keyname='Name',
                                                      valuename='Value')
            if 'AlarmName' in dimension:
                watch_name = dimension['AlarmName']
            else:
                dimensions.append(dimension)

        # We expect an AlarmName dimension as currently the engine
        # implementation requires metric data to be associated
        # with an alarm.  When this is fixed, we can simply
        # parse the user-defined dimensions and add the list to
        # the metric data
        if not watch_name:
            logger.error("Request does not contain AlarmName dimension!")
            return exception.HeatMissingParameterError("AlarmName dimension")

        # Extract the required data from the metric_data
        # and format dict to pass to engine
        data = {
            'Namespace': namespace,
            api_utils.get_param_value(metric_data[0], 'MetricName'): {
                'Unit': api_utils.get_param_value(metric_data[0], 'Unit'),
                'Value': api_utils.get_param_value(metric_data[0], 'Value'),
                'Dimensions': dimensions
            }
        }

        try:
            self.engine_rpcapi.create_watch_data(con, watch_name, data)
        except rpc_common.RemoteError as ex:
            return exception.map_remote_error(ex)

        result = {'ResponseMetadata': None}
        return api_utils.format_response("PutMetricData", result)
コード例 #5
0
ファイル: watch.py プロジェクト: CiscoAS/heat
    def put_metric_data(self, req):
        """
        Implements PutMetricData API action
        """
        self._enforce(req, 'PutMetricData')

        con = req.context
        parms = dict(req.params)
        namespace = api_utils.get_param_value(parms, 'Namespace')

        # Extract data from the request so we can pass it to the engine
        # We have to do this in two passes, because the AWS
        # query format nests the dimensions within the MetricData
        # query-parameter-list (see AWS PutMetricData docs)
        # extract_param_list gives a list-of-dict, which we then
        # need to process (each dict) for dimensions
        metric_data = api_utils.extract_param_list(parms, prefix='MetricData')
        if not len(metric_data):
            logger.error("Request does not contain required MetricData")
            return exception.HeatMissingParameterError("MetricData list")

        watch_name = None
        dimensions = []
        for p in metric_data:
            dimension = api_utils.extract_param_pairs(p,
                                                      prefix='Dimensions',
                                                      keyname='Name',
                                                      valuename='Value')
            if 'AlarmName' in dimension:
                watch_name = dimension['AlarmName']
            else:
                dimensions.append(dimension)

        # We expect an AlarmName dimension as currently the engine
        # implementation requires metric data to be associated
        # with an alarm.  When this is fixed, we can simply
        # parse the user-defined dimensions and add the list to
        # the metric data
        if not watch_name:
            logger.error("Request does not contain AlarmName dimension!")
            return exception.HeatMissingParameterError("AlarmName dimension")

        # Extract the required data from the metric_data
        # and format dict to pass to engine
        data = {'Namespace': namespace,
                api_utils.get_param_value(metric_data[0], 'MetricName'): {
                    'Unit': api_utils.get_param_value(metric_data[0], 'Unit'),
                    'Value': api_utils.get_param_value(metric_data[0],
                                                       'Value'),
                    'Dimensions': dimensions}}

        try:
            self.engine_rpcapi.create_watch_data(con, watch_name, data)
        except rpc_common.RemoteError as ex:
            return exception.map_remote_error(ex)

        result = {'ResponseMetadata': None}
        return api_utils.format_response("PutMetricData", result)
コード例 #6
0
ファイル: watch.py プロジェクト: MobileCloudNetworking/QOS_OS
    def put_metric_data(self, req):
        """
        Implements PutMetricData API action
        """
        self._enforce(req, 'PutMetricData')

        con = req.context
        parms = dict(req.params)
        namespace = api_utils.get_param_value(parms, 'Namespace')

        # Extract data from the request so we can pass it to the engine
        # We have to do this in two passes, because the AWS
        # query format nests the dimensions within the MetricData
        # query-parameter-list (see AWS PutMetricData docs)
        # extract_param_list gives a list-of-dict, which we then
        # need to process (each dict) for dimensions
        metric_data = api_utils.extract_param_list(parms, prefix='MetricData')
        if not len(metric_data):
            LOG.error(_LE("Request does not contain required MetricData"))
            return exception.HeatMissingParameterError("MetricData list")

        watch_name = None
        dimensions = []
        for p in metric_data:
            dimension = api_utils.extract_param_pairs(p,
                                                      prefix='Dimensions',
                                                      keyname='Name',
                                                      valuename='Value')
            if 'AlarmName' in dimension:
                watch_name = dimension['AlarmName']
            else:
                dimensions.append(dimension)

        # Extract the required data from the metric_data
        # and format dict to pass to engine
        data = {
            'Namespace': namespace,
            api_utils.get_param_value(metric_data[0], 'MetricName'): {
                'Unit': api_utils.get_param_value(metric_data[0], 'Unit'),
                'Value': api_utils.get_param_value(metric_data[0], 'Value'),
                'Dimensions': dimensions
            }
        }

        try:
            self.rpc_client.create_watch_data(con, watch_name, data)
        except messaging.RemoteError as ex:
            return exception.map_remote_error(ex)

        result = {'ResponseMetadata': None}
        return api_utils.format_response("PutMetricData", result)
コード例 #7
0
    def set_alarm_state(self, req):
        """
        Implements SetAlarmState API action
        """
        self._enforce(req, 'SetAlarmState')

        # Map from AWS state names to those used in the engine
        state_map = {
            'OK': engine_api.WATCH_STATE_OK,
            'ALARM': engine_api.WATCH_STATE_ALARM,
            'INSUFFICIENT_DATA': engine_api.WATCH_STATE_NODATA
        }

        con = req.context
        parms = dict(req.params)

        # Get mandatory parameters
        name = api_utils.get_param_value(parms, 'AlarmName')
        state = api_utils.get_param_value(parms, 'StateValue')

        if state not in state_map:
            msg = _('Invalid state %(state)s, '
                    'expecting one of %(expect)s') % {
                        'state': state,
                        'expect': state_map.keys()
                    }
            logger.error(msg)
            return exception.HeatInvalidParameterValueError(msg)

        # Check for optional parameters
        # FIXME : We don't actually do anything with these in the engine yet..
        state_reason = None
        state_reason_data = None
        if 'StateReason' in parms:
            state_reason = parms['StateReason']
        if 'StateReasonData' in parms:
            state_reason_data = parms['StateReasonData']

        logger.debug(
            _("setting %(name)s to %(state)s") % {
                'name': name,
                'state': state_map[state]
            })
        try:
            self.engine_rpcapi.set_watch_state(con,
                                               watch_name=name,
                                               state=state_map[state])
        except rpc_common.RemoteError as ex:
            return exception.map_remote_error(ex)

        return api_utils.format_response("SetAlarmState", "")
コード例 #8
0
ファイル: watch.py プロジェクト: samstav/heat
    def put_metric_data(self, req):
        """
        Implements PutMetricData API action
        """
        self._enforce(req, "PutMetricData")

        con = req.context
        parms = dict(req.params)
        namespace = api_utils.get_param_value(parms, "Namespace")

        # Extract data from the request so we can pass it to the engine
        # We have to do this in two passes, because the AWS
        # query format nests the dimensions within the MetricData
        # query-parameter-list (see AWS PutMetricData docs)
        # extract_param_list gives a list-of-dict, which we then
        # need to process (each dict) for dimensions
        metric_data = api_utils.extract_param_list(parms, prefix="MetricData")
        if not len(metric_data):
            logger.error(_("Request does not contain required MetricData"))
            return exception.HeatMissingParameterError("MetricData list")

        watch_name = None
        dimensions = []
        for p in metric_data:
            dimension = api_utils.extract_param_pairs(p, prefix="Dimensions", keyname="Name", valuename="Value")
            if "AlarmName" in dimension:
                watch_name = dimension["AlarmName"]
            else:
                dimensions.append(dimension)

        # Extract the required data from the metric_data
        # and format dict to pass to engine
        data = {
            "Namespace": namespace,
            api_utils.get_param_value(metric_data[0], "MetricName"): {
                "Unit": api_utils.get_param_value(metric_data[0], "Unit"),
                "Value": api_utils.get_param_value(metric_data[0], "Value"),
                "Dimensions": dimensions,
            },
        }

        try:
            self.rpc_client.create_watch_data(con, watch_name, data)
        except rpc_common.RemoteError as ex:
            return exception.map_remote_error(ex)

        result = {"ResponseMetadata": None}
        return api_utils.format_response("PutMetricData", result)
コード例 #9
0
ファイル: watch.py プロジェクト: cmukai/heat
    def set_alarm_state(self, req):
        """
        Implements SetAlarmState API action
        """
        self._enforce(req, 'SetAlarmState')

        # Map from AWS state names to those used in the engine
        state_map = {'OK': engine_api.WATCH_STATE_OK,
                     'ALARM': engine_api.WATCH_STATE_ALARM,
                     'INSUFFICIENT_DATA': engine_api.WATCH_STATE_NODATA}

        con = req.context
        parms = dict(req.params)

        # Get mandatory parameters
        name = api_utils.get_param_value(parms, 'AlarmName')
        state = api_utils.get_param_value(parms, 'StateValue')

        if state not in state_map:
            msg = _('Invalid state %(state)s, '
                    'expecting one of %(expect)s') % {
                        'state': state,
                        'expect': state_map.keys()}
            logger.error(msg)
            return exception.HeatInvalidParameterValueError(msg)

        # Check for optional parameters
        # FIXME : We don't actually do anything with these in the engine yet..
        state_reason = None
        state_reason_data = None
        if 'StateReason' in parms:
            state_reason = parms['StateReason']
        if 'StateReasonData' in parms:
            state_reason_data = parms['StateReasonData']

        logger.debug(_("setting %(name)s to %(state)s") % {
                     'name': name, 'state': state_map[state]})
        try:
            self.engine_rpcapi.set_watch_state(con, watch_name=name,
                                               state=state_map[state])
        except rpc_common.RemoteError as ex:
            return exception.map_remote_error(ex)

        return api_utils.format_response("SetAlarmState", "")
コード例 #10
0
ファイル: test_api_aws.py プロジェクト: p0i0/openstack-heat
 def test_get_param_value(self):
     params = {"foo": 123}
     self.assertEqual(123, api_utils.get_param_value(params, "foo"))
コード例 #11
0
 def test_get_param_value(self):
     params = {"foo": 123}
     self.assertEqual(123, api_utils.get_param_value(params, "foo"))