c215d20cb33ef66ac21e8ec63bf577428930c0ae
[osm/N2VC.git] / examples / allwatcher.py
1 """
2 This example:
3
4 1. Connects to the current model
5 2. Starts an AllWatcher
6 3. Prints all changes received from the AllWatcher
7 4. Runs forever (kill with Ctrl-C)
8
9 """
10 import asyncio
11 import logging
12
13 from juju.client.connection import Connection
14 from juju.client import watcher
15 from juju import loop
16
17
18 async def watch():
19 allwatcher = watcher.AllWatcher()
20 conn = await Connection.connect_current()
21 allwatcher.connect(conn)
22 while True:
23 change = await allwatcher.Next()
24 for delta in change.deltas:
25 print(delta.deltas)
26
27
28 if __name__ == '__main__':
29 logging.basicConfig(level=logging.DEBUG)
30 # Run loop until the process is manually stopped (watch will loop
31 # forever).
32 loop.run(watch())