-
Notifications
You must be signed in to change notification settings - Fork 93
/
deploy_local_file_resource.py
51 lines (41 loc) · 1.28 KB
/
deploy_local_file_resource.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
# 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 local charm with a oci-image resource and waits until it reports
itself active
3. Destroys the unit and application
"""
from juju import jasyncio
from juju.model import Model
from pathlib import Path
async def main():
model = Model()
print('Connecting to model')
# connect to current model with current user, per Juju CLI
await model.connect()
application = None
try:
print('Deploying local-charm')
base_dir = Path(__file__).absolute().parent.parent
charm_path = '{}/tests/integration/file-resource-charm'.format(base_dir)
resources = {"file-res": "test.file"}
application = await model.deploy(
charm_path,
resources=resources,
)
print('Waiting for active')
await model.wait_for_idle()
print('Removing Charm')
await application.remove()
except Exception as e:
print(e)
if application:
await application.remove()
await model.disconnect()
finally:
print('Disconnecting from model')
await model.disconnect()
if __name__ == '__main__':
jasyncio.run(main())