blob: a15e9f7701f9ba7234784608ea09ebf2f3038f87 [file] [log] [blame]
Adam Israeldcdf82b2017-08-15 15:26:43 -04001"""
2This example:
3
41. Connects to the current model
52. Watches the model and prints all changes
63. Runs forever (kill with Ctrl-C)
7
8"""
9import asyncio
10
11from juju.model import Model
12from juju import loop
13
14
15async 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
22async def watch_model():
23 model = Model()
Adam Israelc3e6c2e2018-03-01 09:31:50 -050024 await model.connect()
Adam Israeldcdf82b2017-08-15 15:26:43 -040025
26 model.add_observer(on_model_change)
27
28
29if __name__ == '__main__':
30 # Run loop until the process is manually stopped (watch_model will loop
31 # forever).
32 loop.run(watch_model())