7f184c37676525fca33d543102dc26092f95f321
[osm/N2VC.git] / 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
13
14 async def on_model_change(delta, old, new, model):
15 print(delta.entity, delta.type, delta.data)
16 print(old)
17 print(new)
18 print(model)
19
20
21 async def watch_model():
22 model = Model()
23 await model.connect_current()
24
25 model.add_observer(on_model_change)
26
27
28 loop = asyncio.get_event_loop()
29 loop.create_task(watch_model())
30 loop.run_forever()