-
Notifications
You must be signed in to change notification settings - Fork 101
/
Copy pathcrossmodel_bundle.py
90 lines (67 loc) · 2.36 KB
/
crossmodel_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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# Copyright 2023 Canonical Ltd.
# Licensed under the Apache V2, see LICENCE file for details.
"""This example:
1. Connects to the current controller
2. Creates two models for consuming and offering
2. Deploys a charm and waits until it reports itself active
3. Creates an offer
4. Lists the offer
5. Deploys a charm and adds relation to the offering url
6. Destroys the units and applications
"""
import asyncio
import time
from logging import getLogger
from pathlib import Path
from juju.controller import Controller
log = getLogger(__name__)
async def main():
controller = Controller()
print("Connecting to controller")
await controller.connect()
try:
print("Creating models")
offering_model = await controller.add_model("test-cmr-1")
consuming_model = await controller.add_model("test-cmr-2")
print("Deploying mysql")
await offering_model.deploy(
"ch:mysql",
application_name="mysql",
series="jammy",
channel="edge",
)
print("Waiting for active")
await offering_model.wait_for_idle(status="active")
print("Adding offer")
await offering_model.create_offer("mysql:db")
print("Deploying bundle")
applications = await consuming_model.deploy(
str("local:" / Path(__file__).absolute().parent / "cmr-bundle")
)
print("Waiting for application to start")
await consuming_model.block_until(
lambda: all(
unit.agent_status == "executing"
for application in applications
for unit in application.units
)
)
print("Exporting bundle")
bundle = await consuming_model.export_bundle()
print(bundle)
time.sleep(10)
print("Remove SAAS")
await consuming_model.remove_saas("mysql")
print("Removing offer")
await offering_model.remove_offer("admin/test-cmr-1.mysql", force=True)
print("Destroying models")
await controller.destroy_model(offering_model.info.uuid)
await controller.destroy_model(consuming_model.info.uuid)
except Exception:
log.exception("Example failed!")
raise
finally:
print("Disconnecting from controller")
await controller.disconnect()
if __name__ == "__main__":
asyncio.run(main())