2
# Licensed under the Apache License, Version 2.0 (the "License");
3
# you may not use this file except in compliance with the License.
4
# You may obtain a copy of the License at
6
# http://www.apache.org/licenses/LICENSE-2.0
8
# Unless required by applicable law or agreed to in writing, software
9
# distributed under the License is distributed on an "AS IS" BASIS,
10
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
# See the License for the specific language governing permissions and
12
# limitations under the License.
14
from charms.reactive import RelationBase
15
from charms.reactive import scopes
16
from charms.reactive import hook
17
from charms.reactive import not_unless
20
class RabbitMQ(RelationBase):
21
# We expect multiple, separate services to be related, but all units of a
22
# given service will share the same database name and connection info.
23
# Thus, we use SERVICE scope and will have one converstaion per service.
24
scope = scopes.SERVICE
26
@hook('amqp-relation-joined')
28
conversation = self.conversation()
29
conversation.set_state('{relation_name}.amqp.requested')
31
@hook('amqp-relation-{broken,departed}')
33
conversation = self.conversation()
35
# if these were requested but not yet fulfilled, cancel the request
36
conversation.remove_state('{relation_name}.amqp.requested')