54783f66b8188297448bc725c578fdc7647e9fa0
- Author
- Leon <82407168+sed-i@users.noreply.github.com>
- Committer
- GitHub <noreply@github.com>
- Date
Message
Diff
This diff is truncated to protect this page.
1diff --git a/plugins/juju/README.md b/plugins/juju/README.md
2new file mode 100644
3index 0000000000000000000000000000000000000000..49f8b0d47fe19638f2ca679d414c40dfda5573d8
4--- /dev/null
5+++ b/plugins/juju/README.md
6@@ -0,0 +1,117 @@
7+# juju plugin
8+
9+This plugin provides useful aliases and functions for [juju](https://juju.is/) (for TAB completion,
10+refer to the [official repo](https://github.com/juju/juju/blob/develop/etc/bash_completion.d/juju)).
11+
12+To use this plugin, add `juju` to the plugins array in your zshrc file.
13+
14+```zsh
15+plugins=(... juju)
16+```
17+
18+## Aliases
19+
20+Naming convention:
21+
22+- `!` suffix: `--force --no-wait -y`.
23+- `ds` suffix: `--destroy-storage`.
24+
25+### General
26+
27+| Alias | Command | Description |
28+|--------|---------------------------------------------|--------------------------------------------------------|
29+| `jdl` | `juju debug-log --ms` | Display log, with millisecond resolution |
30+| `jdlr` | `juju debug-log --ms --replay` | Replay entire log |
31+| `jh` | `juju help` | Show help on a command or other topic |
32+| `jssl` | `juju juju show-status-log` | Output past statuses for the specified entity |
33+| `jstj` | `juju status --format=json` | Show status in json format (more detailed) |
34+| `jst` | `juju status --relations --storage --color` | Show status, including relations and storage, in color |
35+
36+### Bootstrap
37+
38+| Alias | Command | Description |
39+|-------|---------------------------|-------------------------------------------|
40+| `jb` | `juju bootstrap` | Initializing a Juju cloud environment |
41+| `jbm` | `juju bootstrap microk8s` | Initializing a MicroK8s cloud environment |
42+
43+### Controller
44+
45+| Alias | Command | Description |
46+|----------|---------------------------------------------------------------------------------------|-------------------------------------------------------------------|
47+| `jdc` | `juju destroy-controller --destroy-all-models` | Destroy a controller |
48+| `jdc!` | `juju destroy-controller --destroy-all-models --force --no-wait -y` | Destroy a controller |
49+| `jdcds` | `juju destroy-controller --destroy-all-models --destroy-storage` | Destroy a controller and associated storage |
50+| `jdcds!` | `juju destroy-controller --destroy-all-models --destroy-storage --force --no-wait -y` | Destroy a controller and associated storage |
51+| `jkc` | `juju kill-controller -y -t 0` | Forcibly terminate all associated resources for a Juju controller |
52+| `jsw` | `juju switch` | Select or identify the current controller and model |
53+
54+### Model
55+
56+| Alias | Command | Description |
57+|----------|-------------------------------------------------------------|-------------------------------------------------------|
58+| `jam` | `juju add-model` | Add a hosted model |
59+| `jdm` | `juju destroy-model` | Non-recoverable, complete removal of a model |
60+| `jdm!` | `juju destroy-model --force --no-wait -y` | Non-recoverable, complete removal of a model |
61+| `jdmds` | `juju destroy-model --destroy-storage` | Non-recoverable, complete removal of a model |
62+| `jdmds!` | `juju destroy-model --destroy-storage --force --no-wait -y` | Non-recoverable, complete removal of a model |
63+| `jmc` | `juju model-config` | Display or set configuration values on a model |
64+| `jm` | `juju models` | List models a user can access on a controller |
65+| `jshm` | `juju show-model` | Show information about the current or specified model |
66+| `jsw` | `juju switch` | Select or identify the current controller and model |
67+
68+### Application / unit
69+
70+| Alias | Command | Description |
71+|----------|---------------------------------------------------------------|---------------------------------------------------------------------------|
72+| `jc` | `juju config` | Get, set, or reset configuration for a deployed application |
73+| `jde` | `juju deploy --channel=edge` | Deploy a new application or bundle from the edge channel |
74+| `jd` | `juju deploy` | Deploy a new application or bundle |
75+| `jra` | `juju run-action` | Queue an action for execution |
76+| `jraw` | `juju run-action --wait` | Queue an action for execution and wait for results, with optional timeout |
77+| `jrm` | `juju remove-application` | Remove application |
78+| `jrm!` | `juju remove-application --force --no-wait` | Remove application forcefully |
79+| `jrmds` | `juju remove-application --destroy-storage` | Remove application and destroy attached storage |
80+| `jrmds!` | `juju remove-application --destroy-storage --force --no-wait` | Remove application forcefully, destroying attached storage |
81+| `jrp` | `juju refresh --path` | Upgrade charm from local charm file |
82+| `jsa` | `juju scale-application` | Set the desired number of application units |
83+| `jsh` | `juju ssh` | Initiate an SSH session or execute a command on a Juju target |
84+| `jshc` | `juju ssh --container` | Initiate an SSH session or execute a command on a given container |
85+| `jsu` | `juju show-unit` | Displays information about a unit |
86+
87+### Storage
88+
89+| Alias | Command | Description |
90+|---------|-------------------------------|-------------------------------------------------|
91+| `jrs` | `juju remove-storage` | Remove storage |
92+| `jrs!` | `juju remove-storage --force` | Remove storage even if it is currently attached |
93+
94+### Relation
95+
96+| Alias | Command | Description |
97+|-----------|--------------------------------|-------------------------------------------------------------------|
98+| `jrel` | `juju relate` | Relate two applications |
99+| `jrmrel` | `juju remove-relation` | Remove an existing relation between two applications. |
100+| `jrmrel!` | `juju remove-relation --force` | Remove an existing relation between two applications, forcefully. |
101+
102+### Cross-model relation (CMR)
103+
104+| Alias | Command | Description |
105+|----------|--------------------|----------------------------------------------------------------|
106diff --git a/plugins/juju/juju.plugin.zsh b/plugins/juju/juju.plugin.zsh
107new file mode 100644
108index 0000000000000000000000000000000000000000..07f15b3925f4156bbaffe1cb9e7ecfcdd7db1116
109--- /dev/null
110+++ b/plugins/juju/juju.plugin.zsh
111@@ -0,0 +1,127 @@
112+# ---------------------------------------------------------- #
113+# Aliases and functions for juju (https://juju.is) #
114+# ---------------------------------------------------------- #
115+
116+# Load TAB completions
117+# You need juju's bash completion script installed. By default bash-completion's
118+# location will be used (i.e. pkg-config --variable=completionsdir bash-completion).
119+completion_file="$(pkg-config --variable=completionsdir bash-completion 2>/dev/null)/juju" || \
120+ completion_file="/usr/share/bash-completion/completions/juju"
121+[[ -f "$completion_file" ]] && source "$completion_file"
122+unset completion_file
123+
124+# ---------------------------------------------------------- #
125+# Aliases (in alphabetic order) #
126+# #
127+# Generally, #
128+# - `!` means --force --no-wait -y #
129+# - `ds` suffix means --destroy-storage #
130+# ---------------------------------------------------------- #
131+alias jam="juju add-model --config logging-config=\"<root>=WARNING; unit=DEBUG\"\
132+ --config update-status-hook-interval=\"60m\""
133+alias jb='juju bootstrap'
134+alias jbm='juju bootstrap microk8s'
135+alias jc='juju config'
136+alias jdc='juju destroy-controller --destroy-all-models'
137+alias 'jdc!'='juju destroy-controller --destroy-all-models --force --no-wait -y'
138+alias jdcds='juju destroy-controller --destroy-all-models --destroy-storage'
139+alias 'jdcds!'='juju destroy-controller --destroy-all-models --destroy-storage --force --no-wait -y'
140+alias jdm='juju destroy-model'
141+alias 'jdm!'='juju destroy-model --force --no-wait -y'
142+alias jdmds='juju destroy-model --destroy-storage'
143+alias 'jdmds!'='juju destroy-model --destroy-storage --force --no-wait -y'
144+alias jde='juju deploy --channel=edge'
145+alias jd='juju deploy'
146+alias jdl='juju debug-log --ms'
147+alias jdlr='juju debug-log --ms --replay'
148+alias jcon='juju consume'
149+alias jeb='juju export-bundle'
150+alias jex='juju expose'
151+alias jh='juju help'
152+alias jkc='juju kill-controller -y -t 0'
153+alias jm='juju models'
154+alias jmc='juju model-config'
155+alias jof='juju offer'
156+alias jra='juju run-action'
157+alias jraw='juju run-action --wait'
158+alias jrel='juju relate'
159+alias jrm='juju remove-application'
160+alias 'jrm!'='juju remove-application --force --no-wait'
161+alias jrmds='juju remove-application --destroy-storage'
162+alias 'jrmds!'='juju remove-application --destroy-storage --force --no-wait'
163+alias jrmrel='juju remove-relation'
164+alias 'jrmrel!'='juju remove-relation --force'
165+alias jrmsas='juju remove-saas'
166+alias jrp='juju refresh --path'
167+alias jrs='juju remove-storage'
168+alias 'jrs!'='juju remove-storage --force'
169+alias jsa='juju scale-application'
170+alias jsh='juju ssh'
171+alias jshc='juju ssh --container'
172+alias jshm='juju show-model'
173+alias jssl='juju show-status-log'
174+alias jstj='juju status --format=json'
175+alias jst='juju status --relations --storage --color'
176+alias jsu='juju show-unit'
177+alias jsw='juju switch'
178+
179+# ---------------------------------------------------------- #
180+# Functions (in alphabetic order) #
181+# ---------------------------------------------------------- #
182+
183+# Get app or unit address
184+jaddr() {
185+ # $1 = app name
186+ # $2 = unit number (optional)
187+ if (( ! ${+commands[jq]} )); then
188+ echo "jq is required but could not be found." >&2
189+ return 1
190+ fi
191+
192+ if [[ $# -eq 1 ]]; then
193+ # Get app address
194+ juju status "$1" --format=json \
195+ | jq -r ".applications.\"$1\".address"
196+ elif [[ $# -eq 2 ]]; then
197+ # Get unit address
198+ juju status "$1/$2" --format=json \
199+ | jq -r ".applications.\"$1\".units.\"$1/$2\".address"
200+ else
201+ echo "Invalid number of arguments."
202+ echo "Usage: jaddr <app-name> [<unit-number>]"
203+ echo "Example: jaddr karma"
204+ echo "Example: jaddr karma 0"
205+ return 1
206+ fi
207+}
208+
209+# Display app and unit relation data
210+jreld() {