X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FN2VC.git;a=blobdiff_plain;f=modules%2Flibjuju%2Fjuju%2Fapplication.py;h=555bb3d0b4878049b080d5f9af2aadc9784a66cb;hp=620e9c998aff2f4c174a41a6fd29df2f4dd6d053;hb=c3e6c2ec9a1fddfc8e9bd31509b366e633b6d99e;hpb=1a15d1c84fc826fa7996c1c9d221a324edd33432 diff --git a/modules/libjuju/juju/application.py b/modules/libjuju/juju/application.py index 620e9c9..555bb3d 100644 --- a/modules/libjuju/juju/application.py +++ b/modules/libjuju/juju/application.py @@ -51,6 +51,24 @@ class Application(model.ModelEntity): if unit.application == self.name ] + @property + def relations(self): + return [rel for rel in self.model.relations if rel.matches(self.name)] + + def related_applications(self, endpoint_name=None): + apps = {} + for rel in self.relations: + if rel.is_peer: + local_ep, remote_ep = rel.endpoints[0] + else: + def is_us(ep): + return ep.application.name == self.name + local_ep, remote_ep = sorted(rel.endpoints, key=is_us) + if endpoint_name is not None and endpoint_name != local_ep.name: + continue + apps[remote_ep.application.name] = remote_ep.application + return apps + @property def status(self): """Get the application status, as set by the charm's leader.