47eb999b528e5cb281f092b3b2f0458986889af1
[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 import asyncio
10
11 from juju.model import Model
12 from juju import loop
13
14
15 async def on_model_change(delta, old, new, model):
16 print(delta.entity, delta.type, delta.data)
17 print(old)
18 print(new)
19 print(model)
20
21
22 async def watch_model():
23 model = Model()
24 await model.connect_current()
25
26 model.add_observer(on_model_change)
27
28
29 if __name__ == '__main__':
30 # Run loop until the process is manually stopped (watch_model will loop
31 # forever).
32 loop.run(watch_model())