From b7c47ef0eef81a08e60d085a6139e2fa3bb2af80 Mon Sep 17 00:00:00 2001 From: Arif Ali Date: Mon, 28 Dec 2020 10:17:02 +0000 Subject: [PATCH] Add pod for the hypervisor and other fixes * Add pod creation, so that when we remove the hypervisor then all the VMs also get removed automatically * virtinst is only used when creating/installing VMs, so only install on hypervisor nodes * Only grab the top vlan if we have 2, this typically means that we have an ipv4 and ipv6 IP. Could probably do this better, but keep it simple for the time being --- configs/hypervisor.config | 2 +- configs/rpi4-maas.config | 2 +- functions.sh | 6 +++++- manage-hypervisor-nodes.sh | 29 ++++++++++++++++++++++++----- 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/configs/hypervisor.config b/configs/hypervisor.config index fd62d6c..b08188e 120000 --- a/configs/hypervisor.config +++ b/configs/hypervisor.config @@ -1 +1 @@ -asrock01.config \ No newline at end of file +asrock02.config \ No newline at end of file diff --git a/configs/rpi4-maas.config b/configs/rpi4-maas.config index 6dba2eb..47a03b0 100644 --- a/configs/rpi4-maas.config +++ b/configs/rpi4-maas.config @@ -10,7 +10,7 @@ maas_profile="admin" maas_system_ip="192.168.1.10" maas_upstream_dns="1.1.1.1 4.4.4.4 8.8.8.8" maas_user="admin" -maas_version="2.8" +maas_version="2.9" maas_api_key="z9cT7jE3BhmxcXkWWN:ew5WW9QdDMg8TXVnjt:NtKgJdfgA5FVw2YT9CnaKU87wJ5fTxKa" no_proxy="localhost,127.0.0.1,$maas_system_ip" squid_proxy="http://192.168.100.10:3128" diff --git a/functions.sh b/functions.sh index fd16c8f..88a14e0 100644 --- a/functions.sh +++ b/functions.sh @@ -7,7 +7,11 @@ state_timeout=1200 install_deps() { # Install some of the dependent packages - sudo apt -y update && sudo apt -y install jq bc virtinst + deps="jq bc" + if [[ "$0" == "*manage-maas-*" ]] ; then + deps+=" virtinst" + fi + sudo apt -y update && sudo apt -y install ${deps} # We install the snap, as maas-cli is not in distributions, this ensures # that the package we invoke would be consistent diff --git a/manage-hypervisor-nodes.sh b/manage-hypervisor-nodes.sh index 96be2f3..82b3932 100755 --- a/manage-hypervisor-nodes.sh +++ b/manage-hypervisor-nodes.sh @@ -20,7 +20,7 @@ maas_assign_networks() i=0 for vlan in ${vlans[*]} do - subnet_line=$(maas admin subnets read | jq ".[] | {subnet_id:.id, vlan:.vlan.vid, vlan_id:.vlan.id}" --compact-output | grep "vlan\":$vlan,") + subnet_line=$(maas admin subnets read | jq ".[] | {subnet_id:.id, vlan:.vlan.vid, vlan_id:.vlan.id}" --compact-output | grep "vlan\":$vlan," | head -n 1) maas_vlan_id=$(echo $subnet_line | jq .vlan_id | sed s/\"//g) maas_subnet_id=$(echo $subnet_line | jq .subnet_id | sed s/\"//g) ip_addr="" @@ -69,6 +69,13 @@ maas_create_partitions() stg_mount=$(maas ${maas_profile} block-device mount ${system_id} ${libvirt_block_id} mount_point=${storage_path}) } +maas_add_pod() +{ + pod_create=$(maas ${maas_profile} pods create power_address="qemu+ssh://${virsh_user}@${hypervisor_ip}/system" power_user="${virsh_user}" power_pass="${qemu_password}" type="virsh") + pod_id=$(echo $pod_create | jq ".id" | sed s/\"//g) + pod_name=$(maas ${maas_profile} pod update ${pod_id} name=${hypervisor_name}) +} + # Calls the functions that destroys and cleans up all the VMs wipe_node() { install_deps @@ -86,6 +93,14 @@ install_node() { install_deps maas_login deploy_node + maas_add_pod +} + +add_pod() +{ + install_deps + maas_login + maas_add_pod } # Fixes all the networks on all the VMs @@ -128,18 +143,19 @@ deploy_node() { show_help() { echo " - -c Creates Hypervisor - -w Removes Hypervisor - -d Deploy 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 -while getopts ":cwdanp" opt; do +while getopts ":cwdaknp" opt; do case $opt in c) create_node @@ -154,6 +170,9 @@ while getopts ":cwdanp" opt; do create_node install_node ;; + k) + add_pod + ;; n) network_auto ;;