X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FN2VC.git;a=blobdiff_plain;f=modules%2Flibjuju%2Fexamples%2Flivemodel.py;fp=modules%2Flibjuju%2Fexamples%2Flivemodel.py;h=47eb999b528e5cb281f092b3b2f0458986889af1;hp=0000000000000000000000000000000000000000;hb=68858c1915122c2dbc8999a5cd3229694abf5f3a;hpb=032a71b2a6692b8b4e30f629a1f906d246f06736 diff --git a/modules/libjuju/examples/livemodel.py b/modules/libjuju/examples/livemodel.py new file mode 100644 index 0000000..47eb999 --- /dev/null +++ b/modules/libjuju/examples/livemodel.py @@ -0,0 +1,32 @@ +""" +This example: + +1. Connects to the current model +2. Watches the model and prints all changes +3. Runs forever (kill with Ctrl-C) + +""" +import asyncio + +from juju.model import Model +from juju import loop + + +async def on_model_change(delta, old, new, model): + print(delta.entity, delta.type, delta.data) + print(old) + print(new) + print(model) + + +async def watch_model(): + model = Model() + await model.connect_current() + + model.add_observer(on_model_change) + + +if __name__ == '__main__': + # Run loop until the process is manually stopped (watch_model will loop + # forever). + loop.run(watch_model())