From 2b57cff5850b454c9c73e05bb4e335109ec25b75 Mon Sep 17 00:00:00 2001 From: Arif Ali Date: Wed, 30 Dec 2020 22:08:49 +0000 Subject: [PATCH] Add option for hypervisor and therefore re-jig read_config --- TODO.md | 4 ++-- configs/hypervisor.config | 1 - functions.sh | 27 ++++++++++++++++++--------- manage-hypervisor-nodes.sh | 30 +++++++++++++++++++++--------- manage-maas-nodes.sh | 2 +- 5 files changed, 42 insertions(+), 22 deletions(-) delete mode 120000 configs/hypervisor.config diff --git a/TODO.md b/TODO.md index df2269a..1708bf0 100644 --- a/TODO.md +++ b/TODO.md @@ -1,7 +1,7 @@ # Todo -1. add the hypervisor as a flag rather then the configuration file when adding - hypervisors. +1. ~~add the hypervisor as a flag rather then the configuration file when adding + hypervisors.~~ 1. ~~Add script to cloud-init, that will allow to wipe disk. This will allow to reboot the hypervisor, such that we don't have to log back in after the machine has been re-commissioned.~~ diff --git a/configs/hypervisor.config b/configs/hypervisor.config deleted file mode 120000 index fd62d6c..0000000 --- a/configs/hypervisor.config +++ /dev/null @@ -1 +0,0 @@ -asrock01.config \ No newline at end of file diff --git a/functions.sh b/functions.sh index dbb3676..2b372c4 100644 --- a/functions.sh +++ b/functions.sh @@ -136,20 +136,29 @@ maas_add_node() [[ $machine_type == "physical" ]] && maas_create_partitions ${system_id} } -read_config() +read_configs() { configs="" configs+=" configs/default.config" configs+=" configs/maas.config" - configs+=" configs/hypervisor.config" + if [[ "$0" == "*manage-maas-*" ]] ; then + configs+=" configs/hypervisor.config" + fi for config in $configs ; do - if [ ! -f $config ]; then - printf "Error: missing config file. Please create the file '$config'.\n" - exit 1 - else - shopt -s extglob - source "$config" - fi + read_config $config done } + +read_config() +{ + config=$1 + + if [ ! -f $config ]; then + printf "Error: missing config file. Please create the file '$config'.\n" + exit 1 + else + shopt -s extglob + source "$config" + fi +} diff --git a/manage-hypervisor-nodes.sh b/manage-hypervisor-nodes.sh index 82b3932..cf9f904 100755 --- a/manage-hypervisor-nodes.sh +++ b/manage-hypervisor-nodes.sh @@ -143,40 +143,47 @@ deploy_node() { show_help() { echo " - -a Create and Deploy - -c Creates Hypervisor - -d Deploy Hypervisor - -k Add Hypervisor as Pod - -n Assign Networks - -p Update Partitioning - -w Removes Hypervisor + -a Create and Deploy + -c Creates Hypervisor + -d Deploy Hypervisor + -k Add Hypervisor as Pod + -n Assign Networks + -p Update Partitioning + -w Removes Hypervisor " } -read_config +read_configs -while getopts ":cwdaknp" opt; do +while getopts ":c:w:d:a:k:n:p:" opt; do case $opt in c) + read_config "configs/$OPTARG.config" create_node ;; w) + read_config "configs/$OPTARG.config" wipe_node ;; d) + read_config "configs/$OPTARG.config" install_node ;; a) + read_config "configs/$OPTARG.config" create_node install_node ;; k) + read_config "configs/$OPTARG.config" add_pod ;; n) + read_config "configs/$OPTARG.config" network_auto ;; p) + read_config "configs/$OPTARG.config" create_partitions ;; \?) @@ -184,5 +191,10 @@ while getopts ":cwdaknp" opt; do show_help exit 1 ;; + : ) + printf "Option -%s needs an argument.\n" "$OPTARG" >&2 + show_help + echo "" + exit 1 esac done diff --git a/manage-maas-nodes.sh b/manage-maas-nodes.sh index 3abdba9..119b3b7 100755 --- a/manage-maas-nodes.sh +++ b/manage-maas-nodes.sh @@ -417,7 +417,7 @@ show_help() { } # Initialise the configs -read_config +read_configs while getopts ":cwjdnr" opt; do case $opt in