You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Licensed to the Apache Software Foundation (ASF) under one
5
4
# or more contributor license agreements. See the NOTICE file
@@ -20,15 +19,30 @@
20
19
21
20
22
21
usage() {
23
-
printf"Usage: %s:-m <secondary storage mount point> -f <system vm template file> [-h <hypervisor name: kvm|vmware|xenserver|hyperv|ovm3> ] [ -s <mgmt server secret key, if you specified any when running cloudstack-setup-database, default is password>][-u <Url to system vm template>] [-F <clean up system templates of specified hypervisor>] [-e <Template suffix, e.g vhd, ova, qcow2>] [-o <Database server hostname or ip, e.g localhost>] [-r <Database user name, e.g root>] [-p <mysql database port>] [-d <Database password. Fllowed by nothing if the password is empty>]\n"$(basename $0)>&2
24
-
printf"or\n">&2
25
-
printf"%s:-m <secondary storage mount point> -u <http url for system vm template> [-h <hypervisor name: kvm|vmware|xenserver|hyperv|ovm3> ] [ -s <mgmt server secret key>]\n"$(basename $0)>&2
22
+
printf"\nUsage: %s:\n\t-m secondary storage mount point\n\t-f system vm template file\n\t-h hypervisor name: kvm|vmware|xenserver|hyperv|ovm3\n\t-s mgmt server secret key, if you specified any when running cloudstack-setup-database, default is password\n\t-u Url to system vm template\n\t-F clean up system templates of specified hypervisor\n\t-e Template suffix, e.g vhd, ova, qcow2\n\t-o Database server hostname or ip, e.g localhost\n\t-r Database user name, e.g root\n\t-p mysql database port\n\t-d Database password. Followed by nothing if the password is empty\n\n"$(basename $0)>&2
23
+
printf"\tor\n"
24
+
printf"\nUsage: %s:\n\t-m secondary storage mount point\n\t-u http url for system vm template\n\t-h hypervisor name: kvm|vmware|xenserver|hyperv|ovm3\n\t-s mgmt server secret key\n\n"$(basename $0)>&2
26
25
}
27
26
27
+
# Usage: e.g. failed $? "this is an error"
28
28
failed() {
29
-
echo"Installation failed"
30
-
exit$1
29
+
local returnval=$1
30
+
local returnmsg=$2
31
+
32
+
# check for an message, if there is no one dont print anything
templateId=(`mysql -P $dbPort -h $dbHost --user=$dbUser --password=$dbPassword --skip-column-names -U cloud -e "select max(id) from cloud.vm_template where type = \"SYSTEM\" and hypervisor_type = \"KVM\" and removed is null"`)
166
-
elif [ "$hyper"=="xenserver" ]
167
-
then
168
-
ext="vhd"
169
-
templateId=(`mysql -P $dbPort -h $dbHost --user=$dbUser --password=$dbPassword --skip-column-names -U cloud -e "select max(id) from cloud.vm_template where type = \"SYSTEM\" and hypervisor_type = \"XenServer\" and removed is null"`)
170
-
elif [ "$hyper"=="vmware" ]
171
-
then
172
-
ext="ova"
173
-
templateId=(`mysql -P $dbPort -h $dbHost --user=$dbUser --password=$dbPassword --skip-column-names -U cloud -e "select max(id) from cloud.vm_template where type = \"SYSTEM\" and hypervisor_type = \"VMware\" and removed is null"`)
174
-
elif [ "$hyper"=="lxc" ]
175
-
then
176
-
ext="qcow2"
177
-
templateId=(`mysql -P $dbPort -h $dbHost --user=$dbUser --password=$dbPassword --skip-column-names -U cloud -e "select max(id) from cloud.vm_template where type = \"SYSTEM\" and hypervisor_type = \"LXC\" and removed is null"`)
178
-
elif [ "$hyper"=="hyperv" ]
179
-
then
180
-
ext="vhd"
181
-
templateId=(`mysql -P $dbPort -h $dbHost --user=$dbUser --password=$dbPassword --skip-column-names -U cloud -e "select max(id) from cloud.vm_template where type = \"SYSTEM\" and hypervisor_type = \"Hyperv\" and removed is null"`)
182
-
elif [ "$hyper"=="ovm3" ]
183
-
then
184
-
ext="raw"
185
-
templateId=(`mysql -P $dbPort -h $dbHost --user=$dbUser --password=$dbPassword --skip-column-names -U cloud -e "select max(id) from cloud.vm_template where type = \"SYSTEM\" and hypervisor_type = \"Ovm3\" and removed is null"`)
186
-
else
187
-
usage
188
-
failed 2
189
-
fi
164
+
if [[ "$templateId"=="" ]];then
165
+
if [[ "$hyper"=="kvm" ]];then
166
+
ext="qcow2"
167
+
templateId=(`mysql -P $dbPort -h $dbHost --user=$dbUser --password=$dbPassword --skip-column-names -U cloud -e "select max(id) from cloud.vm_template where type = \"SYSTEM\" and hypervisor_type = \"KVM\" and removed is null"`)
168
+
qemuimgcmd=$(which qemu-img)
169
+
elif [[ "$hyper"=="xenserver" ]];then
170
+
ext="vhd"
171
+
templateId=(`mysql -P $dbPort -h $dbHost --user=$dbUser --password=$dbPassword --skip-column-names -U cloud -e "select max(id) from cloud.vm_template where type = \"SYSTEM\" and hypervisor_type = \"XenServer\" and removed is null"`)
172
+
elif [[ "$hyper"=="vmware" ]];then
173
+
ext="ova"
174
+
templateId=(`mysql -P $dbPort -h $dbHost --user=$dbUser --password=$dbPassword --skip-column-names -U cloud -e "select max(id) from cloud.vm_template where type = \"SYSTEM\" and hypervisor_type = \"VMware\" and removed is null"`)
175
+
elif [[ "$hyper"=="lxc" ]];then
176
+
ext="qcow2"
177
+
templateId=(`mysql -P $dbPort -h $dbHost --user=$dbUser --password=$dbPassword --skip-column-names -U cloud -e "select max(id) from cloud.vm_template where type = \"SYSTEM\" and hypervisor_type = \"LXC\" and removed is null"`)
178
+
elif [[ "$hyper"=="hyperv" ]];then
179
+
ext="vhd"
180
+
templateId=(`mysql -P $dbPort -h $dbHost --user=$dbUser --password=$dbPassword --skip-column-names -U cloud -e "select max(id) from cloud.vm_template where type = \"SYSTEM\" and hypervisor_type = \"Hyperv\" and removed is null"`)
181
+
elif [[ "$hyper"=="ovm3" ]];then
182
+
ext="raw"
183
+
templateId=(`mysql -P $dbPort -h $dbHost --user=$dbUser --password=$dbPassword --skip-column-names -U cloud -e "select max(id) from cloud.vm_template where type = \"SYSTEM\" and hypervisor_type = \"Ovm3\" and removed is null"`)
184
+
else
185
+
failed 2 "Please add a correct hypervisor name like: kvm|vmware|xenserver|hyperv|ovm3"
186
+
fi
190
187
fi
191
188
192
-
if [ !$templateId ]
193
-
then
194
-
echo"Unable to get template Id from database"
195
-
failed 8
189
+
if [[ !$templateId ]];then
190
+
failed 2 "Unable to get template Id from database"
196
191
fi
197
192
198
193
_uuid=$(uuidgen)
@@ -205,43 +200,31 @@ mntpoint=`echo "$mntpoint" | sed 's|/*$||'`
205
200
destdir=$mntpoint/template/tmpl/1/$templateId/
206
201
207
202
mkdir -p $destdir
208
-
if [ $?-ne 0 ]
209
-
then
210
-
printf"Failed to write to mount point $mntpoint -- is it mounted?\n"
211
-
failed 3
203
+
if [[ $?-ne 0 ]];then
204
+
failed 2 "Failed to write to mount point $mntpoint -- is it mounted?\n"
212
205
fi
213
206
214
-
if [ "$Fflag"=="1" ]
215
-
then
207
+
if [[ "$Fflag"=="1" ]];then
216
208
rm -rf $destdir/*
217
-
if [ $?-ne 0 ]
218
-
then
219
-
echo"Failed to clean up template directory $destdir -- check permissions?"
220
-
failed 2
209
+
if [[ $?-ne 0 ]];then
210
+
failed 2 "Failed to clean up template directory $destdir -- check permissions?"
221
211
fi
222
212
fi
223
213
224
-
if [ -f$destdir/template.properties ]
225
-
then
226
-
echo"Data already exists at destination $destdir -- use -F to force cleanup of old template"
227
-
echo"IF YOU ARE ATTEMPTING AN UPGRADE, YOU MAY NEED TO SPECIFY A TEMPLATE ID USING THE -t FLAG"
228
-
failed 4
214
+
if [[ -f$destdir/template.properties ]];then
215
+
failed 2 "Data already exists at destination $destdir -- use -F to force cleanup of old template\nIF YOU ARE ATTEMPTING AN UPGRADE, YOU MAY NEED TO SPECIFY A TEMPLATE ID USING THE -t FLAG"
229
216
fi
230
217
231
-
destvhdfiles=$(find $destdir -name \*.$ext)
232
-
if [ "$destvhdfiles"!="" ]
233
-
then
234
-
echo"Data already exists at destination $destdir -- use -F to force cleanup of old template"
235
-
failed 5
218
+
destfiles=$(find $destdir -name \*.$ext)
219
+
if [[ "$destfiles"!="" ]];then
220
+
failed 2 "Data already exists at destination $destdir -- use -F to force cleanup of old template"
236
221
fi
237
222
238
-
tmpfile=$(dirname $0)/$localfile
223
+
tmplfile=$(dirname $0)/$localfile
239
224
240
-
touch $tmpfile
241
-
if [ $?-ne 0 ]
242
-
then
243
-
printf"Failed to create temporary file in directory $(dirname $0) -- is it read-only or full?\n"
244
-
failed 4
225
+
touch $tmplfile
226
+
if [[ $?-ne 0 ]];then
227
+
failed 2 "Failed to create temporary file in directory $(dirname $0) -- is it read-only or full?\n"
[ $localcap-lt$DISKSPACE ] &&echo"Insufficient free disk space for local temporary folder $(dirname $0): avail=${localcap}k req=${DISKSPACE}k"&& failed 4
252
235
253
-
if [ "$uflag"=="1" ]
254
-
then
255
-
wget -O $tmpfile$url
256
-
if [ $?-ne 0 ]
257
-
then
258
-
echo"Failed to fetch system vm template from $url"
259
-
failed 5
236
+
if [[ "$uflag"=="1" ]];then
237
+
wget -O $tmplfile$url
238
+
if [[ $?-ne 0 ]];then
239
+
failed 2 "Failed to fetch system vm template from $url"
260
240
fi
261
241
fi
262
242
263
-
264
-
if [ "$fflag"=="1" ]
265
-
then
266
-
cp $tmpltimg$tmpfile
267
-
if [ $?-ne 0 ]
268
-
then
269
-
printf"Failed to create temporary file in directory $(dirname $0) -- is it read-only or full?\n"
270
-
failed 6
243
+
if [[ "$fflag"=="1" ]];then
244
+
cp $tmpltimg$tmplfile
245
+
if [[ $?-ne 0 ]];then
246
+
failed 2 "Failed to create temporary file in directory $(dirname $0) -- is it read-only or full?\n"
0 commit comments