projects
/
osm
/
N2VC.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Docs are build automatically by RTD, so remove from `make release`
[osm/N2VC.git]
/
examples
/
allwatcher.py
diff --git
a/examples/allwatcher.py
b/examples/allwatcher.py
index
6c549b4
..
c78d689
100644
(file)
--- a/
examples/allwatcher.py
+++ b/
examples/allwatcher.py
@@
-1,19
+1,31
@@
-import asyncio
+"""
+This example:
-from juju.client.connection import Connection
-from juju.client import watcher
+1. Connects to the current model
+2. Starts an AllWatcher
+3. Prints all changes received from the AllWatcher
+4. Runs forever (kill with Ctrl-C)
+"""
+import asyncio
+import logging
-loop = asyncio.get_event_loop()
-conn = loop.run_until_complete(Connection.connect_current())
+from juju.client.connection import Connection
+from juju.client import client
+from juju import loop
async def watch():
async def watch():
-
allwatcher = watcher.AllWatcher
()
- allwatcher
.connect
(conn)
+
conn = await Connection.connect_current
()
+ allwatcher
= client.AllWatcherFacade.from_connection
(conn)
while True:
change = await allwatcher.Next()
for delta in change.deltas:
print(delta.deltas)
while True:
change = await allwatcher.Next()
for delta in change.deltas:
print(delta.deltas)
-loop.run_until_complete(watch())
+
+if __name__ == '__main__':
+ logging.basicConfig(level=logging.DEBUG)
+ # Run loop until the process is manually stopped (watch will loop
+ # forever).
+ loop.run(watch())