| 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. Deploy a charm and waits until it reports itself active |
| 6 | 3. Destroys the unit and application |
| 7 | |
| 8 | """ |
| 9 | from juju import loop |
| 10 | from juju.model import Model |
| 11 | |
| 12 | |
| 13 | async def main(): |
| 14 | model = Model() |
| 15 | print('Connecting to model') |
| 16 | await model.connect_current() |
| 17 | |
| 18 | try: |
| 19 | print('Deploying ubuntu') |
| 20 | application = await model.deploy( |
| 21 | 'ubuntu-10', |
| 22 | application_name='ubuntu', |
| 23 | series='trusty', |
| 24 | channel='stable', |
| 25 | ) |
| 26 | |
| 27 | print('Waiting for active') |
| 28 | await model.block_until( |
| 29 | lambda: all(unit.workload_status == 'active' |
| 30 | for unit in application.units)) |
| 31 | |
| 32 | print('Removing ubuntu') |
| 33 | await application.remove() |
| 34 | finally: |
| 35 | print('Disconnecting from model') |
| 36 | await model.disconnect() |
| 37 | |
| 38 | |
| 39 | if __name__ == '__main__': |
| 40 | loop.run(main()) |