Example #1
0
    def joined_changed(self):
        """
        Handles the relation-joined and relation-changed hook.

        Depending on the state of the conversation, this can trigger one
        of the following states:

        * ``{relation_name}.database.requested`` This state will be activated if
          the remote service has requested a different database name than the
          one it has been provided.  This state should be resolved by calling
          :meth:`provide_database`.  See also :meth:`requested_databases`.

        * ``{relation_name}.roles.requested`` This state will be activated if
          the remote service has requested a specific set of roles for its user.
          This state should be resolved by calling :meth:`ack_roles`.  See also
          :meth:`requrested_roles`.
        """
        service = hookenv.remote_service()
        conversation = self.conversation()

        if self.previous_database(service) != self.requested_database(service):
            conversation.set_state('{relation_name}.database.requested')

        if self.previous_roles(service) != self.requested_roles(service):
            conversation.set_state('{relation_name}.roles.requested')
    def joined_changed(self):
        """
        Handles the relation-joined and relation-changed hook.

        Depending on the state of the conversation, this can trigger one
        of the following states:

        * ``{relation_name}.database.requested`` This state will be activated if
          the remote service has requested a different database name than the
          one it has been provided.  This state should be resolved by calling
          :meth:`provide_database`.  See also :meth:`requested_databases`.

        * ``{relation_name}.roles.requested`` This state will be activated if
          the remote service has requested a specific set of roles for its user.
          This state should be resolved by calling :meth:`ack_roles`.  See also
          :meth:`requrested_roles`.
        """
        service = hookenv.remote_service()
        conversation = self.conversation()

        if self.previous_database(service) != self.requested_database(service):
            conversation.set_state('{relation_name}.database.requested')

        if self.previous_roles(service) != self.requested_roles(service):
            conversation.set_state('{relation_name}.roles.requested')
Example #3
0
    def conversation(self, scope=None):
        """
        Get a single conversation, by scope, that this relation is currently handling.

        If the scope is not given, the correct scope is inferred by the current
        hook execution context.  If there is no current hook execution context, it
        is assume that there is only a single global conversation scope for this
        relation.  If this relation's scope is not global and there is no current
        hook execution context, then an error is raised.
        """
        if scope is None:
            if self.scope is scopes.UNIT:
                scope = hookenv.remote_unit()
            elif self.scope is scopes.SERVICE:
                scope = hookenv.remote_service()
            else:
                scope = self.scope
        if scope is None:
            raise ValueError(
                'Unable to determine default scope: no current hook or global scope'
            )
        for conversation in self._conversations:
            if conversation.scope == scope:
                return conversation
        else:
            raise ValueError("Conversation with scope '%s' not found" % scope)
    def conversation(self, scope=None):
        """
        Get a single conversation, by scope, that this relation is currently handling.

        If the scope is not given, the correct scope is inferred by the current
        hook execution context.  If there is no current hook execution context, it
        is assume that there is only a single global conversation scope for this
        relation.  If this relation's scope is not global and there is no current
        hook execution context, then an error is raised.
        """
        if scope is None:
            if self.scope is scopes.UNIT:
                scope = hookenv.remote_unit()
            elif self.scope is scopes.SERVICE:
                scope = hookenv.remote_service()
            else:
                scope = self.scope
        if scope is None:
            raise ValueError('Unable to determine default scope: no current hook or global scope')
        for conversation in self._conversations:
            if conversation.scope == scope:
                return conversation
        else:
            raise ValueError("Conversation with scope '%s' not found" % scope)