lib/cac.sh: add cac_getserver_by_servername
This commit is contained in:
parent
a2970fcae7
commit
3cc354008a
21
infest
21
infest
@ -19,12 +19,9 @@ nix_find_sha1sum=86f8775bd4f0841edd4c816df861cebf509d58c3
|
|||||||
# hostname=
|
# hostname=
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
listservers=$(cac_listservers)
|
server=$(cac_getserver_by_servername "$cac_servername")
|
||||||
|
|
||||||
config=$(echo $listservers \
|
serverstatus=$(echo $server | jq -r .status)
|
||||||
| jq -r ".[]|select(.servername==\"$cac_servername\")")
|
|
||||||
|
|
||||||
serverstatus=$(echo $config | jq -r .status)
|
|
||||||
case $serverstatus in
|
case $serverstatus in
|
||||||
'Powered On') : ;;
|
'Powered On') : ;;
|
||||||
*)
|
*)
|
||||||
@ -32,9 +29,9 @@ main() {
|
|||||||
exit 2
|
exit 2
|
||||||
esac
|
esac
|
||||||
|
|
||||||
template=$(echo $config | jq -r .template)
|
template=$(echo $server | jq -r .template)
|
||||||
case $template in
|
case $template in
|
||||||
'CentOS-7-64bit') infest_centos7_64bit "$config";;
|
'CentOS-7-64bit') infest_centos7_64bit "$server";;
|
||||||
*)
|
*)
|
||||||
echo $0: bad template: $template >&2
|
echo $0: bad template: $template >&2
|
||||||
exit 3
|
exit 3
|
||||||
@ -43,14 +40,14 @@ main() {
|
|||||||
|
|
||||||
|
|
||||||
infest_centos7_64bit() {
|
infest_centos7_64bit() {
|
||||||
config=$1
|
server=$1
|
||||||
address=$(echo $config | jq -r .ip)
|
address=$(echo $server | jq -r .ip)
|
||||||
gateway=$(echo $config | jq -r .gateway)
|
gateway=$(echo $server | jq -r .gateway)
|
||||||
nameserver=8.8.8.8
|
nameserver=8.8.8.8
|
||||||
netmask=$(echo $config | jq -r .netmask)
|
netmask=$(echo $server | jq -r .netmask)
|
||||||
prefixLength=$(netmaskToPrefixLengh $netmask)
|
prefixLength=$(netmaskToPrefixLengh $netmask)
|
||||||
RSYNC_RSH='sshpass -e ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'
|
RSYNC_RSH='sshpass -e ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'
|
||||||
SSHPASS=$(echo $config | jq -r .rootpass)
|
SSHPASS=$(echo $server | jq -r .rootpass)
|
||||||
export SSHPASS
|
export SSHPASS
|
||||||
export RSYNC_RSH
|
export RSYNC_RSH
|
||||||
|
|
||||||
|
10
lib/cac.sh
10
lib/cac.sh
@ -1,5 +1,15 @@
|
|||||||
. ./lib/url.sh
|
. ./lib/url.sh
|
||||||
|
|
||||||
|
|
||||||
|
cac_getserver_by_servername() {(
|
||||||
|
serverlist=$(cac_listservers)
|
||||||
|
echo $serverlist \
|
||||||
|
| jq \
|
||||||
|
--arg name "$1" \
|
||||||
|
'.[]|select(.servername==$name)'
|
||||||
|
)}
|
||||||
|
|
||||||
|
|
||||||
cac_listservers() {(
|
cac_listservers() {(
|
||||||
listservers=$(_cac_get_api_v1 listservers)
|
listservers=$(_cac_get_api_v1 listservers)
|
||||||
status=$(echo "$listservers" | jq -r .status)
|
status=$(echo "$listservers" | jq -r .status)
|
||||||
|
@ -19,22 +19,18 @@ hostname=$2
|
|||||||
|
|
||||||
# hostname=
|
# hostname=
|
||||||
|
|
||||||
main() {
|
main() {(
|
||||||
listservers=$(cac_listservers)
|
server=$(cac_getserver_by_servername "$cac_servername")
|
||||||
|
print_networking_configuraton "$server"
|
||||||
config=$(echo $listservers \
|
)}
|
||||||
| jq -r ".[]|select(.servername==\"$cac_servername\")")
|
|
||||||
|
|
||||||
print_networking_configuraton "$config"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
print_networking_configuraton() {
|
print_networking_configuraton() {
|
||||||
config=$1
|
server=$1
|
||||||
address=$(echo $config | jq -r .ip)
|
address=$(echo $server | jq -r .ip)
|
||||||
gateway=$(echo $config | jq -r .gateway)
|
gateway=$(echo $server | jq -r .gateway)
|
||||||
nameserver=8.8.8.8
|
nameserver=8.8.8.8
|
||||||
netmask=$(echo $config | jq -r .netmask)
|
netmask=$(echo $server | jq -r .netmask)
|
||||||
prefixLength=$(netmaskToPrefixLengh $netmask)
|
prefixLength=$(netmaskToPrefixLengh $netmask)
|
||||||
|
|
||||||
# TODO generate all config and put it into a temp dir, then rsync that
|
# TODO generate all config and put it into a temp dir, then rsync that
|
||||||
|
Loading…
Reference in New Issue
Block a user