From: Tim Van Steenburgh Date: Tue, 18 Oct 2016 11:57:44 +0000 (-0400) Subject: Move add_relation logic from BundleHandler up into Model X-Git-Tag: 0.1.0~72 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=1dd5b8bb6d597700bd5ae06e00a25f7f7d684797;p=osm%2FN2VC.git Move add_relation logic from BundleHandler up into Model --- diff --git a/juju/model.py b/juju/model.py index 49f07a9..1ed5ecd 100644 --- a/juju/model.py +++ b/juju/model.py @@ -461,7 +461,7 @@ class Model(object): myfunc, entity_type='application', action='add', id_='ubuntu') For more complex filtering conditions, pass a predicate function. It - will called with a delta as it's only argument. If the predicate + will be called with a delta as its only argument. If the predicate function returns True, the callable_ will be called. """ @@ -594,7 +594,16 @@ class Model(object): log.debug( 'Adding relation %s <-> %s', relation1, relation2) - result = await app_facade.AddRelation([relation1, relation2]) + try: + result = await app_facade.AddRelation([relation1, relation2]) + except JujuAPIError as e: + if 'relation already exists' not in e.message: + raise + log.debug( + 'Relation %s <-> %s already exists', relation1, relation2) + # TODO: if relation already exists we should return the + # Relation ModelEntity here + return None def predicate(delta): endpoints = {} @@ -1214,14 +1223,8 @@ class BundleHandler(object): parts = endpoints[i].split(':') parts[0] = self.resolve(parts[0]) endpoints[i] = ':'.join(parts) - try: - await self.app_facade.AddRelation(endpoints) - log.debug('Added relation %s <-> %s', *endpoints) - except JujuAPIError as e: - if 'relation already exists' not in e.message: - raise - log.debug('Relation %s <-> %s already exists', *endpoints) - return None + + return await self.model.add_relation(*endpoints) async def deploy(self, charm, series, application, options, constraints, storage, endpoint_bindings, resources):