| 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') |
| Adam Israel | b094366 | 2018-08-02 15:32:00 -0400 | [diff] [blame] | 16 | # connect to current model with current user, per Juju CLI |
| Adam Israel | c3e6c2e | 2018-03-01 09:31:50 -0500 | [diff] [blame] | 17 | await model.connect() |
| Adam Israel | dcdf82b | 2017-08-15 15:26:43 -0400 | [diff] [blame] | 18 | |
| 19 | try: |
| 20 | print('Deploying ubuntu') |
| 21 | application = await model.deploy( |
| 22 | 'ubuntu-10', |
| 23 | application_name='ubuntu', |
| 24 | series='trusty', |
| 25 | channel='stable', |
| 26 | ) |
| 27 | |
| 28 | print('Waiting for active') |
| 29 | await model.block_until( |
| 30 | lambda: all(unit.workload_status == 'active' |
| 31 | for unit in application.units)) |
| 32 | |
| 33 | print('Removing ubuntu') |
| 34 | await application.remove() |
| 35 | finally: |
| 36 | print('Disconnecting from model') |
| 37 | await model.disconnect() |
| 38 | |
| 39 | |
| 40 | if __name__ == '__main__': |
| 41 | loop.run(main()) |