-function cleanup_vms {
- # clean up existing nodes
- for node in $(virsh list --name | grep -P '\w{3}\d{2}'); do
- virsh destroy "${node}"
- done
- for node in $(virsh list --name --all | grep -P '\w{3}\d{2}'); do
- virsh domblklist "${node}" | awk '/^.da/ {print $2}' | \
- xargs --no-run-if-empty -I{} sudo rm -f {}
- virsh undefine "${node}" --remove-all-storage --nvram
- done
-}
-
-function prepare_vms {
- local base_image=$1; shift
- local image_dir=$1; shift
- local repos_pkgs_str=$1; shift # ^-sep list of repos, pkgs to install/rm
- local vnodes=("$@")
- local image=base_image_opnfv_fuel.img
-
- cleanup_uefi
- cleanup_vms
- get_base_image "${base_image}" "${image_dir}"
-
- rm -f "${image_dir}/${image%.*}"*
- if [[ ! "${repos_pkgs_str}" =~ ^\^+$ ]]; then
- IFS='^' read -r -a repos_pkgs <<< "${repos_pkgs_str}"
- cp "${image_dir}/${base_image/*\/}" "${image_dir}/${image}"
- mount_image "${image}" "${image_dir}"
- apt_repos_pkgs_image "${repos_pkgs[@]:0:4}"
- cleanup_mounts
- else
- ln -sf "${image_dir}/${base_image/*\/}" "${image_dir}/${image}"
- fi
-
- # CWD should be <mcp/scripts>
- # shellcheck disable=SC2016
- envsubst '${SALT_MASTER},${CLUSTER_DOMAIN}' < \
- user-data.template > user-data.sh
-
- # Create config ISO and resize OS disk image for each foundation node VM
- for node in "${vnodes[@]}"; do
- ./create-config-drive.sh -k "$(basename "${SSH_KEY}").pub" -u user-data.sh \
- -h "${node}" "${image_dir}/mcp_${node}.iso"
- cp "${image_dir}/${image}" "${image_dir}/mcp_${node}.qcow2"
- qemu-img resize "${image_dir}/mcp_${node}.qcow2" 100G
- done
-
- # VCP VMs base image specific changes
- if [[ ! "${repos_pkgs_str}" =~ \^{3}$ ]] && [ -n "${repos_pkgs[*]:4}" ]; then
- mount_image "${image}" "${image_dir}"
- apt_repos_pkgs_image "${repos_pkgs[@]:4:4}"
- cleanup_mounts
- ln -sf "${image_dir}/${image}" "${image_dir}/${image%.*}_vcp.img"
- fi
-}
-
-function create_networks {
- local vnode_networks=("$@")
- # create required networks, including constant "mcpcontrol"
- # FIXME(alav): since we renamed "pxe" to "mcpcontrol", we need to make sure
- # we delete the old "pxe" virtual network, or it would cause IP conflicts.
- for net in "pxe" "mcpcontrol" "${vnode_networks[@]}"; do
- if virsh net-info "${net}" >/dev/null 2>&1; then
- virsh net-destroy "${net}" || true
- virsh net-undefine "${net}"
- fi
- # in case of custom network, host should already have the bridge in place
- if [ -f "net_${net}.xml" ] && [ ! -d "/sys/class/net/${net}/bridge" ]; then
- virsh net-define "net_${net}.xml"
- virsh net-autostart "${net}"
- virsh net-start "${net}"
- fi
- done
-}
-
-function create_vms {
- local image_dir=$1; shift
- # vnode data should be serialized with the following format:
- # '<name0>,<ram0>,<vcpu0>|<name1>,<ram1>,<vcpu1>[...]'
- IFS='|' read -r -a vnodes <<< "$1"; shift
- local vnode_networks=("$@")
-
- # AArch64: prepare arch specific arguments
- local virt_extra_args=""
- if [ "$(uname -i)" = "aarch64" ]; then
- # No Cirrus VGA on AArch64, use virtio instead
- virt_extra_args="$virt_extra_args --video=virtio"