5efcfc39735c818a9778172356f82ec0eb3e5916
- Author
- Jose C. Massón <939888+Abuelodelanada@users.noreply.github.com>
- Committer
- GitHub <noreply@github.com>
- Date
Message
feat(juju): add functions to get current controller and model (#11572)
Diff
1diff --git a/plugins/juju/README.md b/plugins/juju/README.md
2index f0c65309c9f13d25d48e2e256e521b8683c25002..6ee333f5060adc7fd3c967491d2237cf595056c7 100644
3--- a/plugins/juju/README.md
4+++ b/plugins/juju/README.md
5@@ -126,5 +126,7 @@ Naming convention:
6 - `jaddr <app_name> [unit_num]`: display app or unit IP address.
7 - `jreld <relation_name> <app_name> <unit_num>`: display app and unit relation data.
8 - `jclean`: destroy all controllers
9+- `jcontroller`: display the controller your are connected to.
10+- `jmodel`: display the model your are connected to.
11 - `wjst [interval_secs] [args_for_watch]`: watch juju status, with optional interval
12 (default: 5s); you may pass additional arguments to `watch`.
13diff --git a/plugins/juju/juju.plugin.zsh b/plugins/juju/juju.plugin.zsh
14index be8a2c7aecbf4ca2521871c238c441de10b4adb9..0c60e35ceb7f9f6d833a228a753e84359ac73000 100644
15--- a/plugins/juju/juju.plugin.zsh
16+++ b/plugins/juju/juju.plugin.zsh
17@@ -163,10 +163,40 @@ jreld() {
18 juju run "relation-get -r $relid - $2" --unit $2/$3
19 }
20
21+# Return Juju current controller
22+jcontroller() {
23+ local controller="$(awk '/current-controller/ {print $2}' ~/.local/share/juju/controllers.yaml)"
24+ if [[ -z "$controller" ]]; then
25+ return 1
26+ fi
27+
28+ echo $controller
29+ return 0
30+}
31+
32+# Return Juju current model
33+jmodel() {
34+ local yqbin="$(whereis yq | awk '{print $2}')"
35+
36+ if [[ -z "$yqbin" ]]; then
37+ echo "--"
38+ return 1
39+ fi
40+
41+ local model="$(yq e ".controllers.$(jcontroller).current-model" < ~/.local/share/juju/models.yaml | cut -d/ -f2)"
42+
43+ if [[ -z "$model" ]]; then
44+ echo "--"
45+ return 1
46+ fi
47+
48+ echo $model
49+ return 0
50+}
51+
52 # Watch juju status, with optional interval (default: 5 sec)
53 wjst() {
54 local interval="${1:-5}"
55 shift $(( $# > 0 ))
56 watch -n "$interval" --color juju status --relations --color "$@"
57 }
58-