Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Charmhub deploy charm #483

Merged
merged 18 commits into from
May 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ client:
$(PY) -m juju.client.facade -s "juju/client/schemas*" -o juju/client/

.PHONY: test
test:
tox
test: lint
tox -e py3
tox -e integration


.PHONY: lint
lint:
Expand Down
44 changes: 30 additions & 14 deletions examples/deploy_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,33 @@
3. Destroys the units and applications

"""
from juju.controller import Controller
from juju import loop
from juju.model import Model


async def main():
model = Model()
print('Connecting to model')
# Connect to current model with current user, per Juju CLI
await model.connect()
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')

# Deploy legacy bundle
await deploy_bundle(controller, 'cs:~juju-qa/bundle/basic-0', 'beta')

await controller.disconnect()


async def deploy_bundle(controller, url, channel=None):
models = await controller.list_models()
model = await controller.add_model('model{}'.format(len(models) + 1))

try:
print('Deploying bundle')
applications = await model.deploy(
'cs:~juju-qa/bundle/basic-0',
channel='beta',
)

print('Waiting for active')
await model.block_until(
lambda: all(unit.workload_status == 'active'
for application in applications for unit in application.units))

applications = await deploy_and_wait_for_bundle(model, url, channel)

print("Successfully deployed!")
print('Removing bundle')
for application in applications:
Expand All @@ -37,5 +43,15 @@ async def main():
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__':
loop.run(main())
8 changes: 8 additions & 0 deletions juju/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,14 @@ async def run(self, command, timeout=None):
units=[],
)

@property
def charm_url(self):
"""Get the charm url for a given application

:return string: The charm url for an application
"""
return self.safe_data['charm-url']

async def get_annotations(self):
"""Get annotations on this application.

Expand Down
Loading