(self, instance)
return instance_scope
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 ensure_auth_scope(self, instance):
        """
        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
        """
        instance_scope = None

        custom_tags = instance.get('tags', [])
        if custom_tags is None:
            custom_tags = []
        try:
            instance_scope = self.get_scope_for_instance(instance)
        except KeyError:

            # We're missing a project scope for this instance
            # Let's populate it now
            try:
                if 'auth_scope' in instance:
                    instance_scope = OpenStackProjectScope.from_config(self.init_config, instance, self.proxy_config)
                else:
                    instance_scope = OpenStackUnscoped.from_config(self.init_config, instance, self.proxy_config)

                self.service_check(
                    self.IDENTITY_API_SC,
                    AgentCheck.OK,
                    tags=["server:%s" % self.init_config.get("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?",
                    self.init_config.get("keystone_server_url"),
                )
                self.log.debug("Problem grabbing auth token: %s", e)
                self.service_check(
                    self.IDENTITY_API_SC,
                    AgentCheck.CRITICAL,
                    tags=["keystone_server:%s" % self.init_config.get("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:%s" % self.init_config.get("keystone_server_url")] + custom_tags,
                )
                self.service_check(
                    self.COMPUTE_API_SC,
                    AgentCheck.UNKNOWN,
                    tags=["keystone_server:%s" % self.init_config.get("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:%s" % self.init_config.get("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:%s" % self.init_config.get("keystone_server_url")] + custom_tags,
                )
            else:
                self.set_scope_for_instance(instance, instance_scope)

        return instance_scope
def ensure_auth_scope ( self , instance ) : instance_scope = None custom_tags = instance . get ( 'tags' , [ ] ) if custom_tags is None : custom_tags = [ ] try : instance_scope = self . get_scope_for_instance ( instance ) except KeyError : # We're missing a project scope for this instance # Let's populate it now try : if 'auth_scope' in instance : instance_scope = OpenStackProjectScope . from_config ( self . init_config , instance , self . proxy_config ) else : instance_scope = OpenStackUnscoped . from_config ( self . init_config , instance , self . proxy_config ) self . service_check ( self . IDENTITY_API_SC , AgentCheck . OK , tags = [ "server:%s" % self . init_config . get ( "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?" , self . init_config . get ( "keystone_server_url" ) , ) self . log . debug ( "Problem grabbing auth token: %s" , e ) self . service_check ( self . IDENTITY_API_SC , AgentCheck . CRITICAL , tags = [ "keystone_server:%s" % self . init_config . get ( "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:%s" % self . init_config . get ( "keystone_server_url" ) ] + custom_tags , ) self . service_check ( self . COMPUTE_API_SC , AgentCheck . UNKNOWN , tags = [ "keystone_server:%s" % self . init_config . get ( "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:%s" % self . init_config . get ( "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:%s" % self . init_config . get ( "keystone_server_url" ) ] + custom_tags , ) else : self . set_scope_for_instance ( instance , instance_scope ) return instance_scope