(self, instance_config, keystone_server_url, custom_tags)
Guarantees a valid auth scope for this instance, and returns it

        Communicates with the identity server and initializes a new scope when one is absent, or has been forcibly
        removed due to token expiry
Guarantees a valid auth scope for this instance, and returns it
Guarantees a valid auth scope for this instance and returns it
def init_api(self, instance_config, keystone_server_url, custom_tags):
        """
        Guarantees a valid auth scope for this instance, and returns it

        Communicates with the identity server and initializes a new scope when one is absent, or has been forcibly
        removed due to token expiry
        """
        custom_tags = custom_tags or []

        if self._api is None:
            # We are missing the entire instance scope either because it is the first time we initialize it or because
            # authentication previously failed and got removed from the cache
            # Let's populate it now
            try:
                self.log.debug("Fetch scope for instance %s", self.instance_name)
                # Set keystone api with proper token
                self._api = ApiFactory.create(self.log, instance_config, self.http)
                self.service_check(
                    self.IDENTITY_API_SC,
                    AgentCheck.OK,
                    tags=["keystone_server: {}".format(keystone_server_url)] + custom_tags,
                )
            except KeystoneUnreachable as e:
                self.warning(
                    "The agent could not contact the specified identity server at `%s`. "
                    "Are you sure it is up at that address?",
                    keystone_server_url,
                )
                self.log.debug("Problem grabbing auth token: %s", e)
                self.service_check(
                    self.IDENTITY_API_SC,
                    AgentCheck.CRITICAL,
                    tags=["keystone_server: {}".format(keystone_server_url)] + custom_tags,
                )

                # If Keystone is down/unreachable, we default the
                # Nova and Neutron APIs to UNKNOWN since we cannot access the service catalog
                self.service_check(
                    self.NETWORK_API_SC,
                    AgentCheck.UNKNOWN,
                    tags=["keystone_server: {}".format(keystone_server_url)] + custom_tags,
                )
                self.service_check(
                    self.COMPUTE_API_SC,
                    AgentCheck.UNKNOWN,
                    tags=["keystone_server: {}".format(keystone_server_url)] + custom_tags,
                )

            except MissingNovaEndpoint as e:
                self.warning("The agent could not find a compatible Nova endpoint in your service catalog!")
                self.log.debug("Failed to get nova endpoint for response catalog: %s", e)
                self.service_check(
                    self.COMPUTE_API_SC,
                    AgentCheck.CRITICAL,
                    tags=["keystone_server: {}".format(keystone_server_url)] + custom_tags,
                )

            except MissingNeutronEndpoint:
                self.warning("The agent could not find a compatible Neutron endpoint in your service catalog!")
                self.service_check(
                    self.NETWORK_API_SC,
                    AgentCheck.CRITICAL,
                    tags=["keystone_server: {}".format(keystone_server_url)] + custom_tags,
                )

        if self._api is None:
            # Fast fail in the absence of an api
            raise IncompleteConfig("Could not initialise Openstack API")
def init_api ( self , instance_config , keystone_server_url , custom_tags ) : custom_tags = custom_tags or [ ] if self . _api is None : # We are missing the entire instance scope either because it is the first time we initialize it or because # authentication previously failed and got removed from the cache # Let's populate it now try : self . log . debug ( "Fetch scope for instance %s" , self . instance_name ) # Set keystone api with proper token self . _api = ApiFactory . create ( self . log , instance_config , self . http ) self . service_check ( self . IDENTITY_API_SC , AgentCheck . OK , tags = [ "keystone_server: {}" . format ( keystone_server_url ) ] + custom_tags , ) except KeystoneUnreachable as e : self . warning ( "The agent could not contact the specified identity server at `%s`. " "Are you sure it is up at that address?" , keystone_server_url , ) self . log . debug ( "Problem grabbing auth token: %s" , e ) self . service_check ( self . IDENTITY_API_SC , AgentCheck . CRITICAL , tags = [ "keystone_server: {}" . format ( keystone_server_url ) ] + custom_tags , ) # If Keystone is down/unreachable, we default the # Nova and Neutron APIs to UNKNOWN since we cannot access the service catalog self . service_check ( self . NETWORK_API_SC , AgentCheck . UNKNOWN , tags = [ "keystone_server: {}" . format ( keystone_server_url ) ] + custom_tags , ) self . service_check ( self . COMPUTE_API_SC , AgentCheck . UNKNOWN , tags = [ "keystone_server: {}" . format ( keystone_server_url ) ] + custom_tags , ) except MissingNovaEndpoint as e : self . warning ( "The agent could not find a compatible Nova endpoint in your service catalog!" ) self . log . debug ( "Failed to get nova endpoint for response catalog: %s" , e ) self . service_check ( self . COMPUTE_API_SC , AgentCheck . CRITICAL , tags = [ "keystone_server: {}" . format ( keystone_server_url ) ] + custom_tags , ) except MissingNeutronEndpoint : self . warning ( "The agent could not find a compatible Neutron endpoint in your service catalog!" ) self . service_check ( self . NETWORK_API_SC , AgentCheck . CRITICAL , tags = [ "keystone_server: {}" . format ( keystone_server_url ) ] + custom_tags , ) if self . _api is None : # Fast fail in the absence of an api raise IncompleteConfig ( "Could not initialise Openstack API" )