diff options
-rw-r--r-- | Makefile | 7 | ||||
-rwxr-xr-x | cac | 54 |
2 files changed, 40 insertions, 21 deletions
@@ -1,13 +1,6 @@ -cloudpro-resources: - @ set -eu; \ - . ~/.secrets/cac; \ - ssh -q $$cac_via -t curl -fsS \ - "https://panel.cloudatcost.com/api/v1/cloudpro/resources.php?key=$$cac_key\\&login=$$cac_login" \ - | jq -r . - # cpu=1/2/3/4/5/6/7/8/9 # ram=1024 (must be multiple of 4. ex. 1024 / 2048 / 3096) # storage=10/20/30/40/50 ... etc @@ -47,10 +47,13 @@ sed ' } # +cac_resources_cache=${cac_resources_cache-$HOME/tmp/cac_resources_cache.json} cac_servers_cache=${cac_servers_cache-$HOME/tmp/cac_servers_cache.json} cac_templates_cache=${cac_templates_cache-$HOME/tmp/cac_templates_cache.json} + cac_secrets=${cac_secrets-$HOME/.secrets/cac} + . "$cac_secrets" >/dev/null 2>&1 || : @@ -93,15 +96,27 @@ __cac_cli__templates() { jq -r . $cac_templates_cache } +#? cac resources +#? Print CloudPRO resources JSON. +#? +__cac_cli__resources() { + jq -r . $cac_resources_cache +} + #? cac update -#? Fetch and cache servers and templates JSON. +#? Fetch and cache state JSON. #? __cac_cli__update() {( umask 0077 - for resource in servers templates; do + for x in \ + resources \ + servers \ + templates \ + # This line intentionally left blank. + do { - json=$(_cac_list$resource) - eval file=\$cac_${resource}_cache + json=$(_cac_fetch_$x) + eval file=\$cac_${x}_cache echo $json | jq . > "$file".tmp mv "$file".tmp "$file" } & @@ -347,30 +362,41 @@ __cac_cli__poll() { #? See sleep(1) for TIMESPEC. #? -_cac_listservers() {( - servers=$(_cac_get_api_v1 listservers) - status=$(echo $servers | jq -r .status) +_cac_fetch_servers() {( + res=$(_cac_get_api_v1 listservers) + status=$(echo $res | jq -r .status) if [ "$status" = ok ]; then - echo "$servers" | jq -r .data + echo "$res" | jq -r .data else - echo "cac_listservers: bad listservers status: $status" >&2 + echo "cac_fetch_servers: bad status: $status" >&2 exit 1 fi )} -_cac_listtemplates() {( - templates=$(_cac_get_api_v1 listtemplates) - status=$(echo $templates | jq -r .status) +_cac_fetch_templates() {( + res=$(_cac_get_api_v1 listtemplates) + status=$(echo $res | jq -r .status) if [ "$status" = ok ]; then - echo "$templates" | jq -r .data + echo "$res" | jq -r .data else - echo "cac_listtemplates: bad listtemplates status: $status" >&2 + echo "cac_fetch_templates: bad status: $status" >&2 exit 1 fi )} +_cac_fetch_resources() {( + res=$(_cac_get_api_v1 cloudpro/resources) + status=$(echo $res | jq -r .status) + + if [ "$status" = ok ]; then + echo "$res" | jq -r .data + else + echo "cac_resources: bad cloudpro/resources status: $status" >&2 + exit 1 + fi +)} # rsyncfiles : lines filename |> local-dir x rsync-target -> ? |> ? |