From: Tim Van Steenburgh Date: Fri, 9 Dec 2016 15:57:30 +0000 (-0500) Subject: add_model() can accept just a model name X-Git-Tag: 0.1.0~16 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=7830549373ea7b5680a00d1bc3ecf81ee96eed33;hp=6ba2856fecf224ae3fd589331e889a6587e8153b;p=osm%2FN2VC.git add_model() can accept just a model name --- diff --git a/docs/narrative/create-model.rst b/docs/narrative/create-model.rst index c650f91..b0cdbe7 100644 --- a/docs/narrative/create-model.rst +++ b/docs/narrative/create-model.rst @@ -1,6 +1,8 @@ Creating and Destroying a Model =============================== -Example of creating a new model and then destroying it. +Example of creating a new model and then destroying it. See +:meth:`juju.controller.Controller.add_model` and +:meth:`juju.controller.Controller.destroy_model` for more info. .. code:: python @@ -12,8 +14,6 @@ Example of creating a new model and then destroying it. # Create our new model model = await controller.add_model( 'mymodel', # name of your new model - 'aws', # name of the cloud to use - 'aws-tim', # name of the credential to use ) # Do stuff with our model... diff --git a/juju/controller.py b/juju/controller.py index 67409ba..6331c12 100644 --- a/juju/controller.py +++ b/juju/controller.py @@ -55,39 +55,46 @@ class Controller(object): self.connection = None async def add_model( - self, model_name, cloud_name, credential_name, + self, model_name, cloud_name=None, credential_name=None, owner=None, config=None, region=None): """Add a model to this controller. :param str model_name: Name to give the new model. :param str cloud_name: Name of the cloud in which to create the - model, e.g. 'aws'. + model, e.g. 'aws'. Defaults to same cloud as controller. :param str credential_name: Name of the credential to use when - creating the model. + creating the model. Defaults to current credential. If you + pass a credential_name, you must also pass a cloud_name, + even if it's the default cloud. :param str owner: Username that will own the model. Defaults to the current user. :param dict config: Model configuration. :param str region: Region in which to create the model. """ - # XXX: We can probably obviate the cloud_name param by getting it - # from the controller itself. - model_facade = client.ModelManagerFacade() model_facade.connect(self.connection) owner = owner or self.connection.info['user-info']['identity'] + # XXX: We should be able to accept a credential_name without + # a cloud_name, and just get the cloud_name from the controller. + if credential_name and cloud_name: + credential = tag.credential( + cloud_name, + tag.untag('user-', owner), + credential_name + ) + else: + credential = None + + log.debug('Creating model %s', model_name) model_info = await model_facade.CreateModel( tag.cloud(cloud_name), config, - tag.credential( - cloud_name, - tag.untag('user-', owner), - credential_name - ), + credential, model_name, owner, region, diff --git a/juju/tag.py b/juju/tag.py index f10c5ef..d36316d 100644 --- a/juju/tag.py +++ b/juju/tag.py @@ -1,11 +1,11 @@ def _prefix(prefix, s): - if not s.startswith(prefix): + if s and not s.startswith(prefix): return '{}{}'.format(prefix, s) return s def untag(prefix, s): - if s.startswith(prefix): + if s and s.startswith(prefix): return s[len(prefix):] return s