-
Notifications
You must be signed in to change notification settings - Fork 1
/
boot_cluster
executable file
·85 lines (73 loc) · 2.7 KB
/
boot_cluster
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
#!/bin/bash
set -e
export LIBVIRT_DEFAULT_URI=qemu:///system
POOL=default
NB_INST=${1:-5}
cd "$(dirname $0)"
POOL_PATH=$(virsh pool-dumpxml $POOL | xmllint --xpath "/pool/target/path/child::text()" -)
#
# Check that we already have a pristine qemu image of CoreOS
#
virsh pool-refresh $POOL > /dev/null
if ! virsh vol-list $POOL | grep -q coreos_production_qemu_image.img; then
POOL_TYPE=$(virsh pool-dumpxml $POOL | xmllint --xpath "/pool/attribute::type" -)
if [ "$POOL_TYPE" != " type=\"dir\"" ]; then
echo "coreos_production_qemu_image.img volume doesn’t exist in the “$POOL” storage pool" >&2
exit 1
fi
echo "Please run the following command (may require root privileges):"
echo "curl http://alpha.release.core-os.net/amd64-usr/current/coreos_production_qemu_image.img.bz2 | bzcat > \"$POOL_PATH/coreos_production_qemu_image.img\""
exit 1
fi
#
# Check that we have rights to create user_data
#
if [ ! -w "$POOL_PATH/coreos_configdrive" ]; then
echo "Please run the following command (may require root privileges):"
echo "mkdir \"$POOL_PATH/coreos_configdrive\""
echo "chmod 777 \"$POOL_PATH/coreos_configdrive\""
exit 1
fi
#
# Create the networks
#
virsh net-create network_kubernetes_1.xml
virsh net-create network_kubernetes_2.xml
#
# Create the VMs
#
discovery=$(curl -s https://discovery.etcd.io/new)
rm -rf .run
mkdir .run
for (( i = 1 ; i <= $NB_INST ; i++ )); do
name=coreos$(printf "%02d" $i)
image="$POOL_PATH/$name.img"
config="$POOL_PATH/coreos_configdrive/$name"
kub_path="$POOL_PATH/kubernetes"
machines="$(echo -n '192.168.10.1'; for (( i = 2 ; i <= $NB_INST ; i++ )); do echo -n ",192.168.10.$i"; done)"
if [ -w "$POOL_PATH" ]; then
pushd "$POOL_PATH"
qemu-img create -f qcow2 -b coreos_production_qemu_image.img $name.img
popd
else
echo "You miss write access to $POOL_PATH to benefit from COW"
virsh vol-clone coreos_production_qemu_image.img $name.img --pool $POOL
fi
sed -e "s|%N%|$i|; \
s|%NAME%|$name|; \
s|%IMAGE%|$image|; \
s|%CONFIG%|$config|; \
s|%KUB_PATH%|$kub_path|" < coreos.xml > .run/$name.xml
mkdir -p "$config/openstack/latest"
sed -e "s|%N%|$i|; \
s|%NAME%|$name|; \
s|%SSH_KEYS%|$(cat ~/.ssh/id_*.pub | sed 's/^/ - /')|; \
s|%DISCOVERY%|$discovery|; \
s|%MACHINES%|$machines|" < user_data.yml | \
( if [ $i -eq 1 ]; then
egrep -v "^%(END)?IF MASTER%$" ;
else
awk 'BEGIN {inside=0} /^%IF MASTER%$/ {inside=1} !inside {print} /^%ENDIF MASTER%$/ {inside=0}'
fi ) > "$config/openstack/latest/user_data"
virsh create .run/$name.xml
done