-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-ostack-nodes.sh
179 lines (139 loc) · 4.34 KB
/
create-ostack-nodes.sh
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/bin/bash
PROGNAME=`basename $0`
CONTROLLER_NAME=$1
CONTROLLER_DISK_SIZE=$2
CONTROLLER_MEM=$3
COMPUTE_NAME=$4
COMPUTE_DISK_SIZE=$5
COMPUTE_MEM=$6
ROOTPW=$7
IMAGES_HOME=/var/lib/libvirt/images
CONTROLLER_IMAGE=$IMAGES_HOME/$CONTROLLER_NAME.qcow2
COMPUTE_IMAGE=$IMAGES_HOME/$COMPUTE_NAME.qcow2
usage () {
echo -e "
***NOTE***: Ensure you have at-least 100G free disk space and
10G of free memory available before you invoke
this script.
Usage: ./$PROGNAME CONTROLLER_NAME CONTROLLER_DISK_SIZE \\ \n \
CONTROLLER_MEM COMPUTE_NAME \\ \n \
COMPUTE_DISK_SIZE COMPUTE_MEM ROOTPW
This script aims to setup two virtual machines -- first one, an
OpenStack Controller node; second one, OpenStack Compute node.
Examples:
Create a Controller node with 40G disk, 4096MB memory and
a Compute node with 50G disk, 6144MB memory with root
password as 'fedora':
./$PROGNAME controller 40G 4096 compute 50G 6144 fedora
Create a Controller node with 80G disk, 4096MB memory and
a Compute node with 120G disk, 8192MB memory, with root
password as 'fedora':
./$PROGNAME controller 80G 4096 compute 120G 8192 fedora
"
}
# This must be run as root
check_if_root() {
if [ `id -u` -ne 0 ] ; then
echo "Please run as 'root' to execute $PROGNAME."
exit 1
fi
}
# Check free memory on the host
check_free_mem() {
echo "Checking for free memory on your host. . ."
FREEMEM=$(free -m | awk 'NR==3 {print $4}')
if [ "$FREEMEM" -lt "10000" ]; then
echo "Please ensure you have at-least 10G of free memory"
exit 255
fi
}
set_root_passwd() {
# Create a secure tmp directory
tmp=`(umask 077 && mktemp "vmpwdXXXXXXX") 2>/dev/null` && test $tmp
echo "Create root password for virtual machines. . ."
echo $ROOTPW > $tmp
}
create_nodes() {
# Create Controller node
echo "Preparing Controller node disk image. . ."
virt-builder fedora-20 \
--update \
--selinux-relabel \
--format qcow2 \
--size $CONTROLLER_DISK_SIZE \
--root-password file:$tmp \
-o $IMAGES_HOME/$CONTROLLER_NAME.qcow2
# Create Compute node
echo "Preparing Compute node disk image. . ."
virt-builder fedora-20 \
--update \
--selinux-relabel \
--format qcow2 \
--size $COMPUTE_DISK_SIZE \
--root-password file:$tmp \
-o $IMAGES_HOME/$COMPUTE_NAME.qcow2
rm $tmp
return 0
}
# FIXME: Import with openstack libvirt networks
import_nodes_into_libvirt() {
# Import the virtual machines into libvirt
echo "Importing Controller and Compute images into libvirt. . ."
virt-install --name controller \
--ram $CONTROLLER_MEM \
--disk path=$CONTROLLER_IMAGE,format=qcow2 \
--import --noautoconsole --noreboot
# Import the Compute node disk image into libvirt
virt-install --name compute \
--ram $COMPUTE_MEM \
--disk path=$COMPUTE_IMAGE,format=qcow2 \
--import --noautoconsole --noreboot
return 0
}
check_kvm_nesting() {
CHECK_NESTING=$(cat /sys/module/kvm_intel/parameters/nested)
if [ "$CHECK_NESTING" != "Y" ]; then
echo "Please ensure you enable nested virt"
echo "To enable nested virt, add 'options kvm-intel nested=y'
(without quotes) to '/etc/modprobe.d/dist.conf', & reboot the
host."
exit 255
fi
}
enable_nested_virt() {
echo "Setup netsted virt on Compute host. . ."
virt-xml compute \
--edit \
--cpu host-passthrough,clearxml=yes
}
create_snapshot() {
# Take snapshots
echo "Taking snapshots. . ."
virsh snapshot-create-as \
controller snap1 "Pristine Fedora"
virsh snapshot-create-as \
compute snap1 "Pristine Fedora"
return 0
}
start_nodes() {
echo "Starting Controller and Compute nodes. . ."
virsh start controller
virsh start compute
}
# main()
{
# check if min no. of arguments are 6
if [ "$#" != 7 ]; then
usage
exit 255
fi
check_if_root
check_free_mem
set_root_passwd
create_nodes
import_nodes_into_libvirt
check_kvm_nesting
enable_nested_virt
create_snapshot
start_nodes
}