diff options
Diffstat (limited to 'cac')
-rwxr-xr-x | cac | 54 |
1 files changed, 40 insertions, 14 deletions
@@ -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 -> ? |> ? |