From: Tim Van Steenburgh Date: Fri, 6 Jan 2017 18:29:22 +0000 (-0500) Subject: Refactoring X-Git-Tag: 0.2.0~3^2 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=d2fa820fda0498109ed316c5e1506695f151ce18;p=osm%2FN2VC.git Refactoring - remove superfluous ensure_future() wrappers - Make Model.deploy() call add_local_charm_dir() implicitly if it's passed a local charm dir path. --- diff --git a/docs/narrative/application.rst b/docs/narrative/application.rst index 148f1fa..1565e5f 100644 --- a/docs/narrative/application.rst +++ b/docs/narrative/application.rst @@ -34,8 +34,8 @@ To deploy a new application, connect a model and then call its Deploying a Local Charm ----------------------- -To deploy a local charm, first upload it to the model, then -deploy it using the returned charm url. +To deploy a local charm, pass the charm directory path to +`Model.deploy()`. .. code:: python @@ -44,15 +44,11 @@ deploy it using the returned charm url. model = Model() await model.connect_current() - # Upload local charm to the model. - # The returned 'local:' url can be used to deploy the charm. - charm_url = await model.add_local_charm_dir( - '/home/tvansteenburgh/src/charms/ubuntu', 'trusty') - - # Deploy the charm using the 'local:' charm. + # Deploy a local charm using a path to the charm directory await model.deploy( - charm_url, + '/home/tvansteenburgh/src/charms/ubuntu', application_name='ubuntu', + series='trusty', ) diff --git a/examples/localcharm.py b/examples/localcharm.py index bc92914..9abfe41 100644 --- a/examples/localcharm.py +++ b/examples/localcharm.py @@ -16,15 +16,11 @@ async def run(): model = Model() await model.connect_current() - # Upload local charm to the model. - # The returned 'local:' url can be used to deploy the charm. - charm_url = await model.add_local_charm_dir( - '/home/tvansteenburgh/src/charms/ubuntu', 'trusty') - - # Deploy the charm using the 'local:' charm. + # Deploy a local charm using a path to the charm directory await model.deploy( - charm_url, + '/home/tvansteenburgh/src/charms/ubuntu', application_name='ubuntu', + series='trusty', ) await model.disconnect() diff --git a/juju/model.py b/juju/model.py index e3a6fea..6eb4e9f 100644 --- a/juju/model.py +++ b/juju/model.py @@ -977,6 +977,18 @@ class Model(object): if not is_local: await client_facade.AddCharm(channel, entity_id) + elif not entity_id.startswith('local:'): + # We have a local charm dir that needs to be uploaded + charm_dir = os.path.abspath( + os.path.expanduser(entity_id)) + series = series or get_charm_series(charm_dir) + if not series: + raise JujuError( + "Couldn't determine series for charm at {}. " + "Pass a 'series' kwarg to Model.deploy().".format( + charm_dir)) + entity_id = await self.add_local_charm_dir(charm_dir, series) + app = client.ApplicationDeploy( application=application_name, channel=channel, @@ -1438,7 +1450,7 @@ class BundleHandler(object): # If we have apps to update, spawn all the coroutines concurrently # and wait for them to finish. charm_urls = await asyncio.gather(*[ - asyncio.ensure_future(self.model.add_local_charm_dir(*params)) + self.model.add_local_charm_dir(*params) for params in args ]) # Update the 'charm:' entry for each app with the new 'local:' url.