예제 #1
0
파일: gnocchi.py 프로젝트: psachin/aodh
 def __init__(self, conf):
     super(GnocchiBase, self).__init__(conf)
     self._gnocchi_client = client.Client(
         '1',
         keystone_client.get_session(conf),
         interface=conf.service_credentials.interface,
         region_name=conf.service_credentials.region_name)
예제 #2
0
파일: threshold.py 프로젝트: openstack/aodh
    def _check_ceilometer_sample_api(cls):
        # Check it only once
        if cls.ceilometer_sample_api_is_supported is None:

            auth_config = pecan.request.cfg.service_credentials
            client = ceiloclient.get_client(
                version=2,
                session=keystone_client.get_session(pecan.request.cfg),
                # ceiloclient adapter options
                region_name=auth_config.region_name,
                interface=auth_config.interface,
            )
            try:
                client.statistics.list(
                    meter_name="idontthinkthatexistsbutwhatever")
            except Exception as e:
                if isinstance(e, ceiloexc.HTTPException):
                    if e.code == 410:
                        cls.ceilometer_sample_api_is_supported = False
                    elif e.code < 500:
                        cls.ceilometer_sample_api_is_supported = True
                    else:
                        raise
                else:
                    raise
            else:
                # I don't think this meter can exists but how known
                cls.ceilometer_sample_api_is_supported = True

        if cls.ceilometer_sample_api_is_supported is False:
            raise base.ClientSideError(
                "This telemetry installation is not configured to support"
                "alarm of type 'threshold")
예제 #3
0
    def _check_ceilometer_sample_api(cls):
        # Check it only once
        if cls.ceilometer_sample_api_is_supported is None:

            auth_config = pecan.request.cfg.service_credentials
            client = ceiloclient.get_client(
                version=2,
                session=keystone_client.get_session(pecan.request.cfg),
                # ceiloclient adapter options
                region_name=auth_config.region_name,
                interface=auth_config.interface,
            )
            try:
                client.statistics.list(
                    meter_name="idontthinkthatexistsbutwhatever")
            except Exception as e:
                if isinstance(e, ceiloexc.HTTPException):
                    if e.code == 410:
                        cls.ceilometer_sample_api_is_supported = False
                    elif e.code < 500:
                        cls.ceilometer_sample_api_is_supported = True
                    else:
                        raise
                else:
                    raise
            else:
                # I don't think this meter can exist but how known
                cls.ceilometer_sample_api_is_supported = True

        if cls.ceilometer_sample_api_is_supported is False:
            raise base.ClientSideError(
                "This telemetry installation is not configured to support"
                "alarm of type 'threshold")
 def __init__(self, conf):
     super(GnocchiBase, self).__init__(conf)
     self._gnocchi_client = client.Client(
         '1', keystone_client.get_session(conf),
         interface=conf.service_credentials.interface,
         region_name=conf.service_credentials.region_name,
         endpoint_override=conf.gnocchi_url)
예제 #5
0
 def __init__(self, conf):
     super(GnocchiBase, self).__init__(conf)
     self._gnocchi_client = client.Client(
         '1',
         keystone_client.get_session(conf),
         adapter_options={
             'interface': conf.service_credentials.interface,
             'region_name': conf.service_credentials.region_name
         })
예제 #6
0
파일: gnocchi.py 프로젝트: wangyiyang/aodh
    def validate_alarm(cls, alarm):
        super(AggregationMetricByResourcesLookupRule,
              cls).validate_alarm(alarm)

        rule = alarm.gnocchi_aggregation_by_resources_threshold_rule

        # check the query string is a valid json
        try:
            query = json.loads(rule.query)
        except ValueError:
            raise wsme.exc.InvalidInput('rule/query', rule.query)

        conf = pecan.request.cfg

        # Scope the alarm to the project id if needed
        auth_project = v2_utils.get_auth_project(alarm.project_id)
        if auth_project:

            perms_filter = {"=": {"created_by_project_id": auth_project}}

            external_project_owner = cls.get_external_project_owner()
            if external_project_owner:
                perms_filter = {"or": [
                    perms_filter,
                    {"and": [
                        {"=": {"created_by_project_id":
                               external_project_owner}},
                        {"=": {"project_id": auth_project}}]}
                ]}

            query = {"and": [perms_filter, query]}
            rule.query = json.dumps(query)

        gnocchi_client = client.Client(
            '1', keystone_client.get_session(conf),
            adapter_options={
                'interface': conf.service_credentials.interface,
                'region_name': conf.service_credentials.region_name})
        try:
            gnocchi_client.metric.aggregation(
                metrics=rule.metric,
                query=query,
                aggregation=rule.aggregation_method,
                needed_overlap=0,
                start="-1 day",
                stop="now",
                resource_type=rule.resource_type)
        except exceptions.ClientException as e:
            if e.code == 404:
                # NOTE(sileht): We are fine here, we just want to ensure the
                # 'query' payload is valid for Gnocchi If the metric
                # doesn't exists yet, it doesn't matter
                return
            raise base.ClientSideError(e.message, status_code=e.code)
        except Exception as e:
            raise GnocchiUnavailable(e)
예제 #7
0
    def cm_client(self):
        if self._cm_client is None:
            auth_config = self.conf.service_credentials
            self._cm_client = ceiloclient.get_client(
                version=2,
                session=keystone_client.get_session(self.conf),
                region_name=auth_config.region_name,
                interface=auth_config.interface,
            )

        return self._cm_client
예제 #8
0
    def cm_client(self):
        if self._cm_client is None:
            auth_config = self.conf.service_credentials
            self._cm_client = ceiloclient.get_client(
                version=2,
                session=keystone_client.get_session(self.conf),
                # ceiloclient adapter options
                region_name=auth_config.region_name,
                interface=auth_config.interface,
            )

        return self._cm_client
예제 #9
0
    def lb_client(self):
        if self._lb_client is None:
            endpoint = aodh_keystone.url_for(
                self.conf,
                service_type='load-balancer',
                interface="internal",
                region_name=self.conf.service_credentials.region_name)
            self._lb_client = octavia.OctaviaAPI(
                session=aodh_keystone.get_session(self.conf),
                service_type='load-balancer',
                endpoint=endpoint)

        return self._lb_client
예제 #10
0
    def _get_aggregation_methods():
        conf = pecan.request.cfg
        gnocchi_client = client.Client(
            '1', keystone_client.get_session(conf),
            interface=conf.service_credentials.interface,
            region_name=conf.service_credentials.region_name)

        try:
            return gnocchi_client.capabilities.list().get(
                'aggregation_methods', [])
        except exceptions.ClientException as e:
            raise base.ClientSideError(e.message, status_code=e.code)
        except Exception as e:
            raise GnocchiUnavailable(e)
    def _get_aggregation_methods():
        conf = pecan.request.cfg
        gnocchi_client = client.Client(
            '1', keystone_client.get_session(conf),
            interface=conf.service_credentials.interface,
            region_name=conf.service_credentials.region_name,
            endpoint_override=conf.gnocchi_url)

        try:
            return gnocchi_client.capabilities.list().get(
                'aggregation_methods', [])
        except exceptions.ClientException as e:
            raise base.ClientSideError(e.message, status_code=e.code)
        except Exception as e:
            raise GnocchiUnavailable(e)
예제 #12
0
    def validate_alarm(cls, alarm):
        super(MetricOfResourceRule, cls).validate_alarm(alarm)

        conf = pecan.request.cfg
        gnocchi_client = client.Client(
            '1',
            keystone_client.get_session(conf),
            interface=conf.service_credentials.interface,
            region_name=conf.service_credentials.region_name)

        rule = alarm.gnocchi_resources_threshold_rule
        try:
            gnocchi_client.resource.get(rule.resource_type, rule.resource_id)
        except exceptions.ClientException as e:
            raise base.ClientSideError(e.message, status_code=e.code)
        except Exception as e:
            raise GnocchiUnavailable(e)
예제 #13
0
파일: gnocchi.py 프로젝트: openstack/aodh
    def validate_alarm(cls, alarm):
        super(MetricOfResourceRule, cls).validate_alarm(alarm)

        conf = pecan.request.cfg
        gnocchi_client = client.Client(
            "1",
            keystone_client.get_session(conf),
            interface=conf.service_credentials.interface,
            region_name=conf.service_credentials.region_name,
        )

        rule = alarm.gnocchi_resources_threshold_rule
        try:
            gnocchi_client.resource.get(rule.resource_type, rule.resource_id)
        except exceptions.ClientException as e:
            raise base.ClientSideError(e.message, status_code=e.code)
        except Exception as e:
            raise GnocchiUnavailable(e)
예제 #14
0
    def validate_alarm(cls, alarm):
        super(AggregationMetricByResourcesLookupRule,
              cls).validate_alarm(alarm)

        rule = alarm.gnocchi_aggregation_by_resources_threshold_rule

        # check the query string is a valid json
        try:
            query = jsonutils.loads(rule.query)
        except ValueError:
            raise wsme.exc.InvalidInput('rule/query', rule.query)

        # Scope the alarm to the project id if needed
        auth_project = v2_utils.get_auth_project(alarm.project_id)
        if auth_project:
            query = {
                "and": [{
                    "=": {
                        "created_by_project_id": auth_project
                    }
                }, query]
            }
            rule.query = jsonutils.dumps(query)

        conf = pecan.request.cfg
        gnocchi_client = client.Client(
            '1',
            keystone_client.get_session(conf),
            interface=conf.service_credentials.interface,
            region_name=conf.service_credentials.region_name,
            endpoint_override=conf.gnocchi_url)

        try:
            gnocchi_client.metric.aggregation(
                metrics=rule.metric,
                query=query,
                aggregation=rule.aggregation_method,
                needed_overlap=0,
                resource_type=rule.resource_type)
        except exceptions.ClientException as e:
            raise base.ClientSideError(e.message, status_code=e.code)
        except Exception as e:
            raise GnocchiUnavailable(e)
    def validate_alarm(cls, alarm):
        super(AggregationMetricByResourcesLookupRule,
              cls).validate_alarm(alarm)

        rule = alarm.gnocchi_aggregation_by_resources_threshold_rule

        # check the query string is a valid json
        try:
            query = jsonutils.loads(rule.query)
        except ValueError:
            raise wsme.exc.InvalidInput('rule/query', rule.query)

        # Scope the alarm to the project id if needed
        auth_project = v2_utils.get_auth_project(alarm.project_id)
        if auth_project:
            query = {"and": [{"=": {"created_by_project_id": auth_project}},
                             query]}
            rule.query = jsonutils.dumps(query)

        conf = pecan.request.cfg
        gnocchi_client = client.Client(
            '1', keystone_client.get_session(conf),
            interface=conf.service_credentials.interface,
            region_name=conf.service_credentials.region_name,
            endpoint_override=conf.gnocchi_url)

        try:
            gnocchi_client.metric.aggregation(
                metrics=rule.metric,
                query=query,
                aggregation=rule.aggregation_method,
                needed_overlap=0,
                resource_type=rule.resource_type)
        except exceptions.ClientException as e:
            raise base.ClientSideError(e.message, status_code=e.code)
        except Exception as e:
            raise GnocchiUnavailable(e)