Plugins are fairly new to me with in Juju, they’re a powerful way to extend the CLI by supplementing what already exists, with your own. For example I’ve recently been creating a lot of models and controllers to experiment with Cross Model Relations (CMR), before under taking some new additions to Juju.
Switching between models and controllers can be somewhat laborious as you’re having to remember what the previous model or controller name was. I suggested on IRC that
juju switch should have
- similar to
git checkout - for
cd -. Rather than giving Juju the ability to remember, make a plugin and you can do what you want…
Never experimenting with plugins before, I gave it whirl. Plugins are here to supplement Juju so you can’t overwrite an existing command, but can create your own name for a command and that will be called. If you put a binary or executable script on your path with a prefix of
juju- then it will be discoverable by Juju itself.
juju-example on your path will be called if you do
Following this simple rule allowed me to create what I wanted:
juju stash. Simple extensibility for extending Juju, I think this is one of the under rated parts of Juju CLI and I wish more people extended Juju for their needs.
Juju stash allows you to jump between models as if you have a stack; pushing and popping between models.
Switching to a model
juju stash push modelB
Switching back to previous model
juju stash pop
If you want to ping pong between models, you can do the following (see below) and this will store the popped model into the history. Calling it multiple times will mean you can ping-pong between
modelB with out having to remember their names. Supplying
--status along with the
pop command will also dump the
juju status into the stdout so you can keep track of what’s happening where!
juju stash pop --store
Seeing what’s in your history
juju stash list