dotfiles.2022/_home/dot_sz.shrc.d/32_gcp.shortcuts

64 lines
2.5 KiB
Plaintext
Raw Normal View History

function gcp_project() {
2022-07-25 15:21:39 +00:00
gcloud config get-value core/project 2> /dev/null
}
function gcp_get_project_id() {
2022-07-25 15:21:39 +00:00
gcloud projects list \
--filter="$1" \
--format="value(project_id)" \
2> /dev/null
}
function gcp_get_project_number() {
2022-07-25 15:21:39 +00:00
gcloud projects list \
--filter="project_id:$1" \
--format='value(project_number)' \
2> /dev/null
}
2022-07-25 15:21:39 +00:00
function gcp_get_regions() {
gcloud compute regions list --format="value(name)"
}
function gcp_get_region_quotas() {
region_arr_list=( $(gcloud compute regions list --format="value(name)") )
for region in ${region_arr_list[@]}; do
echo -e $region\\\t$(gcloud compute regions describe $region --format="table(quotas:format='table(metric,limit,usage)')" | grep PREEMPTIBLE_CPUS )
done
#for region in {us-central1,us-east1,us-east4,us-west1,us-west2,us-west3,us-west4}; do
# echo -e $region\\\t$(gcloud compute regions describe $region --format="table(quotas:format='table(metric,limit,usage)')" | grep PREEMPTIBLE_CPUS )
#done
}
# Usage: gcp_get_stack dragonheart 10 22
# Watch the 'dragonheart' stack,
# refresh every 10 seconds,
# set tmux pane to 22 lines high (on every refresh)
2022-07-25 15:21:39 +00:00
function gcp_get_stack() {
local N="${1:-$(basename $PWD)}"
local _cmd=""
local _tmux=''
[ $# -ge 3 ] && [[ -n "$(which-command tmux)" ]] && printf "%s" "$3" > "/tmp/tmux-$1" && _cmd=$(printf "%s" 'tmux resize-pane -t "$TMUX_PANE" -y $(cat "/tmp/tmux-' "$1" '") ; ') && eval $_cmd
_cmd="{ $(printf "%s " \
"N='$N'; " \
"${_cmd}" \
"echo 'Listing $N stack:'; " \
'{ gcloud compute networks list --filter="name:$N" | ' "sed --unbuffered s/^/Networks.:\ /g ; } " \
'&& { gcloud compute networks subnets list --filter="name:$N" | ' "sed --unbuffered s/^/Subnets..:\ /g ; } " \
'&& { gcloud compute disks list --filter="name:$N" | ' "sed --unbuffered s/^/Disks....:\ /g ; } " \
'&& { gcloud compute instances list --filter="name:$N" | ' "sed --unbuffered s/^/Instances:\ /g ; } " \
2022-08-05 14:06:12 +00:00
'&& { gcloud compute network-firewall-policies get-effective-firewalls --network="$N-network"' \
" | sed --unbuffered s/^/Firewall:\ /g ; } " \
) ;}"
[ $# -ge 2 ] && _cmd="watch -n${2} '${_cmd}'"
[[ -n ${SZ_DEBUG} ]] && printf "Executing: \n\t$_cmd\n\n"
eval $_cmd
2022-07-25 15:21:39 +00:00
}
# printf '\n\n'; gcp_get_stack 'dragonheart' 5
function gcp_region() {
2022-07-25 15:21:39 +00:00
gcloud config get-value compute/region 2> /dev/null
}