Rework a few bits

* Move the commision_vm/node to functions.sh
* if machine already exists in maas, then re-use it
* move node variables above the node_num, to calculate correctly
This commit is contained in:
Arif Ali 2021-01-02 11:07:16 +00:00
parent d53d6c25c7
commit 4a6485a14a
Signed by: arif
GPG Key ID: 369608FBA1353A70
3 changed files with 42 additions and 32 deletions

View File

@ -20,6 +20,11 @@ control_count=1
control_cpus=3
control_ram=8192
# Compute node definition
node_start=1
node_cpus=2
node_ram=4096
# 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
@ -27,11 +32,6 @@ control_ram=8192
# 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 ))
# Compute node definition
node_start=1
node_cpus=2
node_ram=4096
# Disks to create on each VM
disks=()
disks+=(50)

View File

@ -50,7 +50,7 @@ machine_add_tag()
# If the tag doesn't exist, then create it
if [[ $(maas ${maas_profile} tag read ${tag}) == "Not Found" ]] ; then
case $tag in:
case $tag in
"pod-console-logging")
kernel_opts="console=tty1 console=ttyS0"
;;
@ -121,21 +121,31 @@ maas_add_node()
power_params=""
fi
# TODO: check to see if the machine already exists, then we can skip the
# creation below
# This command creates the machine in MAAS. This will then automatically
# turn the machines on, and start commissioning.
maas ${maas_profile} machines create \
hostname=${node_name} \
mac_addresses=${mac_addr} \
architecture=amd64/generic \
power_type=${power_type} ${power_params} > /dev/null
# Grabs the system_id for th node that we are adding
# Check if the system already exists
system_id=$(maas_system_id ${node_name})
ensure_machine_in_state ${system_id} "Ready"
# This command creates the machine in MAAS, if it doesn't already exist.
# This will then automatically turn the machines on, and start
# commissioning.
if [[ -z "$system_id" ]] ; then
machine_create=$(maas ${maas_profile} machines create \
hostname=${node_name} \
mac_addresses=${mac_addr} \
architecture=amd64/generic \
power_type=${power_type} ${power_params})
system_id=$(echo $machine_create | jq .system_id | sed s/\"//g)
ensure_machine_in_state ${system_id} "Ready"
else
boot_int=$(maas ${maas_profile} machine read ${system_id} | jq ".boot_interface | {mac:.mac_address, int_d:.id}")
if [[ $mac_addr != "$(echo $boot_int | jq .mac | sed s/\"//g)" ]] ; then
maas $maas_profile interface update $(echo $boot_int | jq .int_id | sed s/\"//g) mac_addr=${mac_addr}
fi
maas ${maas_profile} machine update ${system_id} \
power_type=${power_type} ${power_params}
commission_node ${system_id}
fi
machine_add_tag ${system_id} ${node_type}
[[ $machine_type == "vm" ]] && machine_add_tag ${system_id} "pod-console-logging"
@ -147,6 +157,18 @@ maas_add_node()
[[ $machine_type == "physical" ]] && maas_create_partitions ${system_id}
}
commission_node()
{
system_id=$1
commission_machine=$(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}
}
read_configs()
{
configs=""

View File

@ -99,18 +99,6 @@ network_auto()
wait
}
commission_vm()
{
system_id=$1
commission_machine=$(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
@ -120,7 +108,7 @@ recommission_vms()
printf -v virt_node %s-%02d "$compute" "$virt"
system_id=$(maas_system_id ${virt_node})
commission_vm ${system_id} &
commission_node ${system_id} &
sleep ${build_fanout}
done