| Adam Israel | dcdf82b | 2017-08-15 15:26:43 -0400 | [diff] [blame] | 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 | from juju import loop |
| 13 | |
| 14 | async def report_leadership(): |
| 15 | model = Model() |
| Adam Israel | c3e6c2e | 2018-03-01 09:31:50 -0500 | [diff] [blame] | 16 | await model.connect() |
| Adam Israel | dcdf82b | 2017-08-15 15:26:43 -0400 | [diff] [blame] | 17 | |
| 18 | print("Leadership: ") |
| 19 | for app in model.applications.values(): |
| 20 | for unit in app.units: |
| 21 | print("{}: {}".format( |
| 22 | unit.name, await unit.is_leader_from_status())) |
| 23 | |
| 24 | await model.disconnect() |
| 25 | |
| 26 | |
| 27 | if __name__ == '__main__': |
| 28 | loop.run(report_leadership()) |