-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathdeploy_caasp.sh
executable file
·219 lines (192 loc) · 5.81 KB
/
deploy_caasp.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#!/bin/bash
function printHelp {
cat << EOF
Usage ${0##*/} [options..]
-m, --model <model> Which config.yml model to use for vm sizing
Default: "minimal"
-f, --full attempt to bring the machines up and deploy the cluster
-a, --air-gapped Setup CaaSP nodes with substitute registries (for deployment and/or private image access)
-i, --ignore-memory Don't prompt when over allocating memory
-t, --test Do a dry run, don't actually deploy the vms
-v, --verbose [uint8] Verbosity level to pass to skuba -v (default is 1)
-h,-?, --help Show help
EOF
}
# Get all models in the file
VALID_MODELS=`egrep '^[a-zA-Z]' config.yml |tr ':' ' '|tr -d '\r\n' `
function validate_model {
local result=0
if [[ " $VALID_MODELS " =~ .*\ $1\ .* ]]; then
result=1
fi
echo "$result"
}
function invalid_model {
echo "Invalid model option, must be one of '$VALID_MODELS'."
echo "Update config.yml if needed."
exit 1
}
CAASP_CONFIG_MODEL="minimal"
DO_MEMORY_CHECK=true
FULL_DEPLOYMENT=false
AIR_GAPPED=false
DO_DRY_RUN=false
PARAMS=""
while (( "$#" )); do
case "$1" in
-h|-\?|--help)
printHelp
exit
;;
-m|--model)
CAASP_CONFIG_MODEL=$2
shift 2
;;
-f|--full)
FULL_DEPLOYMENT=true
shift
;;
-a|--air-gapped)
AIR_GAPPED=true
shift
;;
-i|--ignore-memory)
DO_MEMORY_CHECK=false
shift
;;
-t|--test)
DO_DRY_RUN=true
shift
;;
-v|--verbose)
SKUBA_VERBOSITY=$2
shift 2
;;
--) # end argument parsing
shift
break
;;
-*|--*=) # unsupported flags
echo "Error: Unsupported flag $1" >&2
exit 1
;;
*) # preserve positional arguments
PARAMS="$PARAMS $1"
shift
;;
esac
done
# set positional arguments in their proper place
eval set -- "$PARAMS"
res=$(validate_model $CAASP_CONFIG_MODEL)
if [ "$res" -eq "0" ]; then
invalid_model
fi
# This is so Vagrantfile can read the
# selected model
export CAASP_CONFIG_MODEL
# read in the config.yml and write out the caasp_env.conf
source lib.sh
# Collect System Requirements
master_ram="${CAASP_CONFIG_MODEL}_nodes_master_memory"
master_cpus="${CAASP_CONFIG_MODEL}_nodes_master_cpus"
MASTERMEM=${!master_ram}
worker_ram="${CAASP_CONFIG_MODEL}_nodes_worker_memory"
worker_cpus="${CAASP_CONFIG_MODEL}_nodes_worker_cpus"
WORKERMEM=${!worker_ram}
lb_ram="${CAASP_CONFIG_MODEL}_nodes_loadbalancer_memory"
lb_cpus="${CAASP_CONFIG_MODEL}_nodes_loadbalancer_cpus"
LBMEM=${!lb_ram}
storage_ram="${CAASP_CONFIG_MODEL}_nodes_storage_memory"
storage_cpus="${CAASP_CONFIG_MODEL}_nodes_storage_cpus"
STORAGEMEM=${!storage_ram}
MEMNEEDED="$(($MASTERMEM * $NMASTERS + $WORKERMEM * $NWORKERS + $LBMEM * $NLOADBAL + $STORAGEMEM * $NSTORAGE))"
MEMHOST="$(free -m | awk 'NR==2{print $7}')"
if [[ $DO_MEMORY_CHECK == true ]]; then
# Check memory configuration with host
if [[ "$MEMNEEDED" -gt "$MEMHOST" ]]; then
read -r -p "The configuration needs ${MEMNEEDED}MB but the host only has ${MEMHOST}MB available, do you want to continue [y/N] " response
response=${response,,}
if [[ ! "$response" =~ ^(yes|y)$ ]]; then
exit 1
fi
fi
fi
echo "Deploy CAASP with the CAASP_CONFIG_MODEL=$CAASP_CONFIG_MODEL"
echo " Masters=$NMASTERS CPUS=${!master_cpus} MEM=$MASTERMEM"
echo " Workers=$NWORKERS CPUS=${!worker_cpus} MEM=$WORKERMEM"
echo " Load Balancers=$NLOADBAL CPUS=${!lb_cpus} MEM=$LBMEM"
echo " Storage Nodes=$NSTORAGE CPUS=${!storage_cpus} MEM=$STORAGEMEM"
total_cpus="$((${!master_cpus}*$NMASTERS + ${!worker_cpus}*$NWORKERS + ${!lb_cpus}*$NLOADBAL + ${!storage_cpus}*$NSTORAGE))"
total_mem="$(($MASTERMEM*$NMASTERS + $WORKERMEM*$NWORKERS + $LBMEM*$NLOADBAL + $STORAGEMEM*$NSTORAGE))"
echo "TOTALS CPU=$total_cpus MEM=$total_mem"
echo ""
if [[ $AIR_GAPPED == true ]]; then
# Check for required air-gapped config files
FILE=./air-gap.d/air-gapped-registries.conf
if [[ -f "$FILE" ]]; then
echo "Custom Air-gapped Registries configuration found!!"
echo "Configuring nodes for air-gap after VMs are up."
else
echo "Air-gap command-line option specified but missing required configuration file(s)."
echo "See ./air-gap.d/README.md for information."
echo "Exiting"
exit 1
fi
else
echo "Default registry location : ensure access to registry.suse.com for installation images"
fi
if [ "$FULL_DEPLOYMENT" == true ]; then
echo "Do full deployment after VMs are up."
else
echo "Not running deployment scripts after VMs are up."
fi
if [[ $DO_DRY_RUN == true ]]; then
echo "Dry run complete"
exit
fi
#
# Now do the work of standing up the vms
#
echo "Deploying $NMASTERS masters"
for m in $(seq ${NMASTERS})
do
vagrant up caasp4-master-${m}
done
echo "Deploying $NWORKERS workers"
for w in $(seq ${NWORKERS})
do
vagrant up caasp4-worker-${w}
done
echo "Deploying $NLOADBAL load balancers"
for l in $(seq ${NLOADBAL})
do
vagrant up caasp4-lb-${l}
done
echo "Deploying $NSTORAGE storage nodes"
for s in $(seq ${NSTORAGE})
do
vagrant up caasp4-storage-${s}
done
if [[ $AIR_GAPPED == true ]]; then
echo "Preparing Air-Gapped Setup..."
echo "Modifying Masters..."
for m in $(seq ${NMASTERS})
do
vagrant ssh caasp4-master-${m} -c 'sudo /vagrant/deploy/100.prep_airgap.sh'
done
echo "Modifying Workers..."
for w in $(seq ${NWORKERS})
do
vagrant ssh caasp4-worker-${w} -c 'sudo /vagrant/deploy/100.prep_airgap.sh'
done
echo "Finished Air-Gapped Setup."
fi
if [[ $FULL_DEPLOYMENT == true ]]; then
vagrant ssh caasp4-master-1 -c 'sudo su - sles -c /vagrant/deploy/99.run-all.sh'
fi
echo "Happy CaaSPing!"
echo "vagrant ssh caasp4-master-1"
echo "sudo su - sles"
echo "See scripts in the /vagrant/deploy directory for deployment guide steps"
echo "...or run $0 --full to have your cluster auto-deployed"