From f1141c79947f1ba335c697be546761a1a1fc43b3 Mon Sep 17 00:00:00 2001 From: Cory Johns Date: Thu, 2 Mar 2017 16:41:49 -0500 Subject: [PATCH] Make connect_model and deploy a bit more friendly --- juju/client/connection.py | 11 ++++++++--- juju/model.py | 12 ++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/juju/client/connection.py b/juju/client/connection.py index dbd48c6..77edda5 100644 --- a/juju/client/connection.py +++ b/juju/client/connection.py @@ -260,12 +260,17 @@ class Connection: async def connect_model(cls, model, loop=None): """Connect to a model by name. - :param str model: : + :param str model: [:] """ - controller_name, model_name = model.split(':') - jujudata = JujuData() + + if ':' in model: + controller_name, model_name = model.split(':') + else: + controller_name = jujudata.current_controller() + model_name = model + controller = jujudata.controllers()[controller_name] endpoint = controller['api-endpoints'][0] cacert = controller.get('ca-cert') diff --git a/juju/model.py b/juju/model.py index 5506e69..91aba25 100644 --- a/juju/model.py +++ b/juju/model.py @@ -1022,6 +1022,18 @@ class Model(object): 'Deploying %s', entity_id) if not is_local: + parts = entity_id[3:].split('/') + if parts[0].startswith('~'): + parts.pop(0) + if not application_name: + application_name = parts[-1].split('-')[0] + if not series: + if len(parts) > 1: + series = parts[0] + else: + entity = await self.charmstore.entity(entity_id) + ss = entity['Meta']['supported-series'] + series = ss['SupportedSeries'][0] await client_facade.AddCharm(channel, entity_id) elif not entity_id.startswith('local:'): # We have a local charm dir that needs to be uploaded -- 2.25.1