-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathdeploy_bundle.py
63 lines (43 loc) · 1.53 KB
/
deploy_bundle.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
51
52
53
54
55
56
57
58
59
60
61
62
63
# Copyright 2023 Canonical Ltd.
# Licensed under the Apache V2, see LICENCE file for details.
"""This example:
1. Connects to the current model
2. Deploy a bundle and waits until it reports itself active
3. Destroys the units and applications
"""
import asyncio
from juju.controller import Controller
async def main():
controller = Controller()
# connect to current controller with current user, per Juju CLI
await controller.connect()
# Deploy charmhub bundle
await deploy_bundle(controller, "juju-qa-bundle-test")
await controller.disconnect()
async def deploy_bundle(controller, url, channel=None):
models = await controller.list_models()
model = await controller.add_model(f"model{len(models) + 1}")
try:
print("Deploying bundle")
applications = await deploy_and_wait_for_bundle(model, url, channel)
print("Successfully deployed!")
print("Removing bundle")
for application in applications:
await application.remove()
finally:
print("Disconnecting from model")
await model.disconnect()
print("Success")
async def deploy_and_wait_for_bundle(model, url, channel=None):
applications = await model.deploy(url, channel=channel)
print("Waiting for active")
await model.block_until(
lambda: all(
unit.workload_status == "active"
for application in applications
for unit in application.units
)
)
return applications
if __name__ == "__main__":
asyncio.run(main())