| Adam Israel | 1a15d1c | 2017-10-23 12:00:49 -0400 | [diff] [blame^] | 1 | import sys |
| 2 | from juju import loop |
| 3 | from juju.controller import Controller |
| 4 | |
| 5 | |
| 6 | async def main(cloud_name, credential_name): |
| 7 | controller = Controller() |
| 8 | model = None |
| 9 | print('Connecting to controller') |
| 10 | await controller.connect_current() |
| 11 | try: |
| 12 | print('Adding model') |
| 13 | model = await controller.add_model( |
| 14 | 'test', |
| 15 | cloud_name=cloud_name, |
| 16 | credential_name=credential_name) |
| 17 | |
| 18 | # verify credential |
| 19 | print("Verify model's credential: {}".format( |
| 20 | model.info.cloud_credential_tag)) |
| 21 | |
| 22 | # verify we can deploy |
| 23 | print('Deploying ubuntu') |
| 24 | app = await model.deploy('ubuntu-10') |
| 25 | |
| 26 | print('Waiting for active') |
| 27 | await model.block_until( |
| 28 | lambda: app.units and all(unit.workload_status == 'active' |
| 29 | for unit in app.units)) |
| 30 | |
| 31 | print('Removing ubuntu') |
| 32 | await app.remove() |
| 33 | finally: |
| 34 | print('Cleaning up') |
| 35 | if model: |
| 36 | print('Removing model') |
| 37 | model_uuid = model.info.uuid |
| 38 | await model.disconnect() |
| 39 | await controller.destroy_model(model_uuid) |
| 40 | print('Disconnecting') |
| 41 | await controller.disconnect() |
| 42 | |
| 43 | |
| 44 | if __name__ == '__main__': |
| 45 | assert len(sys.argv) > 2, 'Please provide a cloud and credential name' |
| 46 | loop.run(main(sys.argv[1], sys.argv[2])) |