blob: 1b10ac92352542c3eb5444c1c1a6631fc824c377 [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"""
Adam Israeldcdf82b2017-08-15 15:26:43 -04009from juju.model import Model
10from juju import loop
11
12
13async 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
20async def watch_model():
21 model = Model()
Adam Israelb0943662018-08-02 15:32:00 -040022 # connect to current model with current user, per Juju CLI
Adam Israelc3e6c2e2018-03-01 09:31:50 -050023 await model.connect()
Adam Israeldcdf82b2017-08-15 15:26:43 -040024
25 model.add_observer(on_model_change)
26
27
28if __name__ == '__main__':
29 # Run loop until the process is manually stopped (watch_model will loop
30 # forever).
31 loop.run(watch_model())