~andrewsmedina/pyjuju/ec2-ipv4

« back to all changes in this revision

Viewing changes to juju/state/relation.py

  • Committer: Jim Baker
  • Date: 2012-03-30 17:44:08 UTC
  • mfrom: (485.1.15 relation-id)
  • Revision ID: jim.baker@canonical.com-20120330174408-n9khvorp0r4rp36l
merge relation-id [r=hazmat][f=963640]

Implments relation id support (code calls this relation ident) to
unambiguously refer to relations.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
        atomically.
29
29
        """
30
30
 
31
 
        # the TOODs in the following comments in this function are for
 
31
        # the TODOs in the following comments in this function are for
32
32
        # type checking to be implemented ASAP. However, this will
33
33
        # require some nontrivial test modification, so it's best to
34
34
        # be done in a future branch. This is because these tests use
224
224
    def internal_relation_id(self):
225
225
        return self._relation_id
226
226
 
 
227
    @staticmethod
 
228
    def get_relation_ident(relation_name, internal_relation_id):
 
229
        """Returns <relation name>:<normalized internal relation id>"""
 
230
 
 
231
        # NOTE: ideally this function would not be directly exposed,
 
232
        # however, UnitRelationLifecycle currently uses internal
 
233
        # relation ids, and needs to reconstruct the workflow, which
 
234
        # requires an external relation id, from a file when a
 
235
        # relation has departed.
 
236
 
 
237
        # normalize internal ids like 'relation-0000000042' to '42'
 
238
        digits = internal_relation_id.split('-')[1]
 
239
        normalized = digits.lstrip("0")
 
240
        if not normalized:
 
241
            normalized = '0'
 
242
        return "%s:%s" % (relation_name, normalized)
 
243
 
 
244
    @property
 
245
    def relation_ident(self):
 
246
        """Returns <relation name>:<normalized internal relation id>"""
 
247
        return self.get_relation_ident(
 
248
            self.relation_name, self.internal_relation_id)
 
249
 
227
250
    @property
228
251
    def internal_service_id(self):
229
252
        return self._service_id
327
350
                unit_map = yaml.load(content)
328
351
            else:
329
352
                unit_map = {}
330
 
            # If its already present, we're done, just return the
 
353
            # If it's already present, we're done, just return the
331
354
            # existing content, to avoid unstable yaml dict
332
355
            # serialization.
333
356
            if unit_state.internal_id in unit_map: