Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make baremetal targets more resilient to re-running #1004

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 40 additions & 7 deletions devsetup/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ BMAAS_ROUTE_LIBVIRT_NETWORKS ?= ${BMAAS_NETWORK_NAME},crc,default
DATAPLANE_PLAYBOOK ?= osp.edpm.download_cache
DATAPLANE_CUSTOM_SERVICE_RUNNER_IMG ?=quay.io/openstack-k8s-operators/openstack-ansibleee-runner:latest
BM_NETWORK_NAME ?=default
BM_INSTANCE_NAME_PREFIX ?=edpm-compute
BM_INSTANCE_NAME_PREFIX ?=edpm-compute-baremetal
BM_INSTANCE_NAME_SUFFIX ?=0
BM_NODE_COUNT ?=1
BM_ROOT_PASSWORD_SECRET ?=
BMH_NAMESPACE ?=openstack
Expand Down Expand Up @@ -377,25 +378,39 @@ edpm_baremetal_compute: export OPERATOR_NAME=openstack
edpm_baremetal_compute: export NAMESPACE=${BMH_NAMESPACE}
edpm_baremetal_compute: export BMAAS_NETWORK_NAME=${BM_NETWORK_NAME}
edpm_baremetal_compute: export BMAAS_INSTANCE_NAME_PREFIX=${BM_INSTANCE_NAME_PREFIX}
edpm_baremetal_compute: export BMAAS_INSTANCE_NAME_SUFFIX=${BM_INSTANCE_NAME_SUFFIX}
edpm_baremetal_compute: export BMAAS_NODE_COUNT=${BM_NODE_COUNT}
edpm_baremetal_compute: export NODE_COUNT=${BM_NODE_COUNT}
edpm_baremetal_compute: export DEPLOY_DIR=../out/bmaas
edpm_baremetal_compute: ## Create virtual baremetal for the dataplane
$(eval $(call vars))
make bmaas_virtual_bms
make bmaas_sushy_emulator_wait
bash scripts/edpm-compute-baremetal.sh --create
if [ "${NODE_COUNT}" = "1" ]; then \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though you can now re-run to create additional BMHs, as we cleanup the existing OpenstackDataPlaneNodeSet/OpenStackDataPlaneDeployments with edpm_deploy_cleanup[1] that would deprovision the all existing BMHs as well, before provisioning them again.

[1] https://github.com/openstack-k8s-operators/install_yamls/blob/main/Makefile#L922

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true. I would actually drop the cleanup deps from edpm_baremetal_deploy and edpm_deploy. I usually use the existing resources already written out, customize them as needed, and use them with oc directly. I guess it depends how far we want to take it in terms of making the targets work without cleanup or making them re-runnable.

bash scripts/edpm-compute-baremetal.sh --create ; \
else \
for INDEX in $(shell seq 0 $$((${NODE_COUNT} -1))) ; do \
export BMAAS_INSTANCE_NAME_SUFFIX=$$INDEX ; \
bash scripts/edpm-compute-baremetal.sh --create ; \
done \
fi

edpm_baremetal_compute_cleanup: export BMAAS_NETWORK_NAME=${BM_NETWORK_NAME}
edpm_baremetal_compute_cleanup: export NAMESPACE=${BMH_NAMESPACE}
edpm_baremetal_compute_cleanup: export BMAAS_INSTANCE_NAME_PREFIX=${BM_INSTANCE_NAME_PREFIX}
edpm_baremetal_compute_cleanup: export BMAAS_INSTANCE_NAME_SUFFIX=${BM_INSTANCE_NAME_SUFFIX}
edpm_baremetal_compute_cleanup: export BMAAS_NODE_COUNT=${BM_NODE_COUNT}
edpm_baremetal_compute_cleanup: export NODE_COUNT=${BM_NODE_COUNT}
edpm_baremetal_compute_cleanup: ## Cleanup dataplane with BMAAS
$(eval $(call vars))
scripts/edpm-compute-baremetal.sh --cleanup
pushd .. && rm -Rf out/edpm || true && popd
make bmaas_sushy_emulator_cleanup || true
if [ "${NODE_COUNT}" = "1" ]; then \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we're changing the name of the vms and bmhs, cleanup won't work with things created with earlier version of the script. They have to be manually deleted.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that would still be possible with using the env vars to set the names. However, I don't think we need to maintain backwards compatibility here anyway.

bash scripts/edpm-compute-baremetal.sh --cleanup ; \
else \
for INDEX in $(shell seq 0 $$((${NODE_COUNT} -1))) ; do \
export BMAAS_INSTANCE_NAME_SUFFIX=$$INDEX ; \
bash scripts/edpm-compute-baremetal.sh --cleanup ; \
done \
fi
make bmaas_virtual_bms_cleanup || true

.PHONY: edpm_compute
Expand Down Expand Up @@ -662,27 +677,42 @@ bmaas_metallb_cleanup:
bmaas_virtual_bms: export NODE_COUNT = ${BMAAS_NODE_COUNT}
bmaas_virtual_bms: export NETWORK_NAME = ${BMAAS_NETWORK_NAME}
bmaas_virtual_bms: export NODE_NAME_PREFIX = ${BMAAS_INSTANCE_NAME_PREFIX}
bmaas_virtual_bms: export NODE_NAME_SUFFIX = ${BMAAS_INSTANCE_NAME_SUFFIX}
bmaas_virtual_bms: export MEMORY = ${BMAAS_INSTANCE_MEMORY}
bmaas_virtual_bms: export VCPUS = ${BMAAS_INSTANCE_VCPUS}
bmaas_virtual_bms: export DISK_SIZE = ${BMAAS_INSTANCE_DISK_SIZE}
bmaas_virtual_bms: export OS_VARIANT = ${BMAAS_INSTANCE_OS_VARIANT}
bmaas_virtual_bms: export VIRT_TYPE = ${BMAAS_INSTANCE_VIRT_TYPE}
bmaas_virtual_bms: export NET_MODEL = ${BMAAS_INSTANCE_NET_MODEL}
bmaas_virtual_bms: ## Create libvirt VM for BMaaS
scripts/bmaas/vbm-setup.sh --create
if [ ${NODE_COUNT} -eq 1 ]; then \
scripts/bmaas/vbm-setup.sh --create ; \
else \
for INDEX in $(shell seq 0 $$((${NODE_COUNT} -1))) ; do \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling these scripts as many times as the number of nodes is possibly little inefficient, though does not matter probably as no one would be deploying large number of nodes with install_yamls.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to iterate in the Makefile though? The vbm-setup.sh takes a NODE_COUNT env var and iterates within the script itself:
https://github.com/openstack-k8s-operators/install_yamls/blob/main/devsetup/scripts/bmaas/vbm-setup.sh#L166-L170

https://github.com/openstack-k8s-operators/install_yamls/blob/main/devsetup/scripts/bmaas/vbm-setup.sh#L145-L147

if [ ${NODE_COUNT} -eq 1 ]; then \
 		scripts/bmaas/vbm-setup.sh --create ; \
 	else
 	        scripts/bmaas/vbm-setup.sh --create --num-nodes $NODE_COUNT
fi

Then we can just handle the NODE_NAME_SUFFIX in the script?

Just avoids re-running the script like Rabi is mentioning/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the whole check isn't really needed in that scenario actually, because NODE_COUNT would just be handled in the script anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR changes vbm-setup.sh to drop --num-nodes, so it manages just a single VM. That change is already included in this PR. Are you asking me to drop that change from the PR? The only inefficient part of calling the script twice would be setting up the libvirt logging, not really something I'd optimize in a dev repo, but we can go back to the way it was if that is wanted.

gen-edpm-node.sh manages 1 vm at a time. That is used for networker and bootc vms already, with the Makefile controlling the looping. So, I was changing the baremetal scripts to work in a similar way.

gen-edpm-node-bgp.sh is hardcoded to manage 3 at a time, so that's a different way as well.

Whichever way it's done, I'd like to see these things consistent.

set -x ; \
NODE_NAME_SUFFIX=$$INDEX scripts/bmaas/vbm-setup.sh --create ; \
done \
fi

.PHONY: bmaas_virtual_bms_cleanup
bmaas_virtual_bms_cleanup: export NODE_COUNT = ${BMAAS_NODE_COUNT}
bmaas_virtual_bms_cleanup: export NETWORK_NAME = ${BMAAS_NETWORK_NAME}
bmaas_virtual_bms_cleanup: export NODE_NAME_PREFIX = ${BMAAS_INSTANCE_NAME_PREFIX}
bmaas_virtual_bms_cleanup: export NODE_NAME_SUFFIX = ${BMAAS_INSTANCE_NAME_SUFFIX}
bmaas_virtual_bms_cleanup: export MEMORY = ${BMAAS_INSTANCE_MEMORY}
bmaas_virtual_bms_cleanup: export VCPUS = ${BMAAS_INSTANCE_VCPUS}
bmaas_virtual_bms_cleanup: export DISK_SIZE = ${BMAAS_INSTANCE_DISK_SIZE}
bmaas_virtual_bms_cleanup: export OS_VARIANT = ${BMAAS_INSTANCE_OS_VARIANT}
bmaas_virtual_bms_cleanup: export VIRT_TYPE = ${BMAAS_INSTANCE_VIRT_TYPE}
bmaas_virtual_bms_cleanup: export NET_MODEL = ${BMAAS_INSTANCE_NET_MODEL}
bmaas_virtual_bms_cleanup: ## Cleanup libvirt VM for BMaaS
scripts/bmaas/vbm-setup.sh --cleanup
if [ ${NODE_COUNT} -eq 1 ]; then \
scripts/bmaas/vbm-setup.sh --cleanup ; \
else \
for INDEX in $(shell seq 0 $$((${NODE_COUNT} -1))) ; do \
NODE_NAME_SUFFIX=$$INDEX scripts/bmaas/vbm-setup.sh --cleanup ; \
done \
fi

.PHONY: bmaas_sushy_emulator
bmaas_sushy_emulator: export NODE_NAME_PREFIX = ${BMAAS_INSTANCE_NAME_PREFIX}
Expand All @@ -697,17 +727,20 @@ bmaas_sushy_emulator: export SUSHY_EMULATOR_OS_CLOUD = ${BMAAS_SUSHY_EMULATOR_OS
bmaas_sushy_emulator: export SUSHY_EMULATOR_OS_CLIENT_CONFIG_FILE = ${BMAAS_SUSHY_EMULATOR_OS_CLIENT_CONFIG_FILE}
bmaas_sushy_emulator: export REDFISH_USERNAME = ${BMAAS_REDFISH_USERNAME}
bmaas_sushy_emulator: export REDFISH_PASSWORD = ${BMAAS_REDFISH_PASSWORD}
bmaas_sushy_emulator: export DEPLOY_DIR=../out/bmaas
bmaas_sushy_emulator: ## Create BMaaS sushy-emulator (Virtual RedFish)
scripts/bmaas/sushy-emulator.sh --create

.PHONY: bmaas_sushy_emulator_cleanup
bmaas_sushy_emulator_cleanup: export NODE_NAME_PREFIX = ${BMAAS_INSTANCE_NAME_PREFIX}
bmaas_sushy_emulator_cleanup: export NODE_NAME_SUFFIX = ${BMAAS_INSTANCE_NAME_SUFFIX}
bmaas_sushy_emulator_cleanup: export LIBVIRT_USER = ${BMAAS_LIBVIRT_USER}
bmaas_sushy_emulator_cleanup: export SUSHY_EMULATOR_NAMESPACE = ${BMAAS_SUSHY_EMULATOR_NAMESPACE}
bmaas_sushy_emulator_cleanup: export SUSHY_EMULATOR_DRIVER = ${BMAAS_SUSHY_EMULATOR_DRIVER}
bmaas_sushy_emulator_cleanup: export SUSHY_EMULATOR_OS_CLOUD = ${BMAAS_SUSHY_EMULATOR_OS_CLOUD}
bmaas_sushy_emulator_cleanup: export REDFISH_USERNAME = ${BMAAS_REDFISH_USERNAME}
bmaas_sushy_emulator_cleanup: export REDFISH_PASSWORD = ${BMAAS_REDFISH_PASSWORD}
bmaas_sushy_emulator_cleanup: export DEPLOY_DIR=../out/bmaas
bmaas_sushy_emulator_cleanup: ## Cleanup BMaaS sushy-emulator (Virtual RedFish)
scripts/bmaas/sushy-emulator.sh --cleanup

Expand Down
73 changes: 44 additions & 29 deletions devsetup/scripts/bmaas/sushy-emulator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ function usage {
echo
}

MY_TMP_DIR="$(mktemp -d)"
trap 'rm -rf -- "$MY_TMP_DIR"' EXIT

NODE_NAME_PREFIX=${NODE_NAME_PREFIX:-"crc-bmaas"}
NAMESPACE=${SUSHY_EMULATOR_NAMESPACE:-"sushy-emulator"}
DRIVER=${SUSHY_EMULATOR_DRIVER:-"libvirt"}
Expand All @@ -27,6 +24,9 @@ IMAGE=${SUSHY_EMULATOR_IMAGE:-"quay.io/metal3-io/sushy-tools:latest"}
CRC_NETWORK_NAME=${CRC_NETWORK_NAME:-crc}
BM_IPV6=${BM_IPV6:-false}
BM_IPV4=${BM_IPV4:-false}
SUSHY_DIR=${SUSHY_DIR:-"${DEPLOY_DIR}/sushy"}

mkdir -p ${SUSHY_DIR}


if [ $DRIVER = "libvirt" ]; then
Expand Down Expand Up @@ -60,15 +60,15 @@ fi

function create_sushy_emulator_namespace {
echo "Creating namespace ${NAMESPACE}"
cat <<EOF > "${MY_TMP_DIR}/namespace.yaml"
cat <<EOF > "${SUSHY_DIR}/namespace.yaml"
apiVersion: v1
kind: Namespace
metadata:
name: ${NAMESPACE}
EOF

# cat ${MY_TMP_DIR}/namespace.yaml
oc apply -f "${MY_TMP_DIR}/namespace.yaml"
# cat ${SUSHY_DIR}/namespace.yaml
oc apply -f "${SUSHY_DIR}/namespace.yaml"
}

function create_sushy_emulator_user {
Expand All @@ -88,28 +88,39 @@ function generate_ssh_keypair {
echo "PANIC, unable to get ${LIBVIRT_USER} home directory."
exit 1
fi
ssh-keygen -q -f "${MY_TMP_DIR}/${SSH_KEY_FILE}" -N "" -t "${SSH_ALGORITHM}" -b "${SSH_KEY_SIZE}"
if [ ! -f "${SUSHY_DIR}/${SSH_KEY_FILE}" ]; then
ssh-keygen -q -f "${SUSHY_DIR}/${SSH_KEY_FILE}" -N "" -t "${SSH_ALGORITHM}" -b "${SSH_KEY_SIZE}"
else
echo "${SUSHY_DIR}/${SSH_KEY_FILE} already exists, not re-generating"
fi
sudo mkdir -p "${homedir}/.ssh"
sudo cp "${MY_TMP_DIR}/${SSH_KEY_FILE}" "${homedir}/.ssh/${SSH_KEY_FILE}"
sudo cp "${MY_TMP_DIR}/${SSH_KEY_FILE}.pub" "${homedir}/.ssh/${SSH_KEY_FILE}.pub"
sudo cp "${SUSHY_DIR}/${SSH_KEY_FILE}" "${homedir}/.ssh/${SSH_KEY_FILE}"
sudo cp "${SUSHY_DIR}/${SSH_KEY_FILE}.pub" "${homedir}/.ssh/${SSH_KEY_FILE}.pub"
sudo touch "${homedir}/.ssh/authorized_keys"
cat "${MY_TMP_DIR}/${SSH_KEY_FILE}.pub" | sudo tee "${homedir}/.ssh/authorized_keys" > /dev/null
cat "${SUSHY_DIR}/${SSH_KEY_FILE}.pub" | sudo tee "${homedir}/.ssh/authorized_keys" > /dev/null
sudo chown -R "${LIBVIRT_USER}":"${LIBVIRT_USER}" "${homedir}/.ssh"
sudo chmod 700 "${homedir}/.ssh"
sudo chmod -R og-rwx "${homedir}/.ssh"
}

function create_sushy_emulator_config {
echo "Creating sushy-emulator-config"
cat << EOF > "${MY_TMP_DIR}/config-map.yaml"
local htpasswd
if [ -f "${SUSHY_DIR}/htpasswd" ]; then
htpasswd=$(cat ${SUSHY_DIR}/htpasswd)
else
htpasswd=$(htpasswd -nbB "${REDFISH_USERNAME}" "${REDFISH_PASSWORD}")
echo ${htpasswd} > ${SUSHY_DIR}/htpasswd
fi
cat << EOF > "${SUSHY_DIR}/config-map.yaml"
apiVersion: v1
kind: ConfigMap
metadata:
name: sushy-emulator-config
namespace: ${NAMESPACE}
data:
htpasswd: |
$(htpasswd -nbB "${REDFISH_USERNAME}" "${REDFISH_PASSWORD}" | sed 's/^/ /')
${htpasswd}
config: |
# Listen on all local IP interfaces
SUSHY_EMULATOR_LISTEN_IP = ${SUSHY_EMULATOR_LISTEN_IP}
Expand Down Expand Up @@ -146,24 +157,24 @@ $(htpasswd -nbB "${REDFISH_USERNAME}" "${REDFISH_PASSWORD}" | sed 's/^/ /')
SUSHY_EMULATOR_ALLOWED_INSTANCES = ${INSTANCES}
EOF

# cat ${MY_TMP_DIR}/config-map.yaml
oc apply -f "${MY_TMP_DIR}/config-map.yaml"
# cat ${SUSHY_DIR}/config-map.yaml
oc apply -f "${SUSHY_DIR}/config-map.yaml"
}

function create_sushy_emulator_secret {
echo "Creating sushy-emulator-secret"
if [ $DRIVER = "libvirt" ]; then
cat << EOF > "${MY_TMP_DIR}/secret.yaml"
cat << EOF > "${SUSHY_DIR}/secret.yaml"
apiVersion: v1
kind: Secret
metadata:
name: sushy-emulator-secret
namespace: ${NAMESPACE}
data:
ssh-publickey: |
$(base64 < "${MY_TMP_DIR}/${SSH_KEY_FILE}.pub" | sed 's/^/ /')
$(base64 < "${SUSHY_DIR}/${SSH_KEY_FILE}.pub" | sed 's/^/ /')
ssh-privatekey: |
$(base64 < "${MY_TMP_DIR}/${SSH_KEY_FILE}" | sed 's/^/ /')
$(base64 < "${SUSHY_DIR}/${SSH_KEY_FILE}" | sed 's/^/ /')
ssh-known-hosts: |
$(ssh-keyscan -H "${LIBVIRT_IP_ADDRESS}" | base64 | sed 's/^/ /')
---
Expand All @@ -176,7 +187,7 @@ data:
openstack-clouds-yaml: ""
EOF
elif [ $DRIVER = "openstack" ]; then
cat << EOF > "${MY_TMP_DIR}/secret.yaml"
cat << EOF > "${SUSHY_DIR}/secret.yaml"
apiVersion: v1
kind: Secret
metadata:
Expand All @@ -198,13 +209,13 @@ $(cat ${OS_CLIENT_CONFIG_FILE} | base64 | sed 's/^/ /')
EOF
fi

# cat ${MY_TMP_DIR}/secret.yaml
oc apply -f "${MY_TMP_DIR}/secret.yaml"
# cat ${SUSHY_DIR}/secret.yaml
oc apply -f "${SUSHY_DIR}/secret.yaml"
}

function create_sushy_emulator_pod {
echo "Creating sushy-emulator pod"
cat << EOF > "${MY_TMP_DIR}/sushy-emulator-pod.yaml"
cat << EOF > "${SUSHY_DIR}/sushy-emulator-pod.yaml"
---
apiVersion: v1
kind: Pod
Expand Down Expand Up @@ -284,13 +295,15 @@ spec:
restartPolicy: OnFailure
EOF

# cat ${MY_TMP_DIR}/sushy-emulator-pod.yaml
oc apply -f "${MY_TMP_DIR}/sushy-emulator-pod.yaml"
# cat ${SUSHY_DIR}/sushy-emulator-pod.yaml
# delete existing pod to force reloading of any config changes
oc delete -n sushy-emulator --wait pod sushy-emulator
oc apply -f "${SUSHY_DIR}/sushy-emulator-pod.yaml"
}

function create_sushy_emulator_service {
echo "Creating sushy-emulator-service"
cat << EOF > "${MY_TMP_DIR}/sushy-emulator-service.yaml"
cat << EOF > "${SUSHY_DIR}/sushy-emulator-service.yaml"
---
apiVersion: v1
kind: Service
Expand All @@ -308,13 +321,13 @@ spec:
targetPort: 8000
EOF

# cat ${MY_TMP_DIR}/sushy-emulator-service.yaml
oc apply -f "${MY_TMP_DIR}/sushy-emulator-service.yaml"
# cat ${SUSHY_DIR}/sushy-emulator-service.yaml
oc apply -f "${SUSHY_DIR}/sushy-emulator-service.yaml"
}

function create_sushy_emulator_route {
echo "Creating sushy-emulator-route"
cat << EOF > "${MY_TMP_DIR}/sushy-emulator-route.yaml"
cat << EOF > "${SUSHY_DIR}/sushy-emulator-route.yaml"
---
apiVersion: route.openshift.io/v1
kind: Route
Expand All @@ -332,8 +345,8 @@ spec:
name: sushy-emulator-service
EOF

# cat ${MY_TMP_DIR}/sushy-emulator-route.yaml
oc apply -f "${MY_TMP_DIR}/sushy-emulator-route.yaml"
# cat ${SUSHY_DIR}/sushy-emulator-route.yaml
oc apply -f "${SUSHY_DIR}/sushy-emulator-route.yaml"
}

function create {
Expand Down Expand Up @@ -366,6 +379,8 @@ function cleanup {
echo "Not deleting user ${LIBVIRT_USER}, user does not exist"
fi
fi

rm -rf ${SUSHY_DIR}
}

case "$1" in
Expand Down
23 changes: 7 additions & 16 deletions devsetup/scripts/bmaas/vbm-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fi
SCRIPTPATH="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
NETWORK_NAME=${NETWORK_NAME:-"crc-bmaas"}
NODE_NAME_PREFIX=${NODE_NAME_PREFIX:-"crc-bmaas"}
NODE_COUNT=${NODE_COUNT:-"1"}
NODE_NAME_SUFFIX=${NODE_NAME_SUFFIX:-"0"}
ACTION=""

# Virtual Machine spec
Expand All @@ -37,7 +37,6 @@ function usage {
echo "options:"
echo " --create Create BMaaS virtual baremetal VMs"
echo " --cleanup Cleanup, delete BMaaS virtual baremteal VMs"
echo " --num-nodes Number of BMaaS virtual baremetal VMs to create (default: 1)"
echo
}

Expand Down Expand Up @@ -104,8 +103,8 @@ function cleanup_libvirt_logging {
function create_vm {
local temp_file
local name
name=$1
temp_file=$(mktemp -p "$MY_TMP_DIR")
name="$NODE_NAME_PREFIX-$(printf "%02d" "$i")"
echo "Creating VM: $name"
virt-install --connect qemu:///system \
--name "$name" \
Expand Down Expand Up @@ -142,17 +141,14 @@ function create {
echo "Network $NETWORK_NAME does not exist, please create it"
exit 1
fi
for (( i=1; i<=NODE_COUNT; i++ )); do
create_vm "$i"
done
vm="$NODE_NAME_PREFIX-$(printf "%02d" "${NODE_NAME_SUFFIX}")"
create_vm "$vm"
}

function cleanup {
local vms
vms=$(virsh --connect=qemu:///system list --all --name | grep "$NODE_NAME_PREFIX")
for vm in $vms; do
delete_vm "$vm"
done
local vm
vm="$NODE_NAME_PREFIX-$(printf "%02d" "${NODE_NAME_SUFFIX}")"
delete_vm "$vm"
}

while [[ "$#" -gt 0 ]]; do
Expand All @@ -163,11 +159,6 @@ while [[ "$#" -gt 0 ]]; do
"--cleanup")
ACTION="CLEANUP";
;;
"--num-nodes")
[[ $2 =~ ^[0-9]+$ ]] || { echo "Invalid value --num-nodes must be a number"; usage; exit 1; }
NODE_COUNT="$2";
shift
;;
*)
echo "Unknown parameter passed: $1";
usage
Expand Down
Loading