diff --git a/src/datastore_mad/remotes/downloader.sh b/src/datastore_mad/remotes/downloader.sh index dcdee6ac79..7a45b80307 100755 --- a/src/datastore_mad/remotes/downloader.sh +++ b/src/datastore_mad/remotes/downloader.sh @@ -257,6 +257,10 @@ while true; do export MAX_SIZE="$2" shift 2 ;; + --convert) + export CONVERT="$2" + shift 2 + ;; --) shift break @@ -393,3 +397,40 @@ fi if [ "$TO" != "-" ]; then unarchive "$TO" fi + +# Function to know what is the original image type +# Figure out what type of image it is +function get_original_type +{ + command_get_type="qemu-img info "$TO"" + output_get_type=$(eval "$command_get_type") + + split=$(echo $output_get_type | tr ":" "\n") + count=0 + format="" + + for pal in $split + do + if [ "$count" == 4 ]; then + format=$pal + break + fi + count=$((count+1)) + done + echo $format +} + +# Convert the image to a given type into a tmp image with qemu-img +if [ ! -z "$CONVERT" ]; then + + tmpimage=$TO".tmp" + + original_type=$(get_original_type) + convert_type=$CONVERT + + convert="qemu-img convert -f "$original_type" -O "$convert_type" "$TO" "$tmpimage"" + + # Move tmp image to get the final image + mvcommand="mv "$tmpimage" "$TO"" + eval "$mvcommand" +fi \ No newline at end of file diff --git a/src/datastore_mad/remotes/vcenter/cp b/src/datastore_mad/remotes/vcenter/cp index 94c14ec7cc..9575bb93ec 100755 --- a/src/datastore_mad/remotes/vcenter/cp +++ b/src/datastore_mad/remotes/vcenter/cp @@ -92,6 +92,7 @@ if VCenterDriver::FileHelper.is_remote_or_needs_unpack?(img_path) downsh_args << "--sha1 #{sha1} " if sha1 && !sha1.empty? downsh_args << "--nodecomp " if nodecomp && !nodecomp.empty? downsh_args << "--limit #{limit_bw} " if limit_bw && !limit_bw.empty? + downsh_args << "--convert vmdk" downloader = "#{File.dirname(__FILE__)}/../downloader.sh #{downsh_args}"