~clint-fewbar/pyjuju/repo-from-env

« back to all changes in this revision

Viewing changes to juju/state/relation.py

merge watch-related-units-callbacks [r=hazmat,jimbaker][f=900104]

Not a behavioural change; just splits one dual-purpose callback into two for clarity's sake.

Show diffs side-by-side

added added

removed removed

Lines of Context:
408
408
        returnValue(endpoint_container)
409
409
 
410
410
    @inlineCallbacks
411
 
    def watch_related_units(self, callback):
 
411
    def watch_related_units(self, cb_members, cb_settings):
412
412
        """Register a callback to be invoked when related units change.
413
413
 
414
414
        @param: callback a function that gets invoked when related
443
443
            watcher_factory = PeerUnitWatcher
444
444
 
445
445
        watcher = watcher_factory(
446
 
            self._client, self, endpoint_container, callback)
 
446
            self._client, self, endpoint_container, cb_members, cb_settings)
447
447
        returnValue(watcher)
448
448
 
449
449
 
474
474
                 client,
475
475
                 watcher_unit,
476
476
                 unit_container_path,
477
 
                 callback):
 
477
                 cb_members,
 
478
                 cb_settings):
478
479
        super(RelationUnitWatcherBase, self).__init__(client)
479
480
        self._units = []
480
481
        self._watcher_unit = watcher_unit
481
482
        self._container_path = unit_container_path
482
 
        self._callback = callback
 
483
        self._cb_members = cb_members
 
484
        self._cb_settings = cb_settings
483
485
        self._stopped = None
484
486
        self._unit_name_map = None
485
487
        self._log = logging.getLogger("unit.relation.watch")
610
612
        # Invoke callback
611
613
        callback_d.addCallback(
612
614
            lambda (old_units, new_units): maybeDeferred(
613
 
                self._callback,
614
 
                old_units=sorted(old_units),
615
 
                new_units=sorted(new_units)))
 
615
                self._cb_members, sorted(old_units), sorted(new_units)))
616
616
 
617
617
        # Attach initial notifiers and change handlers to new nodes
618
618
        if settings_watches:
635
635
            return
636
636
        ((unit_name,),) = yield self._resolve_unit_names([unit_id])
637
637
        node_info = (unit_name, stat["version"])
638
 
        yield self._callback(modified=(node_info,))
 
638
        yield self._cb_settings((node_info,))
639
639
 
640
640
    def _watch_settings_for_units(self, added):
641
641
        """Setup watches on new unit relation setting nodes.