ustcweizhou commented on a change in pull request #3346: Fix template size for 
managed storage / refactor cloud-install-sys-tmplt and createtmplt.sh
URL: https://github.com/apache/cloudstack/pull/3346#discussion_r286359012
 
 

 ##########
 File path: scripts/storage/secondary/cloud-install-sys-tmplt
 ##########
 @@ -250,51 +232,49 @@ destcap=$(df -P $destdir | awk '{print $4}' | tail -1 )
 localcap=$(df -P $(dirname $0) | awk '{print $4}' | tail -1 )
 [ $localcap -lt $DISKSPACE ] && echo "Insufficient free disk space for local 
temporary folder $(dirname $0): avail=${localcap}k req=${DISKSPACE}k" && failed 
4
 
-if [ "$uflag" == "1" ]
-then
-  wget -O $tmpfile $url
-  if [ $? -ne 0 ]
-  then
-    echo "Failed to fetch system vm template from $url"
-    failed 5
+if [[ "$uflag" == "1" ]]; then
+  wget -O $tmplfile $url
+  if [[ $? -ne 0 ]]; then
+    failed 2 "Failed to fetch system vm template from $url"
   fi
 fi
 
-
-if [ "$fflag" == "1" ]
-then
-  cp $tmpltimg $tmpfile
-  if [ $? -ne 0 ]
-  then
-    printf "Failed to create temporary file in directory $(dirname $0) -- is 
it read-only or full?\n"
-    failed 6
+if [[ "$fflag" == "1" ]]; then
+  cp $tmpltimg $tmplfile
+  if [[ $? -ne 0 ]]; then
+    failed 2 "Failed to create temporary file in directory $(dirname $0) -- is 
it read-only or full?\n"
   fi
 fi
 
+installrslt=$($(dirname $0)/createtmplt.sh -n $localfile -t $destdir -f 
$tmplfile)
 
-installrslt=$($(dirname $0)/createtmplt.sh -s 2 -d 'SystemVM Template' -n 
$localfile -t $destdir/ -f $tmpfile -u -v)
-
-if [ $? -ne 0 ]
-then
-  echo "Failed to install system vm template $tmpltimg to $destdir: 
$installrslt"
-  failed 7
+if [[ $? -ne 0 ]]; then
+  failed 2 "Failed to install system vm template $tmpltimg to $destdir: 
$installrslt"
 fi
 
-if [ "$ext" == "ova" ]
-then
-  tar xvf $destdir/$localfile -C $destdir &> /dev/null
+if [[ $(which qemu-img) ]]; then
+  qemuimgcmd=$(which qemu-img)
+else
+  failed 2 "Please install qemu-img command"
 fi
 
 tmpltfile=$destdir/$localfile
-tmpltsize=$(ls -l $tmpltfile| awk -F" " '{print $5}')
-
+tmpltsize=$(ls -l $tmpltfile | awk -F" " '{print $5}')
+vrtmpltsize=$($qemuimgcmd info $tmpltfile | grep -i 'virtual size' | sed -ne 
's/.*(\([0-9]*\).*/\1/p' | xargs)
 
 Review comment:
   that only applies on qcow2 images
   ```
   if [ "$ext" == "qcow2" ]
   then
       vrtmpltsize= XXXX
   else
       vrtmpltsize=tmpltsize
   fi
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to