Skip to content

Commit ef05ad8

Browse files
authored
Merge pull request #483 from SimonRichardson/charmhub-deploy-charm
#483 This PR allows the deploying of charmhub charms and bundles. There are a few gaps in this PR and those will be filled in future PRs. 1. resources (oci-images, local, etc) 2. refresh/upgrade-charm 3. k8s testing The replicates as much as the juju go CLI. Although there are gaps in how we deal with series as we currently don't have as much information as the go CLI, but that is coming. ## Q&A Steps Run the examples for bundles and try and deploy a charmhub charm.
2 parents eed19e4 + 98bef78 commit ef05ad8

14 files changed

Lines changed: 613 additions & 125 deletions

File tree

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ client:
2020
$(PY) -m juju.client.facade -s "juju/client/schemas*" -o juju/client/
2121

2222
.PHONY: test
23-
test:
24-
tox
23+
test: lint
24+
tox -e py3
25+
tox -e integration
26+
2527

2628
.PHONY: lint
2729
lint:

examples/deploy_bundle.py

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,33 @@
66
3. Destroys the units and applications
77
88
"""
9+
from juju.controller import Controller
910
from juju import loop
10-
from juju.model import Model
1111

1212

1313
async def main():
14-
model = Model()
15-
print('Connecting to model')
16-
# Connect to current model with current user, per Juju CLI
17-
await model.connect()
14+
controller = Controller()
15+
# connect to current controller with current user, per Juju CLI
16+
await controller.connect()
17+
18+
# Deploy charmhub bundle
19+
await deploy_bundle(controller, 'juju-qa-bundle-test')
20+
21+
# Deploy legacy bundle
22+
await deploy_bundle(controller, 'cs:~juju-qa/bundle/basic-0', 'beta')
23+
24+
await controller.disconnect()
25+
26+
27+
async def deploy_bundle(controller, url, channel=None):
28+
models = await controller.list_models()
29+
model = await controller.add_model('model{}'.format(len(models) + 1))
1830

1931
try:
2032
print('Deploying bundle')
21-
applications = await model.deploy(
22-
'cs:~juju-qa/bundle/basic-0',
23-
channel='beta',
24-
)
25-
26-
print('Waiting for active')
27-
await model.block_until(
28-
lambda: all(unit.workload_status == 'active'
29-
for application in applications for unit in application.units))
33+
34+
applications = await deploy_and_wait_for_bundle(model, url, channel)
35+
3036
print("Successfully deployed!")
3137
print('Removing bundle')
3238
for application in applications:
@@ -37,5 +43,15 @@ async def main():
3743
print("Success")
3844

3945

46+
async def deploy_and_wait_for_bundle(model, url, channel=None):
47+
applications = await model.deploy(url, channel=channel)
48+
49+
print('Waiting for active')
50+
await model.block_until(
51+
lambda: all(unit.workload_status == 'active'
52+
for application in applications for unit in application.units))
53+
54+
return applications
55+
4056
if __name__ == '__main__':
4157
loop.run(main())

juju/application.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,14 @@ async def run(self, command, timeout=None):
481481
units=[],
482482
)
483483

484+
@property
485+
def charm_url(self):
486+
"""Get the charm url for a given application
487+
488+
:return string: The charm url for an application
489+
"""
490+
return self.safe_data['charm-url']
491+
484492
async def get_annotations(self):
485493
"""Get annotations on this application.
486494

0 commit comments

Comments
 (0)