X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=juju%2Fapplication.py;h=1e87ced2e26ea1ab24de5badfb63f011c0b9a803;hb=1dd5b8bb6d597700bd5ae06e00a25f7f7d684797;hp=978500fa321ec445a9c686f7da4a3e9630d31277;hpb=2ed7314a9ea1240883655bc521b6e27f149aa485;p=osm%2FN2VC.git diff --git a/juju/application.py b/juju/application.py index 978500f..1e87ced 100644 --- a/juju/application.py +++ b/juju/application.py @@ -7,6 +7,26 @@ log = logging.getLogger(__name__) class Application(model.ModelEntity): + @property + def _unit_match_pattern(self): + return r'^{}.*$'.format(self.entity_id) + + def on_unit_add(self, callable_): + """Add a "unit added" observer to this entity, which will be called + whenever a unit is added to this application. + + """ + self.model.add_observer( + callable_, 'unit', 'add', self._unit_match_pattern) + + def on_unit_remove(self, callable_): + """Add a "unit removed" observer to this entity, which will be called + whenever a unit is removed from this application. + + """ + self.model.add_observer( + callable_, 'unit', 'remove', self._unit_match_pattern) + @property def units(self): return [