3 from juju
.controller
import Controller
6 async def main(cloud_name
, credential_name
):
7 controller
= Controller()
9 print('Connecting to controller')
10 # connect to current controller with current user, per Juju CLI
11 await controller
.connect()
14 model
= await controller
.add_model(
16 cloud_name
=cloud_name
,
17 credential_name
=credential_name
)
20 print("Verify model's credential: {}".format(
21 model
.info
.cloud_credential_tag
))
23 # verify we can deploy
24 print('Deploying ubuntu')
25 app
= await model
.deploy('ubuntu-10')
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
))
32 print('Removing ubuntu')
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()
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]))