~hazmat/pyjuju/rapi-rollup

« back to all changes in this revision

Viewing changes to juju/rapi/delta.py

  • Committer: Kapil Thangavelu
  • Date: 2012-12-20 18:38:14 UTC
  • mfrom: (616.2.8 rapi-annotation)
  • Revision ID: kapil@canonical.com-20121220183814-2h8p484hbcl2m4dy
Merged rapi-annotation into rapi-rollup.

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
import logging
8
8
from twisted.internet.defer import inlineCallbacks, returnValue
9
9
 
 
10
from juju.state.annotation import AnnotationManager
10
11
# For unambigious relations deltas/identities.
11
12
from juju.state.topology import InternalTopology
12
13
 
 
14
 
13
15
log = logging.getLogger("juju.rapi.delta")
14
16
 
15
17
 
28
30
            'topology': None}
29
31
        self.streams = []  # protocol instances
30
32
        self.running = False
 
33
        self.annotations = AnnotationManager(context.client)
 
34
        self.annotation_stream = self.annotations.stream()
31
35
 
32
36
    def start(self):
33
37
        if self.running:
54
58
 
55
59
        try:
56
60
            current = (yield self.context.status())['result']
 
61
            self._annotate(
 
62
                current, (yield self.annotation_stream.next()))
 
63
            yield self.annotations.gc()
57
64
        except Exception, e:
58
65
            # The delta pump must go on.
59
66
            log.exception("An error occurred %s" % str(e))
66
73
        delta(copy.deepcopy(self.previous),
67
74
              copy.deepcopy(current),
68
75
              changes.append)
 
76
 
69
77
        self.previous = current
70
78
        self.flush(changes)
71
79
        self._schedule()
88
96
        t.parse(content)
89
97
        returnValue(t)
90
98
 
 
99
    def _annotate(self, status, annotations):
 
100
        for s in status['services']:
 
101
            if s in annotations:
 
102
                status['services'][s].update(annotations[s])
 
103
 
 
104
            for u in status['services'][s].get('units', ()):
 
105
                if u in annotations:
 
106
                    status['services'][s]['units'][u].update(
 
107
                        annotations[u])
 
108
        for m in status['machines']:
 
109
            if m in annotations:
 
110
                status['machines'][m].update(annotations[m])
 
111
 
91
112
    def add(self, p):
92
113
        """Add a stream/protocol
93
114
        """