~corey.bryant/+junk/charm-composing

« back to all changes in this revision

Viewing changes to interfaces/rabbitmq/provides.py

  • Committer: Liam Young
  • Date: 2015-11-18 13:31:55 UTC
  • Revision ID: liam.young@canonical.com-20151118133155-rr9n29fhvu7ubkg0
Initial cut

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
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
 
5
#
 
6
#     http://www.apache.org/licenses/LICENSE-2.0
 
7
#
 
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.
 
13
 
 
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
 
18
 
 
19
 
 
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
 
25
 
 
26
    @hook('amqp-relation-joined')
 
27
    def joined(self):
 
28
        conversation = self.conversation()
 
29
        conversation.set_state('{relation_name}.amqp.requested')
 
30
 
 
31
    @hook('amqp-relation-{broken,departed}')
 
32
    def departed(self):
 
33
        conversation = self.conversation()
 
34
 
 
35
        # if these were requested but not yet fulfilled, cancel the request
 
36
        conversation.remove_state('{relation_name}.amqp.requested')