예제 #1
0
 def get_external_project_owner():
     kc = keystone_client.get_client(pecan.request.cfg)
     project_name = pecan.request.cfg.api.gnocchi_external_project_owner
     try:
         project = kc.projects.find(name=project_name)
         return project.id
     except ka_exceptions.NotFound:
         return None
예제 #2
0
파일: zaqar.py 프로젝트: openstack-yak/aodh
 def _get_endpoint(self):
     try:
         ks_client = keystone_client.get_client(self.conf)
         return ks_client.service_catalog.url_for(
             service_type=cfg.CONF.service_types.zaqar,
             endpoint_type=self.conf.service_credentials.os_endpoint_type)
     except Exception:
         LOG.error(_LE("Aodh was configured to use zaqar:// action,"
                       " but Zaqar endpoint could not be found in Keystone"
                       " service catalog."))
예제 #3
0
 def _get_endpoint(self):
     try:
         ks_client = keystone_client.get_client(self.conf)
         return ks_client.service_catalog.url_for(
             service_type=cfg.CONF.service_types.zaqar,
             endpoint_type=self.conf.service_credentials.os_endpoint_type)
     except Exception:
         LOG.error(
             _LE("Aodh was configured to use zaqar:// action,"
                 " but Zaqar endpoint could not be found in Keystone"
                 " service catalog."))
예제 #4
0
 def _get_endpoint(self):
     if self._endpoint is None:
         try:
             ks_client = keystone_client.get_client(self.conf)
             srv = ks_client.services.find(type='function-engine')
             endpoint = ks_client.endpoints.find(service_id=srv.id,
                                                 interface='public')
             self._endpoint = endpoint.url
         except Exception:
             LOG.error("Qinling endpoint could not be found in Keystone "
                       "service catalog.")
     return self._endpoint
예제 #5
0
파일: gnocchi.py 프로젝트: sileht/aodh
    def _get_aggregation_methods():
        ks_client = keystone_client.get_client(pecan.request.cfg)
        gnocchi_url = pecan.request.cfg.gnocchi_url
        headers = {'Content-Type': "application/json",
                   'X-Auth-Token': ks_client.auth_token}
        try:
            r = requests.get("%s/v1/capabilities" % gnocchi_url,
                             headers=headers)
        except requests.ConnectionError as e:
            raise GnocchiUnavailable(e)
        if r.status_code // 200 != 1:
            raise GnocchiUnavailable(r.text)

        return jsonutils.loads(r.text).get('aggregation_methods', [])
예제 #6
0
파일: zaqar.py 프로젝트: mail2nsrajesh/aodh
 def _get_endpoint(self):
     if self._zendpoint is None:
         try:
             ks_client = keystone_client.get_client(self.conf)
             z_srv = ks_client.services.find(
                 type=self.conf.service_types.zaqar)
             endpoint_type = self.conf.service_credentials.interface
             z_endpoint = ks_client.endpoints.find(service_id=z_srv.id,
                                                   interface=endpoint_type)
             self._zendpoint = z_endpoint.url
         except Exception:
             LOG.error("Aodh was configured to use zaqar:// action,"
                       " but Zaqar endpoint could not be found in"
                       " Keystone service catalog.")
     return self._zendpoint
예제 #7
0
파일: zaqar.py 프로젝트: openstack/aodh
 def _get_endpoint(self):
     if self._zendpoint is None:
         try:
             ks_client = keystone_client.get_client(self.conf)
             z_srv = ks_client.services.find(
                 type=self.conf.service_types.zaqar)
             endpoint_type = self.conf.service_credentials.interface
             z_endpoint = ks_client.endpoints.find(service_id=z_srv.id,
                                                   interface=endpoint_type)
             self._zendpoint = z_endpoint.url
         except Exception:
             LOG.error(_LE("Aodh was configured to use zaqar:// action,"
                           " but Zaqar endpoint could not be found in"
                           " Keystone service catalog."))
     return self._zendpoint
예제 #8
0
파일: trust.py 프로젝트: openstack-yak/aodh
    def notify(self, action, alarm_id, alarm_name, severity, previous, current, reason, reason_data):
        trust_id = action.username

        client = keystone_client.get_client(self.conf, trust_id)

        # Remove the fake user
        netloc = action.netloc.split("@")[1]
        # Remove the trust prefix
        scheme = action.scheme[6:]

        action = parse.SplitResult(scheme, netloc, action.path, action.query, action.fragment)

        headers = {"X-Auth-Token": keystone_client.get_auth_token(client)}
        super(TrustRestAlarmNotifier, self).notify(
            action, alarm_id, alarm_name, severity, previous, current, reason, reason_data, headers
        )
예제 #9
0
파일: gnocchi.py 프로젝트: yi-cloud/aodh
 def get_external_project_owner():
     kc = keystone_client.get_client(pecan.request.cfg)
     project_name = pecan.request.cfg.api.gnocchi_external_project_owner
     domain_name = pecan.request.cfg.api.gnocchi_external_domain_name
     try:
         domains = kc.domains.list(name=domain_name)
         project = kc.projects.find(name=project_name,
                                    domain_id=domains[0].id)
         return project.id
     except ka_exceptions.NotFound:
         LOG.warning(
             "Unable to get domain or project information. "
             "domain_name : %(domain_name)s, "
             "project_name : %(project_name)s", {
                 'domain_name': domain_name,
                 'project_name': project_name
             })
         return None
예제 #10
0
파일: trust.py 프로젝트: paperandsoap/aodh
    def notify(self, action, alarm_id, alarm_name, severity, previous, current,
               reason, reason_data):
        trust_id = action.username

        client = keystone_client.get_client(self.conf, trust_id)

        # Remove the fake user
        netloc = action.netloc.split("@")[1]
        # Remove the trust prefix
        scheme = action.scheme[6:]

        action = parse.SplitResult(scheme, netloc, action.path, action.query,
                                   action.fragment)

        headers = {'X-Auth-Token': keystone_client.get_auth_token(client)}
        super(TrustRestAlarmNotifier, self).notify(
            action, alarm_id, alarm_name, severity, previous, current, reason,
            reason_data, headers)
예제 #11
0
파일: gnocchi.py 프로젝트: sileht/aodh
    def validate_alarm(cls, alarm):
        super(MetricOfResourceRule,
              cls).validate_alarm(alarm)

        rule = alarm.gnocchi_resources_threshold_rule
        ks_client = keystone_client.get_client(pecan.request.cfg)
        gnocchi_url = pecan.request.cfg.gnocchi_url
        headers = {'Content-Type': "application/json",
                   'X-Auth-Token': ks_client.auth_token}
        try:
            r = requests.get("%s/v1/resource/%s/%s" % (
                gnocchi_url, rule.resource_type,
                rule.resource_id),
                headers=headers)
        except requests.ConnectionError as e:
            raise GnocchiUnavailable(e)
        if r.status_code == 404:
            raise base.EntityNotFound('gnocchi resource',
                                      rule.resource_id)
        elif r.status_code // 200 != 1:
            raise base.ClientSideError(r.content, status_code=r.status_code)
예제 #12
0
파일: gnocchi.py 프로젝트: pczerkas/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 = 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:
            rule.query = jsonutils.dumps({
                "and": [{"=": {"created_by_project_id": auth_project}},
                        query]})

        # Delegate the query validation to gnocchi
        ks_client = keystone_client.get_client(pecan.request.cfg)
        request = {
            'url': "%s/v1/aggregation/resource/%s/metric/%s" % (
                pecan.request.cfg.gnocchi_url,
                rule.resource_type,
                rule.metric),
            'headers': {'Content-Type': "application/json",
                        'X-Auth-Token': ks_client.auth_token},
            'params': {'aggregation': rule.aggregation_method,
                       'needed_overlap': 0},
            'data': rule.query,
        }

        try:
            r = requests.post(**request)
        except requests.ConnectionError as e:
            raise GnocchiUnavailable(e)
        if r.status_code // 200 != 1:
            raise base.ClientSideError(r.content, status_code=r.status_code)
예제 #13
0
파일: gnocchi.py 프로젝트: sileht/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 = 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:
            rule.query = jsonutils.dumps({
                "and": [{"=": {"created_by_project_id": auth_project}},
                        query]})

        # Delegate the query validation to gnocchi
        ks_client = keystone_client.get_client(pecan.request.cfg)
        request = {
            'url': "%s/v1/aggregation/resource/%s/metric/%s" % (
                pecan.request.cfg.gnocchi_url,
                rule.resource_type,
                rule.metric),
            'headers': {'Content-Type': "application/json",
                        'X-Auth-Token': ks_client.auth_token},
            'params': {'aggregation': rule.aggregation_method},
            'data': rule.query,
        }

        try:
            r = requests.post(**request)
        except requests.ConnectionError as e:
            raise GnocchiUnavailable(e)
        if r.status_code // 200 != 1:
            raise base.ClientSideError(r.content, status_code=r.status_code)
예제 #14
0
 def ks_client(self):
     if self._ks_client is None:
         self._ks_client = keystone_client.get_client(self.conf)
     return self._ks_client
예제 #15
0
 def ks_client(self):
     if self._ks_client is None:
         self._ks_client = keystone_client.get_client(self.conf)
     return self._ks_client