Updates with some fine tuning

* Add openvswitch support
* Fine tuning of jq commands
This commit is contained in:
2022-10-30 19:17:51 +00:00
parent f3eeb6e2eb
commit 577be01157
8 changed files with 55 additions and 42 deletions

View File

@@ -156,7 +156,7 @@ build_maas() {
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)
default_release=$(maas $maas_profile boot-source-selection read 1 1 | jq -r .release)
# Add bionic if the default is focal, or vice-versa
[[ $default_release == "focal" ]] && other_release="bionic"
@@ -177,7 +177,7 @@ build_maas() {
i=0
for space in ${maas_spaces[*]} ; do
fabric_id=$(maas admin fabrics read | jq ".[] | {id:.id, vlan:.vlans[].vid, fabric:.name}" --compact-output | grep fabric-0 | jq ".id")
fabric_id=$(maas admin fabrics read | jq -c ".[] | {id:.id, vlan:.vlans[].vid, fabric:.name}" | grep fabric-0 | jq ".id")
space_object=$(maas ${maas_profile} spaces create name=${space})
echo $space_object | jq .
space_id=$(echo $space_object | jq ".id")
@@ -357,7 +357,7 @@ fi
juju bootstrap "$cloud_name" --debug --config=config-"$rand_uuid".yaml \
--model-default image-metadata-url=http://192.168.1.12/lxd/ \
--model-default agent-metadata-url=http://192.168.1.12/juju/tools/ \
--constraints "tags=juju"
--no-gui --constraints "tags=juju"
# Since we created ephemeral files, let's wipe them out. Comment if you want to keep them around
if [[ $? = 0 ]]; then

View File

@@ -46,6 +46,7 @@ disks+=(20)
# Network, will assign each interface to the virsh network that has been
# defined in the networks array.
network_type=bridge
bridge_type=ovs
# The vlans for each of the bridges if that is defined.
vlans=()

View File

@@ -1,6 +1,6 @@
juju_version="2.8/stable"
juju_version="2.9/stable"
juju_ha="true"
juju_bootstrap_series="focal"
juju_bootstrap_series="bionic"
launchpad_user="arif-ali"
package_repository="http://192.168.1.12/archive.ubuntu.com/ubuntu/"
maas_bridge_ip="10.0.1.253"

View File

@@ -18,6 +18,11 @@ install_deps()
sudo snap install maas --channel=${maas_version}/stable
}
pkg_cleanup()
{
sudo snap remove maas maas-cli lxd
}
# Ensures that any dependent packages are installed for any MAAS CLI commands
# This also logs in to MAAS, and sets up the admin profile
maas_login()
@@ -31,7 +36,7 @@ maas_system_id()
{
node_name=$1
maas ${maas_profile} machines read hostname=${node_name} | jq ".[].system_id" | sed s/\"//g
maas ${maas_profile} machines read hostname=${node_name} | jq -r ".[].system_id"
}
# Based on the nodename, finds the pod id, if it exists
@@ -39,8 +44,8 @@ maas_pod_id()
{
node_name=$1
maas ${maas_profile} pods read | jq ".[] | {pod_id:.id, hyp_name:.name}" --compact-output | \
grep ${node_name} | jq ".pod_id" | sed s/\"//g
maas ${maas_profile} pods read | jq -c ".[] | {pod_id:.id, hyp_name:.name}" | \
grep ${node_name} | jq -r ".pod_id"
}
machine_add_tag()
@@ -98,7 +103,7 @@ ensure_machine_in_state()
time_end=${time_start}
# The initial state of the system
status_name=$(maas ${maas_profile} machine read ${system_id} | jq ".status_name" | sed s/\"//g)
status_name=$(maas ${maas_profile} machine read ${system_id} | jq -r ".status_name")
# We will continue to check the state of the machine to see if it is in
# $state or the timeout has occured, which defaults to 20 mins
@@ -108,7 +113,7 @@ ensure_machine_in_state()
sleep 20
# Grab the current state
status_name=$(maas ${maas_profile} machine read ${system_id} | jq ".status_name" | sed s/\"//g)
status_name=$(maas ${maas_profile} machine read ${system_id} | jq -r ".status_name")
# Grab the current time to compare against
time_end=$(date +%s)
@@ -147,7 +152,7 @@ maas_add_node()
mac_addresses=${mac_addr} \
architecture=amd64/generic \
power_type=${power_type} ${power_params})
system_id=$(echo $machine_create | jq .system_id | sed s/\"//g)
system_id=$(echo $machine_create | jq -r .system_id)
ensure_machine_in_state ${system_id} "Ready"
@@ -160,7 +165,7 @@ maas_add_node()
# The machine needs to be broken, ready or allocated.
hack_commission=$(maas $maas_profile machine commission ${system_id})
hack_break=$(maas $maas_profile machine mark-broken ${system_id})
int_update=$(maas $maas_profile interface update ${system_id} $(echo $boot_int | jq .int_id | sed s/\"//g) mac_address=${mac_addr})
int_update=$(maas $maas_profile interface update ${system_id} $(echo $boot_int | jq -r .int_id) mac_address=${mac_addr})
fi
machine_power_update=$(maas ${maas_profile} machine update ${system_id} \
power_type=${power_type} ${power_params})

View File

@@ -14,16 +14,16 @@ maas_assign_networks()
# Get the details of the physical interface
phsy_int=$(maas ${maas_profile} interfaces read ${system_id} | jq -c ".[] | {id:.id, name:.name,parent:.parents}" | grep "parent.*\[\]")
phys_int_name=$(echo $phsy_int | jq .name | sed s/\"//g)
phys_int_id=$(echo $phsy_int | jq .id | sed s/\"//g)
phys_int_name=$(echo $phsy_int | jq -r .name)
phys_int_id=$(echo $phsy_int | jq -r .id)
i=0
for vlan in ${vlans[*]}
do
subnet_line=$(maas admin subnets read | jq -rc --arg vlan "$vlan" ".[] | select(.vlan.vid == $vlan) | select(.name | contains(\"/24\"))| {subnet_id:.id, vlan_id:.vlan.id, cidr: .cidr}")
maas_vlan_id=$(echo $subnet_line | jq .vlan_id | sed s/\"//g)
maas_subnet_id=$(echo $subnet_line | jq .subnet_id | sed s/\"//g)
sub_prefix=$(echo $subnet_line | jq .cidr | sed s/\"//g | sed 's/0\/24//g' )
maas_vlan_id=$(echo $subnet_line | jq -r .vlan_id)
maas_subnet_id=$(echo $subnet_line | jq -r .subnet_id)
sub_prefix=$(echo $subnet_line | jq -r .cidr | sed 's/0\/24//g')
ip_addr=""
if [[ $i -eq 0 ]] ; then
# Set the first interface to be static as per the configuration so that it
@@ -36,7 +36,7 @@ maas_assign_networks()
vlan_int_id=$(maas ${maas_profile} interfaces read ${system_id} | jq --argjson vlan ${vlan} '.[] | select(.vlan.vid == $vlan) | select(.type == "vlan") | .id')
if [[ -z "$vlan_int_id" ]] ; then
vlan_int=$(maas ${maas_profile} interfaces create-vlan ${system_id} vlan=${maas_vlan_id} parent=$phys_int_id)
vlan_int_id=$(echo $vlan_int | jq .id | sed s/\"//g)
vlan_int_id=$(echo $vlan_int | jq -r .id)
fi
if [[ $vlan -eq $external_vlan ]] ; then
# Set the external IP to be static as per the configuration
@@ -50,9 +50,9 @@ maas_assign_networks()
fi
# Check to see if the bridge interface already exists, otherwise create it
bridge_int=$(maas ${maas_profile} interfaces read ${system_id} | jq --argjson vlan ${vlan} '.[] | select(.vlan.vid == $vlan) | select(.type == "bridge")')
[[ -z "${bridge_int}" ]] && bridge_int=$(maas ${maas_profile} interfaces create-bridge ${system_id} name=${bridges[$i]} vlan=$maas_vlan_id mac_address=${hypervisor_mac} parent=$vlan_int_id)
bridge_int_id=$(echo $bridge_int | jq .id | sed s/\"//g)
cur_mode=$(echo $bridge_int | jq ".links[].mode" | sed s/\"//g)
[[ -z "${bridge_int}" ]] && bridge_int=$(maas ${maas_profile} interfaces create-bridge ${system_id} name=${bridges[$i]} vlan=$maas_vlan_id mac_address=${hypervisor_mac} parent=$vlan_int_id bridge_tyepe=${bridge_type})
bridge_int_id=$(echo $bridge_int | jq -r .id)
cur_mode=$(echo $bridge_int | jq -r ".links[].mode")
# If the mode is already set correctly, then move on
[[ $cur_mode == "auto" ]] && [[ $mode == "AUTO" ]] && continue
#bridge_unlink=$(maas ${maas_profile} interface unlink-subnet $system_id $bridge_int_id id=$( echo $bridge_int_id | jq {maas_subnet_id})
@@ -79,10 +79,10 @@ maas_create_partitions()
storage_layout=$(maas ${maas_profile} machine set-storage-layout ${system_id} storage_layout=lvm vg_name=${hypervisor_name} lv_name=root lv_size=${actual_size} root_disk=${boot_disk})
vg_device=$(echo $storage_layout | jq ".volume_groups[].id" )
remaining_space=$(maas ${maas_profile} volume-group read ${system_id} ${vg_device} | jq ".available_size" | sed s/\"//g)
remaining_space=$(maas ${maas_profile} volume-group read ${system_id} ${vg_device} | jq -r ".available_size")
libvirt_lv=$(maas ${maas_profile} volume-group create-logical-volume ${system_id} ${vg_device} name=libvirt size=${remaining_space})
libvirt_block_id=$(echo ${libvirt_lv} | jq .id)
libvirt_block_id=$(echo ${libvirt_lv} | jq -r .id)
stg_fs=$(maas ${maas_profile} block-device format ${system_id} ${libvirt_block_id} fstype=ext4)
@@ -90,27 +90,27 @@ maas_create_partitions()
for ((disk=1;disk<${#disk_names[@]};disk++)); do
disk_id=$(echo $disks | jq ".[] | select(.name == \"${disk_names[$disk]}\") | .id")
disk_id=$(echo $disks | jq -r ".[] | select(.name == \"${disk_names[$disk]}\") | .id")
create_partition=$(maas ${maas_profile} partitions create ${system_id} ${disk_id})
part_id=$(echo $create_partition | jq .id)
part_id=$(echo $create_partition | jq -r .id)
if [[ $disk -eq 1 ]] ; then
vg_create=$(maas ${maas_profile} volume-groups create ${system_id} name=${hypervisor_name}-nvme block_device=${disk_id} partitions=${part_id})
vg_id=$(echo $vg_create | jq .id)
vg_size=$(echo $vg_create | jq .size)
vg_id=$(echo $vg_create | jq -r .id)
vg_size=$(echo $vg_create | jq -r .size)
else
vg_update=$(maas ${maas_profile} volume-group update ${system_id} ${vg_id} add_partitions=${part_id})
vg_size=$(echo $vg_update | jq .size)
vg_size=$(echo $vg_update | jq -r .size)
fi
done
lv_create=$(maas admin volume-group create-logical-volume ${system_id} ${vg_id} name=images size=${vg_size})
lv_id=$(echo $lv_create | jq .id)
lv_id=$(echo $lv_create | jq -r .id)
lv_fs=$(maas ${maas_profile} block-device format ${system_id} ${lv_id} fstype=ext4)
lv_mount=$(maas ${maas_profile} block-device mount ${system_id} ${lv_id} mount_point=${storage_path})
}
@@ -118,7 +118,7 @@ maas_create_partitions()
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_id=$(echo $pod_create | jq -r .id)
pod_name=$(maas ${maas_profile} pod update ${pod_id} name=${hypervisor_name})
}

View File

@@ -26,7 +26,7 @@ maas_auto_assign_networks()
# Grabs all the interfaces that are attached to the system
node_interfaces=$(maas ${maas_profile} interfaces read ${system_id} \
| jq ".[] | {id:.id, name:.name, mode:.links[].mode, subnet:.links[].subnet.id, vlan:.vlan.vid }" --compact-output)
| jq -c ".[] | {id:.id, name:.name, mode:.links[].mode, subnet:.links[].subnet.id, vlan:.vlan.vid }")
# This for loop will go through all the interfaces and enable Auto-Assign
# on all ports
@@ -42,8 +42,8 @@ maas_auto_assign_networks()
# the subnet details from subnets that have the vlan assigned/discovered
# at commissioning stage
if [[ $subnet_id == null ]] ; then
subnet_line=$(maas admin subnets read | jq ".[] | {subnet_id:.id, vlan:.vlan.vid, vlan_id:.vlan.id}" --compact-output | grep "vlan\":$vlan,")
subnet_id=$(echo $subnet_line | jq .subnet_id | sed s/\"//g)
subnet_line=$(maas admin subnets read | jq -c ".[] | {subnet_id:.id, vlan:.vlan.vid, vlan_id:.vlan.id}" | grep "vlan\":$vlan,")
subnet_id=$(echo $subnet_line | jq -r .subnet_id)
fi
# If vlan is the external network, then we want to grab IP via DHCP
# from the external network. Other networks would be auto mode
@@ -86,35 +86,35 @@ maas_create_partitions()
# Grab the first disk, typically /dev/sda
blk_device=$(maas ${maas_profile} block-devices read ${system_id} | jq ".[] | select(.name == \"sda\")")
blk_device_id=$(echo $blk_device | jq .id)
blk_device_id=$(echo $blk_device | jq -r .id)
# create /boot/efi partition, just in-case we are using a uEFI based VM
boot_size=512
size=$(( ${boot_size} * 1024 * 1024 ))
boot_part=$(maas ${maas_profile} partitions create ${system_id} ${blk_device_id} size=$size)
boot_part_id=$(echo $boot_part | jq .id)
boot_part_id=$(echo $boot_part | jq -r .id)
boot_format=$(maas ${maas_profile} partition format ${system_id} ${blk_device_id} ${boot_part_id} fstype=fat32)
boot_mount=$(maas ${maas_profile} partition mount ${system_id} ${blk_device_id} ${boot_part_id} mount_point=/boot/efi)
# Create the volume group for the rest of the partitions
vg_part=$(maas ${maas_profile} partitions create ${system_id} ${blk_device_id})
vg_part_id=$(echo $vg_part | jq .id)
vg_part_id=$(echo $vg_part | jq -r .id)
vg_create=$(maas ${maas_profile} volume-groups create ${system_id} name=${vg_name} partitions=${vg_part_id})
vg_id=$(echo $vg_create | jq .id)
vg_id=$(echo $vg_create | jq -r .id)
for part in ${!parts[@]}; do
if [[ ${part_size[$part]} == "remaining" ]] ; then
size=$(maas ${maas_profile} volume-group read ${system_id} ${vg_id} | jq ".available_size" | sed s/\"//g)
size=$(maas ${maas_profile} volume-group read ${system_id} ${vg_id} | jq -r ".available_size")
else
size=$(( ${part_size[$part]} * 1024 * 1024 * 1024 ))
fi
lv_create=$(maas ${maas_profile} volume-group create-logical-volume ${system_id} ${vg_id} name=${part} size=${size})
lv_block_id=$(echo ${lv_create} | jq .id)
lv_block_id=$(echo ${lv_create} | jq -r .id)
stg_fs=$(maas ${maas_profile} block-device format ${system_id} ${lv_block_id} fstype=ext4)
stg_mount=$(maas ${maas_profile} block-device mount ${system_id} ${lv_block_id} mount_point=${parts[$part]})
@@ -171,7 +171,7 @@ do_nodes()
fi
system_id=$(maas_system_id ${virt_node})
status_name=$(maas ${maas_profile} machine read ${system_id} | jq ".status_name" | sed s/\"//g)
status_name=$(maas ${maas_profile} machine read ${system_id} | jq -r ".status_name")
if [[ ${status_name} == "Deployed" ]] ; then
case $function in
@@ -353,6 +353,9 @@ build_vms() {
# Now define the network definition
for ((net=0;net<${#net_type[@]};net++)); do
network_spec+=" --network=$net_prefix="${net_type[$net]}",model=$nic_model"
if [[ "${bridge_type}" == "ovs" ]] ; then
network_spec+=",virtualport_type=openvswitch"
fi
done
if [[ $juju_total -le $juju_count ]] ; then
@@ -565,3 +568,6 @@ while getopts ":cdjnprtwz" opt; do
;;
esac
done
# Cleanup
pkg_cleanup

View File

@@ -3,7 +3,7 @@
. configs/maas.config
for subnet in ${maas_subnets[*]} ; do
maas ${maas_profile} ipranges create type=reserved comment="Servers" start_ip="${subnet}.241" end_ip="${subnet}.254"
maas "${maas_profile}" ipranges create type=reserved comment="Servers" start_ip="${subnet}.241" end_ip="${subnet}.254"
done
maas ${maas_profile} ipranges create type=reserved comment="OpenStack VIPs" start_ip="${maas_ip_range}.211" end_ip="${maas_ip_range}.225"
maas "${maas_profile}" ipranges create type=reserved comment="OpenStack VIPs" start_ip="${maas_ip_range}.211" end_ip="${maas_ip_range}.225"

View File

@@ -26,6 +26,7 @@ packages:
- virtinst
- jq
- ksmtuned
- openvswitch-switch
snap:
commands: