Created
September 11, 2019 17:26
-
-
Save fearphage/d14f1cc08124e6cd5d22aca82f9f2e23 to your computer and use it in GitHub Desktop.
Revisions
-
fearphage created this gist
Sep 11, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,41 @@ ## az-get Returns a property value of a resource passing additional params as needed. ### Usage ```shell az-get <resource> <property> [additional params] ``` ### Example ```shell id=$(az-get image id --name my-image-name --resource-group my-resource-group-name) # allows for deeply nested properties agent=$(az-get vm osProfile.linuxConfiguration.provisionVmAgent --name vm-name --resource-group my-group) ``` ## az-group Returns a list of group names resulting from `az group list`. By default it will list all groups. All passed params will be searched for in the names of the groups using an or (`||`). ### Usage ```shell az-group [search strings] ``` Calling `az-group` without parameters is idential to `az group list --query '[].name' --output tsv`. Calling it with params will search for the substring(s) in the names of the groups. ### Example ```shell # deletes all groups with the substring of deleteme *OR* killme az-group deleteme killme | xargs --max-args 1 --no-run-if-empty az group delete --yes --name ``` Notes: `--no-run-if-empty` is a GNU extensions and thus doesn't work on a Mac. This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ function az-get { # Usage: id=$(az-get image id --name $name --resource-group $group) local property local resource resource="$1" property="$2" shift shift az "$resource" show "$@" --query "$property" --output tsv } function az-group { local query if [ $# -gt 0 ]; then # cross-shell (bash, zsh, etc.) array.join() support query="?contains(name, '$(python -c 'import sys;print sys.argv[1].join(sys.argv[2:])' "') || contains(name, '" "$@")')" fi az group list --query "[$query].name" --output tsv }