juju.plugin.zsh 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. # ---------------------------------------------------------- #
  2. # Aliases and functions for juju (https://juju.is) #
  3. # ---------------------------------------------------------- #
  4. # Load TAB completions
  5. # You need juju's bash completion script installed. By default bash-completion's
  6. # location will be used (i.e. pkg-config --variable=completionsdir bash-completion).
  7. completion_file="$(pkg-config --variable=completionsdir bash-completion 2>/dev/null)/juju" || \
  8. completion_file="/usr/share/bash-completion/completions/juju"
  9. [[ -f "$completion_file" ]] && source "$completion_file"
  10. unset completion_file
  11. # ---------------------------------------------------------- #
  12. # Aliases (in alphabetic order) #
  13. # #
  14. # Generally, #
  15. # - `!` means --force --no-wait -y #
  16. # - `ds` suffix means --destroy-storage #
  17. # ---------------------------------------------------------- #
  18. alias jam="juju add-model --config logging-config=\"<root>=WARNING; unit=DEBUG\"\
  19. --config update-status-hook-interval=\"60m\""
  20. alias jb='juju bootstrap'
  21. alias jbm='juju bootstrap microk8s'
  22. alias jc='juju config'
  23. alias jdc='juju destroy-controller --destroy-all-models'
  24. alias 'jdc!'='juju destroy-controller --destroy-all-models --force --no-wait -y'
  25. alias jdcds='juju destroy-controller --destroy-all-models --destroy-storage'
  26. alias 'jdcds!'='juju destroy-controller --destroy-all-models --destroy-storage --force --no-wait -y'
  27. alias jdm='juju destroy-model'
  28. alias 'jdm!'='juju destroy-model --force --no-wait -y'
  29. alias jdmds='juju destroy-model --destroy-storage'
  30. alias 'jdmds!'='juju destroy-model --destroy-storage --force --no-wait -y'
  31. alias jde='juju deploy --channel=edge'
  32. alias jd='juju deploy'
  33. alias jdl='juju debug-log --ms'
  34. alias jdlr='juju debug-log --ms --replay'
  35. alias jcon='juju consume'
  36. alias jeb='juju export-bundle'
  37. alias jex='juju expose'
  38. alias jh='juju help'
  39. alias jkc='juju kill-controller -y -t 0'
  40. alias jm='juju models'
  41. alias jmc='juju model-config'
  42. alias jof='juju offer'
  43. alias jra='juju run-action'
  44. alias jraw='juju run-action --wait'
  45. alias jrel='juju relate'
  46. alias jrm='juju remove-application'
  47. alias 'jrm!'='juju remove-application --force --no-wait'
  48. alias jrmds='juju remove-application --destroy-storage'
  49. alias 'jrmds!'='juju remove-application --destroy-storage --force --no-wait'
  50. alias jrmrel='juju remove-relation'
  51. alias 'jrmrel!'='juju remove-relation --force'
  52. alias jrmsas='juju remove-saas'
  53. alias jrp='juju refresh --path'
  54. alias jrs='juju remove-storage'
  55. alias 'jrs!'='juju remove-storage --force'
  56. alias jsa='juju scale-application'
  57. alias jsh='juju ssh'
  58. alias jshc='juju ssh --container'
  59. alias jshm='juju show-model'
  60. alias jssl='juju show-status-log'
  61. alias jstj='juju status --format=json'
  62. alias jst='juju status --relations --storage --color'
  63. alias jsu='juju show-unit'
  64. alias jsw='juju switch'
  65. # ---------------------------------------------------------- #
  66. # Functions (in alphabetic order) #
  67. # ---------------------------------------------------------- #
  68. # Get app or unit address
  69. jaddr() {
  70. # $1 = app name
  71. # $2 = unit number (optional)
  72. if (( ! ${+commands[jq]} )); then
  73. echo "jq is required but could not be found." >&2
  74. return 1
  75. fi
  76. if [[ $# -eq 1 ]]; then
  77. # Get app address
  78. juju status "$1" --format=json \
  79. | jq -r ".applications.\"$1\".address"
  80. elif [[ $# -eq 2 ]]; then
  81. # Get unit address
  82. juju status "$1/$2" --format=json \
  83. | jq -r ".applications.\"$1\".units.\"$1/$2\".address"
  84. else
  85. echo "Invalid number of arguments."
  86. echo "Usage: jaddr <app-name> [<unit-number>]"
  87. echo "Example: jaddr karma"
  88. echo "Example: jaddr karma 0"
  89. return 1
  90. fi
  91. }
  92. # Display app and unit relation data
  93. jreld() {
  94. # $1 = relation name
  95. # $2 = app name
  96. # $3 = unit number
  97. if [[ $# -ne 3 ]]; then
  98. echo "Invalid number of arguments."
  99. echo "Usage: jreld <relation-name> <app-name> <unit-number>"
  100. echo "Example: jreld karma-dashboard alertmanager 0"
  101. return 1
  102. fi
  103. local relid="$(juju run "relation-ids $1" --unit $2/$3)"
  104. if [[ -z "$relid" ]]; then
  105. return 1
  106. fi
  107. echo "App data:"
  108. juju run "relation-get -r $relid --app - $2" --unit $2/$3
  109. echo
  110. echo "Unit data:"
  111. juju run "relation-get -r $relid - $2" --unit $2/$3
  112. }
  113. # Watch juju status, with optional interval (default: 5 sec)
  114. wjst() {
  115. local interval="${1:-5}"
  116. shift $(( $# > 0 ))
  117. watch -n "$interval" --color juju status --relations --storage --color "$@"
  118. }