c52de60ab715ce5382b6a94abb230af9f8f755af
[osm/N2VC.git] / examples / leadership.py
1 """
2 This example:
3
4 1. Connects to the current model.
5 2. Prints out leadership status for all deployed units in the model.
6 3. Cleanly disconnects.
7
8 """
9 import asyncio
10
11 from juju.model import Model
12
13 async def report_leadership():
14 model = Model()
15 await model.connect_current()
16
17 print("Leadership: ")
18 for app in model.applications.values():
19 for unit in app.units:
20 print("{}: {}".format(
21 unit.name, await unit.is_leader_from_status()))
22
23 await model.disconnect()
24
25 loop = asyncio.get_event_loop()
26 loop.run_until_complete(report_leadership())