/
libvirt
executable file
·92 lines (79 loc) · 3.17 KB
/
libvirt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/bash -e
# Manage four VM nodes which have a specific set of hardware attributes.
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi
function main {
case "$1" in
"create-docker") create_docker;;
"create-rkt") create_rkt;;
"start") start;;
"reboot") reboot;;
"shutdown") shutdown;;
"poweroff") poweroff;;
"destroy") destroy;;
"delete-disks") delete_disks;;
*)
usage
exit 2
;;
esac
}
function usage {
echo "USAGE: ${0##*/} <command>"
echo "Commands:"
echo -e "\tcreate-docker\tcreate 4 libvirt nodes on the docker0 bridge"
echo -e "\tcreate-rkt\tcreate 4 libvirt nodes on a rkt CNI metal0 bridge"
echo -e "\tstart\t\tstart the 4 libvirt nodes"
echo -e "\treboot\t\treboot the 4 libvirt nodes"
echo -e "\tshutdown\tshutdown the 4 libvirt nodes"
echo -e "\tpoweroff\tpoweroff the 4 libvirt nodes"
echo -e "\tdestroy\t\tdestroy the 4 libvirt nodes"
echo -e "\tdelete-disks\tdelete the allocated disks"
}
function create_docker {
virt-install --name node1 -u 16e7d8a7-bfa9-428b-9117-363341bb330b --pxe --disk pool=default,size=6 --boot=hd,network --network=bridge:docker0 --memory=1024 --vcpus=1 --os-type=linux --noautoconsole
virt-install --name node2 -u 264cd073-ca62-44b3-98c0-50aad5b5f819 --pxe --disk pool=default,size=6 --boot=hd,network --network=bridge:docker0 --memory=1024 --vcpus=1 --os-type=linux --noautoconsole
virt-install --name node3 -u 39d2e747-2648-4d68-ae92-bbc70b245055 --pxe --disk pool=default,size=6 --boot=hd,network --network=bridge:docker0 --memory=1024 --vcpus=1 --os-type=linux --noautoconsole
virt-install --name node4 -u 4ed46e8e-db69-471e-b874-0990dd65649d --pxe --disk pool=default,size=6 --boot=hd,network --network=bridge:docker0 --memory=1024 --vcpus=1 --os-type=linux --noautoconsole
}
function create_rkt {
virt-install --name node1 -u 16e7d8a7-bfa9-428b-9117-363341bb330b --pxe --disk pool=default,size=6 --boot=hd,network --network=bridge:metal0 --memory=1024 --vcpus=1 --os-type=linux --noautoconsole
virt-install --name node2 -u 264cd073-ca62-44b3-98c0-50aad5b5f819 --pxe --disk pool=default,size=6 --boot=hd,network --network=bridge:metal0 --memory=1024 --vcpus=1 --os-type=linux --noautoconsole
virt-install --name node3 -u 39d2e747-2648-4d68-ae92-bbc70b245055 --pxe --disk pool=default,size=6 --boot=hd,network --network=bridge:metal0 --memory=1024 --vcpus=1 --os-type=linux --noautoconsole
virt-install --name node4 -u 4ed46e8e-db69-471e-b874-0990dd65649d --pxe --disk pool=default,size=6 --boot=hd,network --network=bridge:metal0 --memory=1024 --vcpus=1 --os-type=linux --noautoconsole
}
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 undefine $node
done
}
function delete_disks {
virsh pool-refresh default
for node in ${nodes[@]}; do
virsh vol-delete --pool default $node.qcow2
done
}
main $@