Ejemplo n.º 1
0
class V2Controller(object):
    """Version 2 API controller root."""

    resources = resources.ResourcesController()
    meters = meters.MetersController()
    samples = samples.SamplesController()
    alarms = alarms.AlarmsController()
    event_types = events.EventTypesController()
    events = events.EventsController()
    query = query.QueryController()
    capabilities = capabilities.CapabilitiesController()
Ejemplo n.º 2
0
 def _lookup(self, kind, *remainder):
     if (kind in ['meters', 'resources', 'samples', 'instancestates']
             and self.gnocchi_is_enabled):
         if kind == 'meters' and pecan.request.method == 'POST':
             direct = pecan.request.params.get('direct', '')
             if strutils.bool_from_string(direct):
                 pecan.abort(
                     400,
                     _('direct option cannot be true when '
                       'Gnocchi is enabled.'))
             return meters.MetersController(), remainder
         gnocchi_abort()
     elif kind == 'meters':
         return meters.MetersController(), remainder
     elif kind == 'resources':
         return resources.ResourcesController(), remainder
     elif kind == 'samples':
         return samples.SamplesController(), remainder
     elif kind == 'query':
         return QueryController(
             gnocchi_is_enabled=self.gnocchi_is_enabled,
             aodh_url=self.aodh_url,
         ), remainder
     elif kind == 'alarms' and (not self.aodh_url):
         aodh_abort()
     elif kind == 'alarms' and self.aodh_url:
         _redirect(self.aodh_url)
     elif kind == 'events':
         if self.panko_url:
             return _redirect(self.panko_url)
         return events.EventsController(), remainder
     elif kind == 'event_types':
         if self.panko_url:
             return _redirect(self.panko_url)
         return events.EventTypesController(), remainder
     # add by xieweijie for instance states
     # 2017-06-20
     elif kind == 'instancestates':
         if self.panko_url:
             return _redirect(self.panko_url)
         return instancestates.instancestatesController(), remainder
     # end
     # hy added
     elif kind == "capability":
         if self.panko_url:
             return _redirect(self.panko_url)
         return capability.CapabilityController(), remainder
     # hy added
     else:
         pecan.abort(404)
Ejemplo n.º 3
0
class V2Controller(object):
    """Version 2 API controller root."""

    event_types = events.EventTypesController()
    events = events.EventsController()
    capabilities = capabilities.CapabilitiesController()

    def __init__(self):
        self._gnocchi_is_enabled = None
        self._aodh_is_enabled = None
        self._aodh_url = None

    @property
    def gnocchi_is_enabled(self):
        if self._gnocchi_is_enabled is None:
            if cfg.CONF.api.gnocchi_is_enabled is not None:
                self._gnocchi_is_enabled = cfg.CONF.api.gnocchi_is_enabled

            elif ("gnocchi" not in cfg.CONF.dispatcher
                  or "database" in cfg.CONF.dispatcher):
                self._gnocchi_is_enabled = False
            else:
                try:
                    ks = keystone_client.get_client()
                    ks.service_catalog.url_for(service_type='metric')
                except exceptions.EndpointNotFound:
                    self._gnocchi_is_enabled = False
                except exceptions.ClientException:
                    LOG.warn(
                        _LW("Can't connect to keystone, assuming gnocchi "
                            "is disabled and retry later"))
                else:
                    self._gnocchi_is_enabled = True
                    LOG.warn(
                        _LW("ceilometer-api started with gnocchi "
                            "enabled. The resources/meters/samples "
                            "URLs are disabled."))
        return self._gnocchi_is_enabled

    @property
    def aodh_url(self):
        if self._aodh_url is None:
            if cfg.CONF.api.aodh_is_enabled is False:
                self._aodh_url = ""
            elif cfg.CONF.api.aodh_url is not None:
                self._aodh_url = self._normalize_aodh_url(
                    cfg.CONF.api.aodh_url)
            else:
                try:
                    ks = keystone_client.get_client()
                    self._aodh_url = self._normalize_aodh_url(
                        ks.service_catalog.url_for(service_type='alarming'))
                except exceptions.EndpointNotFound:
                    self._aodh_url = ""
                except exceptions.ClientException:
                    LOG.warn(
                        _LW("Can't connect to keystone, "
                            "assuming aodh is disabled and retry later."))
                else:
                    LOG.warn(
                        _LW("ceilometer-api started with aodh enabled. "
                            "Alarms URLs will be redirected to aodh "
                            "endpoint."))
        return self._aodh_url

    @pecan.expose()
    def _lookup(self, kind, *remainder):
        if (kind in ['meters', 'resources', 'samples']
                and self.gnocchi_is_enabled):
            gnocchi_abort()
        elif kind == 'meters':
            return meters.MetersController(), remainder
        elif kind == 'resources':
            return resources.ResourcesController(), remainder
        elif kind == 'samples':
            return samples.SamplesController(), remainder
        elif kind == 'query':
            return QueryController(
                gnocchi_is_enabled=self.gnocchi_is_enabled,
                aodh_url=self.aodh_url,
            ), remainder
        elif kind == 'alarms' and self.aodh_url:
            aodh_redirect(self.aodh_url)
        elif kind == 'alarms':
            return alarms.AlarmsController(), remainder
        else:
            pecan.abort(404)

    @staticmethod
    def _normalize_aodh_url(url):
        if url.endswith("/"):
            return url[:-1]
        return url
Ejemplo n.º 4
0
class V2Controller(object):
    """Version 2 API controller root."""

    event_types = events.EventTypesController()
    events = events.EventsController()
    capabilities = capabilities.CapabilitiesController()

    def __init__(self):
        self._gnocchi_is_enabled = None
        self._aodh_is_enabled = None
        self._aodh_url = None

    @property
    def gnocchi_is_enabled(self):
        print cfg.CONF.meter_dispatchers  # debug by Tony
        pdb.set_trace()  # debug by Tony
        if self._gnocchi_is_enabled is None:
            if cfg.CONF.api.gnocchi_is_enabled is not None:
                self._gnocchi_is_enabled = cfg.CONF.api.gnocchi_is_enabled

            elif ("gnocchi" not in cfg.CONF.meter_dispatchers
                  or "database" in cfg.CONF.meter_dispatchers):
                self._gnocchi_is_enabled = False
            else:
                try:
                    catalog = keystone_client.get_service_catalog(
                        keystone_client.get_client())
                    catalog.url_for(service_type='metric')
                except exceptions.EndpointNotFound:
                    self._gnocchi_is_enabled = False
                except exceptions.ClientException:
                    LOG.warning(
                        _LW("Can't connect to keystone, assuming "
                            "gnocchi is disabled and retry later"))
                else:
                    self._gnocchi_is_enabled = True
                    LOG.warning(
                        _LW("ceilometer-api started with gnocchi "
                            "enabled. The resources/meters/samples "
                            "URLs are disabled."))
        return self._gnocchi_is_enabled

    @property
    def aodh_url(self):
        if self._aodh_url is None:
            if cfg.CONF.api.aodh_is_enabled is False:
                self._aodh_url = ""
            elif cfg.CONF.api.aodh_url is not None:
                self._aodh_url = self._normalize_aodh_url(
                    cfg.CONF.api.aodh_url)
            else:
                try:
                    catalog = keystone_client.get_service_catalog(
                        keystone_client.get_client())
                    self._aodh_url = self._normalize_aodh_url(
                        catalog.url_for(service_type='alarming'))
                except exceptions.EndpointNotFound:
                    self._aodh_url = ""
                except exceptions.ClientException:
                    LOG.warning(
                        _LW("Can't connect to keystone, assuming aodh "
                            "is disabled and retry later."))
                else:
                    LOG.warning(
                        _LW("ceilometer-api started with aodh "
                            "enabled. Alarms URLs will be redirected "
                            "to aodh endpoint."))
        return self._aodh_url

    @pecan.expose()
    def _lookup(self, kind, *remainder):
        if (kind in ['meters', 'resources', 'samples']
                and self.gnocchi_is_enabled):
            if kind == 'meters' and pecan.request.method == 'POST':
                direct = pecan.request.params.get('direct', '')
                if strutils.bool_from_string(direct):
                    pecan.abort(
                        400,
                        _('direct option cannot be true when '
                          'Gnocchi is enabled.'))
                return meters.MetersController(), remainder
            gnocchi_abort()
        elif kind == 'meters':
            return meters.MetersController(), remainder
        elif kind == 'resources':
            return resources.ResourcesController(), remainder
        elif kind == 'samples':
            return samples.SamplesController(), remainder
        elif kind == 'query':
            return QueryController(
                gnocchi_is_enabled=self.gnocchi_is_enabled,
                aodh_url=self.aodh_url,
            ), remainder
        elif kind == 'alarms' and self.aodh_url:
            aodh_redirect(self.aodh_url)
        else:
            pecan.abort(404)

    @staticmethod
    def _normalize_aodh_url(url):
        if url.endswith("/"):
            return url[:-1]
        return url