From f74100750168c5cbafac1cf88f2cfa94e23327b2 Mon Sep 17 00:00:00 2001 From: Arif Ali Date: Wed, 30 Dec 2020 09:36:42 +0000 Subject: [PATCH] Update bootstrap-maas, auto calculate node_count * Ensure that the boot-sources are done at the beginning to give it time to sync * Automatically calculate the amount of VMs depending on memory --- bootstrap-maas.sh | 28 ++++++++++++----------- configs/default.config | 1 - configs/hp01.config | 2 -- configs/hypervisor.common.config | 1 - examples/hypervisor.config.example.bridge | 1 - manage-maas-nodes.sh | 7 ++++++ 6 files changed, 22 insertions(+), 18 deletions(-) diff --git a/bootstrap-maas.sh b/bootstrap-maas.sh index 4f20403..52113e5 100755 --- a/bootstrap-maas.sh +++ b/bootstrap-maas.sh @@ -147,6 +147,18 @@ build_maas() { # Ensure that we are only grabbing amd64 and not other arches as well maas $maas_profile boot-source-selection update 1 1 arches="amd64" + # The release that is is downloading by default + default_release=$(maas $maas_profile boot-source-selection read 1 1 | jq .release | sed s/\"//g) + + # Add bionic if the default is focal + if [[ $default_release == "focal" ]] ; then + maas ${maas_profile} boot-source-selections update 1 os="ubuntu" release="bionic" arches="amd64" subarches="*" labels="*" + fi + + # Import the base images; this can take some time + echo "Importing boot images, please be patient, this may take some time..." + maas $maas_profile boot-resources import + # This is hacky, but it's the only way I could find to reliably get the # correct subnet for the maas bridge interface maas $maas_profile subnet update "$(maas $maas_profile subnets read | jq -rc --arg maas_ip "$maas_ip_range" '.[] | select(.name | contains($maas_ip)) | "\(.id)"')" \ @@ -164,7 +176,7 @@ build_maas() { echo $vlan_object | jq . vlan_id=$(echo $vlan_object | jq ".id") subnet_id=$(maas $maas_profile subnets read | jq -rc --arg maas_ip "${maas_subnets[$i]}" '.[] | select(.name | contains($maas_ip)) | "\(.id)"') - maas ${maas_profile} subnet update $subnet_id vlan=${vlan_id} managed=False + maas ${maas_profile} subnet update $subnet_id vlan=${vlan_id} maas_int_id=$(maas ${maas_profile} interfaces read ${maas_system_id} | jq -rc --arg int_ip "${maas_subnets[$i]}" '.[] | select(.links[].subnet.name | contains($int_ip)) | "\(.id)"') @@ -175,6 +187,7 @@ build_maas() { maas $maas_profile vlan update fabric-0 ${maas_vlans[$i]} dhcp_on=True primary_rack="$maas_system_id" # Force MAAS to manage all subnets except for external + maas $maas_profile subnet update $subnet_id managed=False maas $maas_profile subnet update $subnet_id managed=True fi (( i++ )) @@ -198,17 +211,6 @@ build_maas() { } bootstrap_maas() { - # The release that is is downloading by default - default_release=$(maas $maas_profile boot-source-selection read 1 1 | jq .release) - - # Add bionic if the default is focal - if [[ $default_release == "focal" ]] ; then - maas ${maas_profile} boot-source-selections update 1 os="ubuntu" release="bionic" arches="amd64" subarches="*" labels="*" - fi - - # Import the base images; this can take some time - echo "Importing boot images, please be patient, this may take some time..." - maas $maas_profile boot-resources import until [ "$(maas $maas_profile boot-resources is-importing)" = false ]; do sleep 3; done; @@ -357,8 +359,8 @@ if [ $# -eq 0 ]; then fi # Load up some initial variables from the config and package arrays -init_variables read_config +init_variables # This is the proxy that MAAS itself uses (the "internal" MAAS proxy) no_proxy="localhost,127.0.0.1,$maas_system_ip,$(echo $maas_ip_range.{100..200} | sed 's/ /,/g')" diff --git a/configs/default.config b/configs/default.config index 73dfd3b..a09b7bf 100644 --- a/configs/default.config +++ b/configs/default.config @@ -17,7 +17,6 @@ control_count=1 control_cpus=3 control_ram=8192 -node_count=9 node_start=1 node_cpus=2 node_ram=4096 diff --git a/configs/hp01.config b/configs/hp01.config index eccd7e7..626ebe7 100644 --- a/configs/hp01.config +++ b/configs/hp01.config @@ -8,8 +8,6 @@ external_ip=192.168.1.200 compute="hp1-maas-node" -node_count=7 - bridges=() bridges+=("br0") bridges+=("br1") diff --git a/configs/hypervisor.common.config b/configs/hypervisor.common.config index ec71d13..2f36384 100644 --- a/configs/hypervisor.common.config +++ b/configs/hypervisor.common.config @@ -9,7 +9,6 @@ control_count=1 control_cpus=3 control_ram=8192 -node_count=11 node_start=1 node_cpus=2 node_ram=4096 diff --git a/examples/hypervisor.config.example.bridge b/examples/hypervisor.config.example.bridge index 426d332..4b8eb91 100644 --- a/examples/hypervisor.config.example.bridge +++ b/examples/hypervisor.config.example.bridge @@ -8,7 +8,6 @@ control_count=1 control_cpus=3 control_ram=8192 -node_count=11 node_start=1 node_cpus=2 node_ram=4096 diff --git a/manage-maas-nodes.sh b/manage-maas-nodes.sh index b813901..3abdba9 100755 --- a/manage-maas-nodes.sh +++ b/manage-maas-nodes.sh @@ -13,6 +13,13 @@ stg_bus="scsi" # Time between building VMs build_fanout=60 +# Dynamically generate the node count +# The amount of memory add on 10% then divide by node_ram then add 1 +# For a 32GB machine we'll get 10 VMs altogether +# 1 x 4GB juju, 1 x 8GB controler, 8 x 4GB compute +# The juju VM is not included in the count +node_count=$(( `cat /proc/meminfo | grep -i memtotal | awk '{print $2}'` * 11 / 10 / 1024 / 1024 / $node_ram / 1024 + 1 )) + maas_assign_networks() { maas_auto_assign_networks $1