c78d689fe9d18588791bbfb8cf15b4f8e5617aa0
[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 client
15 from juju import loop
16
17
18 async def watch():
19 conn = await Connection.connect_current()
20 allwatcher = client.AllWatcherFacade.from_connection(conn)
21 while True:
22 change = await allwatcher.Next()
23 for delta in change.deltas:
24 print(delta.deltas)
25
26
27 if __name__ == '__main__':
28 logging.basicConfig(level=logging.DEBUG)
29 # Run loop until the process is manually stopped (watch will loop
30 # forever).
31 loop.run(watch())