mirror of
https://github.com/outbackdingo/matchbox.git
synced 2026-01-27 18:19:36 +00:00
105 lines
3.2 KiB
Bash
Executable File
105 lines
3.2 KiB
Bash
Executable File
#!/bin/bash
|
|
# Manage VM nodes which have a specific set of hardware attributes.
|
|
|
|
if [ "$EUID" -ne 0 ]
|
|
then echo "Please run as root"
|
|
exit
|
|
fi
|
|
|
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
|
|
source "${DIR}/common.sh"
|
|
|
|
function main {
|
|
case "$1" in
|
|
"create-docker") create_docker;;
|
|
"create-rkt") create_rkt;;
|
|
"create-uefi") create_uefi;;
|
|
"start") start;;
|
|
"reboot") reboot;;
|
|
"shutdown") shutdown;;
|
|
"poweroff") poweroff;;
|
|
"destroy") destroy;;
|
|
*)
|
|
usage
|
|
exit 2
|
|
;;
|
|
esac
|
|
}
|
|
|
|
function usage {
|
|
echo "USAGE: ${0##*/} <command>"
|
|
echo "Commands:"
|
|
echo -e "\tcreate-docker\tcreate libvirt nodes on the docker0 bridge"
|
|
echo -e "\tcreate-rkt\tcreate libvirt nodes on a rkt CNI metal0 bridge"
|
|
echo -e "\tcreate-uefi\tcreate UEFI libvirt nodes on the rkt CNI metal0 bridge"
|
|
echo -e "\tstart\t\tstart the libvirt nodes"
|
|
echo -e "\treboot\t\treboot the libvirt nodes"
|
|
echo -e "\tshutdown\tshutdown the libvirt nodes"
|
|
echo -e "\tpoweroff\tpoweroff the libvirt nodes"
|
|
echo -e "\tdestroy\t\tdestroy the libvirt nodes"
|
|
}
|
|
COMMON_VIRT_OPTS="--memory=1024 --vcpus=1 --os-type=linux --noautoconsole --pxe --disk pool=default,size=6 "
|
|
|
|
function create_docker {
|
|
virt-install --name $NODE1_NAME --network=bridge:docker0,mac=$NODE1_MAC $COMMON_VIRT_OPTS --boot=hd,network
|
|
virt-install --name $NODE2_NAME --network=bridge:docker0,mac=$NODE2_MAC $COMMON_VIRT_OPTS --boot=hd,network
|
|
virt-install --name $NODE3_NAME --network=bridge:docker0,mac=$NODE3_MAC $COMMON_VIRT_OPTS --boot=hd,network
|
|
virt-install --name $NODE4_NAME --network=bridge:docker0,mac=$NODE4_MAC $COMMON_VIRT_OPTS --boot=hd,network
|
|
}
|
|
|
|
function create_rkt {
|
|
virt-install --name $NODE1_NAME --network=bridge:metal0,mac=$NODE1_MAC $COMMON_VIRT_OPTS --boot=hd,network
|
|
virt-install --name $NODE2_NAME --network=bridge:metal0,mac=$NODE2_MAC $COMMON_VIRT_OPTS --boot=hd,network
|
|
virt-install --name $NODE3_NAME --network=bridge:metal0,mac=$NODE3_MAC $COMMON_VIRT_OPTS --boot=hd,network
|
|
virt-install --name $NODE4_NAME --network=bridge:metal0,mac=$NODE4_MAC $COMMON_VIRT_OPTS --boot=hd,network
|
|
}
|
|
|
|
function create_uefi {
|
|
virt-install --name $NODE1_NAME --network=bridge=metal0,model=e1000,mac=$NODE1_MAC $COMMON_VIRT_OPTS --boot=uefi,network
|
|
virt-install --name $NODE2_NAME --network=bridge=metal0,model=e1000,mac=$NODE2_MAC $COMMON_VIRT_OPTS --boot=uefi,network
|
|
virt-install --name $NODE3_NAME --network=bridge=metal0,model=e1000,mac=$NODE3_MAC $COMMON_VIRT_OPTS --boot=uefi,network
|
|
virt-install --name $NODE4_NAME --network=bridge=metal0,model=e1000,mac=$NODE4_MAC $COMMON_VIRT_OPTS --boot=uefi,network
|
|
}
|
|
|
|
nodes=(node1 node2 node3 node4)
|
|
|
|
function start {
|
|
for node in ${nodes[@]}; do
|
|
virsh start $node
|
|
done
|
|
}
|
|
|
|
function reboot {
|
|
for node in ${nodes[@]}; do
|
|
virsh reboot $node
|
|
done
|
|
}
|
|
|
|
function shutdown {
|
|
for node in ${nodes[@]}; do
|
|
virsh shutdown $node
|
|
done
|
|
}
|
|
|
|
function poweroff {
|
|
for node in ${nodes[@]}; do
|
|
virsh destroy $node
|
|
done
|
|
}
|
|
|
|
function destroy {
|
|
for node in ${nodes[@]}; do
|
|
virsh destroy $node
|
|
done
|
|
for node in ${nodes[@]}; do
|
|
virsh undefine $node
|
|
done
|
|
virsh pool-refresh default
|
|
for node in ${nodes[@]}; do
|
|
virsh vol-delete --pool default $node.qcow2
|
|
done
|
|
}
|
|
|
|
main $@
|