-
Notifications
You must be signed in to change notification settings - Fork 93
/
credential.py
50 lines (41 loc) · 1.5 KB
/
credential.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# Copyright 2023 Canonical Ltd.
# Licensed under the Apache V2, see LICENCE file for details.
import sys
from juju import jasyncio
from juju.controller import Controller
async def main(cloud_name, credential_name):
controller = Controller()
model = None
print('Connecting to controller')
# connect to current controller with current user, per Juju CLI
await controller.connect()
try:
print('Adding model')
model = await controller.add_model(
'test',
cloud_name=cloud_name,
credential_name=credential_name)
# verify credential
print("Verify model's credential: {}".format(
model.info.cloud_credential_tag))
# verify we can deploy
print('Deploying ubuntu')
app = await model.deploy('ch:ubuntu')
print('Waiting for active')
await model.block_until(
lambda: app.units and all(unit.workload_status == 'active'
for unit in app.units))
print('Removing ubuntu')
await app.remove()
finally:
print('Cleaning up')
if model:
print('Removing model')
model_uuid = model.info.uuid
await model.disconnect()
await controller.destroy_model(model_uuid)
print('Disconnecting')
await controller.disconnect()
if __name__ == '__main__':
assert len(sys.argv) > 2, 'Please provide a cloud and credential name'
jasyncio.run(main(sys.argv[1], sys.argv[2]))