projects
/
osm
/
N2VC.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Bump VERSION and changelog for release
[osm/N2VC.git]
/
examples
/
livemodel.py
diff --git
a/examples/livemodel.py
b/examples/livemodel.py
index
2330a58
..
47eb999
100644
(file)
--- a/
examples/livemodel.py
+++ b/
examples/livemodel.py
@@
-1,22
+1,32
@@
-import asyncio
+"""
+This example:
-from juju.model import Model
-from juju.client.connection import Connection
+1. Connects to the current model
+2. Watches the model and prints all changes
+3. Runs forever (kill with Ctrl-C)
+"""
+import asyncio
-loop = asyncio.get_event_loop()
-conn = loop.run_until_complete(Connection.connect_current())
+from juju.model import Model
+from juju import loop
-def on_model_change(delta, old, new, model):
+
async
def on_model_change(delta, old, new, model):
print(delta.entity, delta.type, delta.data)
print(old)
print(new)
print(model)
print(delta.entity, delta.type, delta.data)
print(old)
print(new)
print(model)
+
async def watch_model():
async def watch_model():
- model = Model(conn)
+ model = Model()
+ await model.connect_current()
+
model.add_observer(on_model_change)
model.add_observer(on_model_change)
- await model.watch()
-loop.run_until_complete(watch_model())
+
+if __name__ == '__main__':
+ # Run loop until the process is manually stopped (watch_model will loop
+ # forever).
+ loop.run(watch_model())