What is the best way to work with multiple models in a controller using the cli?

Akshat Jiwan Sharma akshatjiwan at gmail.com
Thu Oct 5 09:03:57 UTC 2017


Thanks a lot Ian!

On Thu, Oct 5, 2017 at 1:22 PM, Ian Booth <ian.booth at canonical.com> wrote:

> Hey
>
> The -m argument is what you want. It accepts wither just a model name or a
> controller:model for when you have multiple controllers. eg
>
> $ juju status -m prod
> $ juju status -m ctrl:prod
>
> The first command above works on the prod model on the current controller.
> The
> second selects a specific controller regardless of the current one. The
> second
> way is the safest unless you really are only using one controller.
>
> Also, you can set the JUJU_MODEL env var. That's useful for when you open
> different terminal windows and want to work on a different model in each
> window
> without using -m each time.
>
> On 05/10/17 17:43, Akshat Jiwan Sharma wrote:
> > Hi,
> >
> > I have deployed a few models using the local juju controller and I want
> > to execute a bunch of commands on a particular model using the juju-cli.
> >
> > Lets say I have these three models defined on my controller
> >
> > - model1
> > - model2
> > - model3
> >
> > This is the sequence of commands I want to run
> >
> > 1. List all the machines in model1
> > 2. Add storage unit to model2
> > 3. Add a relation between applications in model3
> >
> > These operations may be run in any order. That is first I might run op 2
> > then op 3 and then op1.
> > The only constraint is that an operation must be run on a particular
> model.
> > Right now I go about this task like so:-
> >
> > juju switch model1 && juju machines
> >
> >  This works fine. I get all my machines listed for model1. The problem
> with
> > this  approach is that I'm not sure if
> > another command is executing a juju switch somewhere and suddenly the
> model
> > I'm operating changes from model1 to model2.
> >
> > For instance suppose that these two commands are run one after the other
> >
> > juju switch model1 && juju list machines
> > juju switch model3 && juju add-relation app1 app2
> >
> > Now how can I be certain that for second command I'm operating on model
> 3?
> > As far as I understand juju switches are global.
> > Meaning a `switch` makes a change "permanent" to all the other commands
> > that follow.
> >
> > My question is how do I "lock" the execution of a certain command to a
> > particular model?
> >
> > Thanks,
> > Akshat
> >
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/juju/attachments/20171005/4ec4ad1e/attachment.html>


More information about the Juju mailing list