Skip to content

Commit cf493b6

Browse files
Revert "Revert "Fix virtual template size for managed storage for KVM / refactor cloud-install-sys-tmplt (#3371)" (#3771)"
This reverts commit e319c8b.
1 parent e319c8b commit cf493b6

File tree

4 files changed

+131
-153
lines changed

4 files changed

+131
-153
lines changed

debian/control

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Description: A common package which contains files which are shared by several C
1515

1616
Package: cloudstack-management
1717
Architecture: all
18-
Depends: ${python:Depends}, openjdk-8-jre-headless | java8-runtime-headless | java8-runtime | openjdk-9-jre-headless, cloudstack-common (= ${source:Version}), sudo, python-mysql.connector, libmysql-java, augeas-tools, mysql-client, adduser, bzip2, ipmitool, file, gawk, iproute2, lsb-release, init-system-helpers (>= 1.14~)
18+
Depends: ${python:Depends}, openjdk-8-jre-headless | java8-runtime-headless | java8-runtime | openjdk-9-jre-headless, cloudstack-common (= ${source:Version}), sudo, python-mysql.connector, libmysql-java, augeas-tools, mysql-client, adduser, bzip2, ipmitool, file, gawk, iproute2, lsb-release, init-system-helpers (>= 1.14~), qemu-utils
1919
Conflicts: cloud-server, cloud-client, cloud-client-ui
2020
Description: CloudStack server library
2121
The CloudStack management server

packaging/centos7/cloud.spec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ Requires: mysql-connector-python
7878
Requires: ipmitool
7979
Requires: %{name}-common = %{_ver}
8080
Requires: iptables-services
81+
Requires: qemu-img
8182
Group: System Environment/Libraries
8283
%description management
8384
The CloudStack management server is the central point of coordination,
Lines changed: 129 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/bin/bash
2-
# $Id: installrtng.sh 11251 2010-07-23 23:40:44Z abhishek $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/storage/secondary/installrtng.sh $
32

43
# Licensed to the Apache Software Foundation (ASF) under one
54
# or more contributor license agreements. See the NOTICE file
@@ -20,15 +19,30 @@
2019

2120

2221
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
2625
}
2726

27+
# Usage: e.g. failed $? "this is an error"
2828
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
33+
if [[ -z $returnmsg ]]; then
34+
:
35+
else
36+
echo -e $returnmsg
37+
fi
38+
if [[ $returnval -eq 0 ]]; then
39+
return 0
40+
else
41+
echo "Installation failed"
42+
exit $returnval
43+
fi
3144
}
45+
3246
#set -x
3347
mflag=
3448
fflag=
@@ -42,7 +56,15 @@ dbUser="root"
4256
dbPassword=
4357
dbPort=3306
4458
jasypt='/usr/share/cloudstack-common/lib/jasypt-1.9.2.jar'
45-
while getopts 'm:h:f:u:Ft:e:s:o:r:d:p:'# OPTION
59+
60+
# check if first parameter is not a dash (-) then print the usage block
61+
if [[ ! $@ =~ ^\-.+ ]]; then
62+
usage
63+
exit 0
64+
fi
65+
66+
OPTERR=0
67+
while getopts 'm:h:f:u:Ft:e:Ms:o:r:d:p:'# OPTION
4668
do
4769
case $OPTION in
4870
m) mflag=1
@@ -78,121 +100,94 @@ do
78100
dbPort="$OPTARG"
79101
;;
80102
?) usage
81-
failed 2
103+
exit 0
104+
;;
105+
*) usage
106+
exit 0
82107
;;
83108
esac
84109
done
85110

86-
if [[ "$mflag$fflag" != "11" && "$mflag$uflag" != "11" ]]
87-
then
88-
usage
89-
failed 2
111+
if [[ "$mflag$fflag" != "11" && "$mflag$uflag" != "11" ]]; then
112+
failed 2 "Please add a mount point and a system vm template file"
90113
fi
91114

92-
if [ -z "$hyper" ]
93-
then
94-
usage
95-
failed 2
115+
if [[ -z "$hyper" ]]; then
116+
failed 2 "Please add a correct hypervisor name like: kvm|vmware|xenserver|hyperv|ovm3"
96117
fi
97118

98-
if [ ! -d $mntpoint ]
99-
then
100-
echo "mount point $mntpoint doesn't exist\n"
101-
failed 4
119+
if [[ ! -d $mntpoint ]]; then
120+
failed 2 "mount point $mntpoint doesn't exist\n"
102121
fi
103122

104-
if [[ "$fflag" == "1" && ! -f $tmpltimg ]]
105-
then
106-
echo "template image file $tmpltimg doesn't exist"
107-
failed 3
123+
if [[ "$fflag" == "1" && ! -f $tmpltimg ]]; then
124+
failed 2 "template image file $tmpltimg doesn't exist"
108125
fi
109126

110-
if [ -f /etc/cloudstack/management/db.properties ]
111-
then
112-
if [ "$pflag" != 1 ]
113-
then
114-
dbPort=$(sed '/^\#/d' /etc/cloudstack/management/db.properties | grep 'db.cloud.port' | tail -n 1 | cut -d "=" -f2- | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
115-
fi
127+
if [[ -f /etc/cloudstack/management/db.properties ]]; then
128+
if [[ "$pflag" != 1 ]]; then
129+
dbPort=$(sed '/^\#/d' /etc/cloudstack/management/db.properties | grep 'db.cloud.port' | tail -n 1 | cut -d "=" -f2- | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
130+
fi
116131

117-
if [ "$oflag" != 1 ]
118-
then
119-
dbHost=$(sed '/^\#/d' /etc/cloudstack/management/db.properties | grep 'db.cloud.host' | tail -n 1 | cut -d "=" -f2- | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
120-
fi
132+
if [[ "$oflag" != 1 ]]; then
133+
dbHost=$(sed '/^\#/d' /etc/cloudstack/management/db.properties | grep 'db.cloud.host' | tail -n 1 | cut -d "=" -f2- | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
134+
fi
121135

122-
if [ "$rflag" != 1 ]
123-
then
124-
dbUser=$(sed '/^\#/d' /etc/cloudstack/management/db.properties | grep 'db.cloud.username' | tail -n 1 | cut -d "=" -f2- | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
125-
fi
136+
if [[ "$rflag" != 1 ]]; then
137+
dbUser=$(sed '/^\#/d' /etc/cloudstack/management/db.properties | grep 'db.cloud.username' | tail -n 1 | cut -d "=" -f2- | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
138+
fi
126139

127-
encType=$(sed '/^\#/d' /etc/cloudstack/management/db.properties | grep 'db.cloud.encryption.type' | tail -n 1 | cut -d "=" -f2- | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
128-
if [ "$encType" == "file" ]
129-
then
130-
msKey=$(cat /etc/cloudstack/management/key)
131-
elif [ "$encType" == "web" ]
132-
then
133-
if [ ! "$sflag" == "1" ]
134-
then
135-
echo "Encryption type web requires mgmt secret key using -s option"
136-
failed 9
137-
fi
140+
encType=$(sed '/^\#/d' /etc/cloudstack/management/db.properties | grep 'db.cloud.encryption.type' | tail -n 1 | cut -d "=" -f2- | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
141+
if [[ "$encType" == "file" ]]; then
142+
msKey=$(cat /etc/cloudstack/management/key)
143+
elif [[ "$encType" == "web" ]]; then
144+
if [[ ! "$sflag" == "1" ]]; then
145+
failed 2 "Encryption type web requires mgmt secret key using -s option"
138146
fi
147+
fi
139148

140-
if [[ "$encType" == "file" || "$encType" == "web" ]]
141-
then
142-
encPassword=$(sed '/^\#/d' /etc/cloudstack/management/db.properties | grep 'db.cloud.password' | tail -n 1 | cut -d "=" -f2- | sed 's/^[[:space:]]*//;s/[[:space:]]*$//'i | sed 's/^ENC(\(.*\))/\1/')
143-
if [ ! $encPassword == "" ]
144-
then
145-
dbPassword=(`java -classpath $jasypt org.jasypt.intf.cli.JasyptPBEStringDecryptionCLI decrypt.sh input=$encPassword password=$msKey verbose=false`)
146-
if [ ! $dbPassword ]
147-
then
148-
echo "Failed to decrypt DB password from db.properties"
149-
failed 9
150-
fi
151-
fi
152-
else
153-
if [ "$dflag" != 1 ]
154-
then
155-
dbPassword=$(sed '/^\#/d' /etc/cloudstack/management/db.properties | grep 'db.cloud.password' | tail -n 1 | cut -d "=" -f2- | sed 's/^[[:space:]]*//;s/[[:space:]]*$//'i )
156-
fi
149+
if [[ "$encType" == "file" || "$encType" == "web" ]]; then
150+
encPassword=$(sed '/^\#/d' /etc/cloudstack/management/db.properties | grep 'db.cloud.password' | tail -n 1 | cut -d "=" -f2- | sed 's/^[[:space:]]*//;s/[[:space:]]*$//'i | sed 's/^ENC(\(.*\))/\1/')
151+
if [[ ! $encPassword == "" ]]; then
152+
dbPassword=(`java -classpath $jasypt org.jasypt.intf.cli.JasyptPBEStringDecryptionCLI decrypt.sh input=$encPassword password=$msKey verbose=false`)
153+
if [[ ! $dbPassword ]]; then
154+
failed 2 "Failed to decrypt DB password from db.properties"
155+
fi
156+
fi
157+
else
158+
if [[ "$dflag" != 1 ]]; then
159+
dbPassword=$(sed '/^\#/d' /etc/cloudstack/management/db.properties | grep 'db.cloud.password' | tail -n 1 | cut -d "=" -f2- | sed 's/^[[:space:]]*//;s/[[:space:]]*$//'i )
157160
fi
161+
fi
158162
fi
159163

160-
if [ "$templateId" == "" ]
161-
then
162-
if [ "$hyper" == "kvm" ]
163-
then
164-
ext="qcow2"
165-
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
190187
fi
191188

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"
196191
fi
197192

198193
_uuid=$(uuidgen)
@@ -205,43 +200,31 @@ mntpoint=`echo "$mntpoint" | sed 's|/*$||'`
205200
destdir=$mntpoint/template/tmpl/1/$templateId/
206201

207202
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"
212205
fi
213206

214-
if [ "$Fflag" == "1" ]
215-
then
207+
if [[ "$Fflag" == "1" ]]; then
216208
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?"
221211
fi
222212
fi
223213

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"
229216
fi
230217

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"
236221
fi
237222

238-
tmpfile=$(dirname $0)/$localfile
223+
tmplfile=$(dirname $0)/$localfile
239224

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"
245228
fi
246229

247230
destcap=$(df -P $destdir | awk '{print $4}' | tail -1 )
@@ -250,34 +233,24 @@ destcap=$(df -P $destdir | awk '{print $4}' | tail -1 )
250233
localcap=$(df -P $(dirname $0) | awk '{print $4}' | tail -1 )
251234
[ $localcap -lt $DISKSPACE ] && echo "Insufficient free disk space for local temporary folder $(dirname $0): avail=${localcap}k req=${DISKSPACE}k" && failed 4
252235

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"
260240
fi
261241
fi
262242

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"
271247
fi
272248
fi
273249

250+
installrslt=$($(dirname $0)/createtmplt.sh -s 2 -d 'SystemVM Template' -n $localfile -t $destdir/ -f $tmplfile -u -v)
274251

275-
installrslt=$($(dirname $0)/createtmplt.sh -s 2 -d 'SystemVM Template' -n $localfile -t $destdir/ -f $tmpfile -u -v)
276-
277-
if [ $? -ne 0 ]
278-
then
279-
echo "Failed to install system vm template $tmpltimg to $destdir: $installrslt"
280-
failed 7
252+
if [[ $? -ne 0 ]]; then
253+
failed 2 "Failed to install system vm template $tmpltimg to $destdir: $installrslt"
281254
fi
282255

283256
if [ "$ext" == "ova" ]
@@ -286,15 +259,20 @@ then
286259
fi
287260

288261
tmpltfile=$destdir/$localfile
289-
tmpltsize=$(ls -l $tmpltfile| awk -F" " '{print $5}')
262+
tmpltsize=$(ls -l $tmpltfile | awk -F" " '{print $5}')
263+
if [[ "$ext" == "qcow2" ]]; then
264+
vrtmpltsize=$($qemuimgcmd info $tmpltfile | grep -i 'virtual size' | sed -ne 's/.*(\([0-9]*\).*/\1/p' | xargs)
265+
else
266+
vrtmpltsize=$tmpltsize
267+
fi
290268

291269
echo "$ext=true" >> $destdir/template.properties
292270
echo "id=$templateId" >> $destdir/template.properties
293271
echo "public=true" >> $destdir/template.properties
294272
echo "$ext.filename=$localfile" >> $destdir/template.properties
295273
echo "uniquename=routing-$templateId" >> $destdir/template.properties
296-
echo "$ext.virtualsize=$tmpltsize" >> $destdir/template.properties
297-
echo "virtualsize=$tmpltsize" >> $destdir/template.properties
274+
echo "$ext.virtualsize=$vrtmpltsize" >> $destdir/template.properties
275+
echo "virtualsize=$vrtmpltsize" >> $destdir/template.properties
298276
echo "$ext.size=$tmpltsize" >> $destdir/template.properties
299277

300-
echo "Successfully installed system VM template $tmpltimg to $destdir"
278+
echo "Successfully installed system VM template $tmpltimg and template.properties to $destdir"

0 commit comments

Comments
 (0)