X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=juju%2Fmodel.py;h=1ed5ecd3996b2441c804e0c8fcb87920e5078ac4;hb=1dd5b8bb6d597700bd5ae06e00a25f7f7d684797;hp=49f07a9d818c1e3ebf494fd0a74dbe9e337753d9;hpb=7fdf96510e9aa6960d6c956a7178585cb65caefe;p=osm%2FN2VC.git 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):