diff options
author | tv <tv@shackspace.de> | 2015-08-05 23:46:28 +0200 |
---|---|---|
committer | tv <tv@shackspace.de> | 2015-08-05 23:46:28 +0200 |
commit | 1654c08a17cc6c30194c037816996b5f3e6f29c6 (patch) | |
tree | 4df8645b8b7884af85921ee91380fc304d31fc83 | |
parent | a865fff4e019ce31abc5e1ed2ecf916e838ab26f (diff) |
cac: add _cac_handle_reply
-rwxr-xr-x | cac | 75 |
1 files changed, 20 insertions, 55 deletions
@@ -214,17 +214,7 @@ __cac_cli__powerop() {( reply=$(_cac_post_api_v1 powerop sid="$sid" action="$action") - case $(echo $reply | jq -r .status) in - ok) - echo $reply | jq -r . >&2 - __cac_cli__update - ;; - *) - echo bad reply: >&2 - echo $reply | jq -r . >&2 - exit 23 - ;; - esac + _cac_handle_reply 'cac powerop' "$reply" )} #? cac pushconfig SERVERSPEC [PREFIX=/] @@ -265,17 +255,7 @@ __cac_cli__setlabel() {( reply=$(_cac_post_api_v1 renameserver sid="$sid" name="$label") - case $(echo $reply | jq -r .status) in - ok) - echo $reply | jq -r . >&2 - __cac_cli__update - ;; - *) - echo bad reply: >&2 - echo $reply | jq -r . >&2 - exit 23 - ;; - esac + _cac_handle_reply 'cac setlabel' "$reply" )} #? cac setmode SERVERSPEC (normal|safe) @@ -288,17 +268,7 @@ __cac_cli__setmode() {( reply=$(_cac_post_api_v1 runmode sid="$sid" mode="$mode") - case $(echo $reply | jq -r .status) in - ok) - echo $reply | jq -r . >&2 - __cac_cli__update - ;; - *) - echo bad reply: >&2 - echo $reply | jq -r . - exit 23 - ;; - esac + _cac_handle_reply 'cac setmode' "$reply" )} #? cac ssh SERVERSPEC @@ -379,17 +349,7 @@ __cac_cli__build() {( os="$os" \ ) - case $(echo $reply | jq -r .status) in - ok) - echo $reply | jq -r . >&2 - __cac_cli__update - ;; - *) - echo bad reply: >&2 - echo $reply | jq -r . >&2 - exit 23 - ;; - esac + _cac_handle_reply 'cac build' "$reply" )} #? cac delete SERVERSPEC @@ -401,17 +361,7 @@ __cac_cli__delete() {( reply=$(_cac_post_api_v1 cloudpro/delete sid="$sid") - case $(echo $reply | jq -r .status) in - ok) - echo $reply | jq -r . >&2 - __cac_cli__update - ;; - *) - echo bad reply: >&2 - echo $reply | jq -r . >&2 - exit 23 - ;; - esac + _cac_handle_reply 'cac delete' "$reply" )} @@ -494,7 +444,22 @@ pushdir() { +_cac_handle_reply() {( + label=$1 + reply=$2 + case $(echo $reply | jq -r .status) in + ok) + echo $reply | jq -r . >&2 + __cac_cli__update + ;; + *) + echo $label: bad reply: >&2 + echo $reply | jq -r . >&2 + exit 23 + ;; + esac +)} _cac_get_api_v1() { |