Add Juju Public Key
[osm/N2VC.git] / modules / libjuju / examples / livemodel.py
1 """
2 This example:
3
4 1. Connects to the current model
5 2. Watches the model and prints all changes
6 3. Runs forever (kill with Ctrl-C)
7
8 """
9 from juju.model import Model
10 from juju import loop
11
12
13 async def on_model_change(delta, old, new, model):
14 print(delta.entity, delta.type, delta.data)
15 print(old)
16 print(new)
17 print(model)
18
19
20 async def watch_model():
21 model = Model()
22 # connect to current model with current user, per Juju CLI
23 await model.connect()
24
25 model.add_observer(on_model_change)
26
27
28 if __name__ == '__main__':
29 # Run loop until the process is manually stopped (watch_model will loop
30 # forever).
31 loop.run(watch_model())