Update exceptions
[osm/N2VC.git] / modules / libjuju / examples / credential.py
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 # connect to current controller with current user, per Juju CLI
11 await controller.connect()
12 try:
13 print('Adding model')
14 model = await controller.add_model(
15 'test',
16 cloud_name=cloud_name,
17 credential_name=credential_name)
18
19 # verify credential
20 print("Verify model's credential: {}".format(
21 model.info.cloud_credential_tag))
22
23 # verify we can deploy
24 print('Deploying ubuntu')
25 app = await model.deploy('ubuntu-10')
26
27 print('Waiting for active')
28 await model.block_until(
29 lambda: app.units and all(unit.workload_status == 'active'
30 for unit in app.units))
31
32 print('Removing ubuntu')
33 await app.remove()
34 finally:
35 print('Cleaning up')
36 if model:
37 print('Removing model')
38 model_uuid = model.info.uuid
39 await model.disconnect()
40 await controller.destroy_model(model_uuid)
41 print('Disconnecting')
42 await controller.disconnect()
43
44
45 if __name__ == '__main__':
46 assert len(sys.argv) > 2, 'Please provide a cloud and credential name'
47 loop.run(main(sys.argv[1], sys.argv[2]))