Merge pull request #55 from petevg/bug/fix-placement-docstring
[osm/N2VC.git] / juju / model.py
index e3a6fea..653a20c 100644 (file)
@@ -910,11 +910,14 @@ class Model(object):
         :param dict resources: <resource name>:<file path> pairs
         :param str series: Series on which to deploy
         :param dict storage: Storage constraints TODO how do these look?
-        :param str to: Placement directive, e.g.::
+        :param to: Placement directive. Use placement.parse to generate it.
+            For example:
 
-            '23' - machine 23
-            'lxc:7' - new lxc container on machine 7
-            '24/lxc/3' - lxc container 3 or machine 24
+            from juju import placement
+
+            placement.parse('23') - place on machine 23
+            placement.parse('lxc:7') - place in new lxc container on machine 7
+            placement.parse('24/lxc/3') - place in container 3 on machine 24
 
             If None, a new machine is provisioned.
 
@@ -977,6 +980,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 +1453,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.