From c304c9981717f872103e3d0db494de4a9fcb90ca Mon Sep 17 00:00:00 2001 From: Arif Ali Date: Sun, 27 Dec 2020 10:32:11 +0000 Subject: [PATCH] Add function to recomission VMs --- manage-maas-nodes.sh | 44 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/manage-maas-nodes.sh b/manage-maas-nodes.sh index 9c1e095..a47dda4 100755 --- a/manage-maas-nodes.sh +++ b/manage-maas-nodes.sh @@ -55,15 +55,12 @@ wipe_vms() { destroy_vms } -fix_networks() +# Fixes all the networks on all the VMs +network_auto() { install_deps maas_login - fix_maas_networks -} -# Fixes all the networks on all the VMs -fix_maas_networks() { for ((virt="$node_start"; virt<=node_count; virt++)); do printf -v virt_node %s-%02d "$compute" "$virt" system_id=$(maas_system_id ${virt_node}) @@ -73,6 +70,34 @@ fix_maas_networks() { wait } +commision_vm() +{ + system_id=$1 + + maas ${maas_profile} machine commission ${system_id} + + # Ensure that the machine is in ready state before the next step + ensure_machine_in_state ${system_id} "Ready" + + maas_auto_assign_networks ${system_id} +} + +recommission_vms() +{ + install_deps + maas_login + + for ((virt="$node_start"; virt<=node_count; virt++)); do + printf -v virt_node %s-%02d "$compute" "$virt" + system_id=$(maas_system_id ${virt_node}) + + commission_vm ${system_id} & + + sleep ${build_fanout} + done + wait +} + # Creates the disks for all the nodes create_storage() { for ((virt="$node_start"; virt<=node_count; virt++)); do @@ -238,13 +263,15 @@ show_help() { -c Creates everything -w Removes everything -d Releases VMs, Clears Disk + -n Updates all the networks on all VMs + -r Recommission all VMs " } # Initialise the configs read_config -while getopts ":cwd" opt; do +while getopts ":cwdnr" opt; do case $opt in c) create_vms @@ -256,7 +283,10 @@ while getopts ":cwd" opt; do wipe_disks ;; n) - fix_networks + network_auto + ;; + r) + recommission_vms ;; \?) printf "Unrecognized option: -%s. Valid options are:" "$OPTARG" >&2