mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-22 18:50:08 +03:00
from downloader.sh to vcenter/cp Co-authored-by: Tino Vázquez <cvazquez@opennebula.io> (cherry picked from commit 7e46da9fe21714f121e70af12de2c47067fd3320)
This commit is contained in:
parent
911e950174
commit
e46157bb22
@ -295,7 +295,7 @@ function get_rbd_cmd
|
||||
echo "ssh '$(esc_sq "$DST_HOST")' \"$RBD export '$(esc_sq "$SOURCE")' -\""
|
||||
}
|
||||
|
||||
TEMP=`getopt -o m:s:l:c:n -l md5:,sha1:,limit:,max-size:,convert:,nodecomp -- "$@"`
|
||||
TEMP=`getopt -o m:s:l:c:n -l md5:,sha1:,limit:,max-size:,nodecomp -- "$@"`
|
||||
|
||||
if [ $? != 0 ] ; then
|
||||
echo "Arguments error" >&2
|
||||
@ -328,10 +328,6 @@ while true; do
|
||||
export MAX_SIZE="$2"
|
||||
shift 2
|
||||
;;
|
||||
--convert)
|
||||
export CONVERT="$2"
|
||||
shift 2
|
||||
;;
|
||||
--)
|
||||
shift
|
||||
break
|
||||
@ -477,24 +473,7 @@ if [ -n "$HASH_TYPE" ]; then
|
||||
fi
|
||||
fi
|
||||
|
||||
function convert_image
|
||||
{
|
||||
original_type=$(qemu-img info $TO | grep "^file format:" | awk '{print $3}' || :)
|
||||
if [ "$CONVERT" != "$original_type" ]; then
|
||||
tmpimage=$TO".tmp"
|
||||
qemu-img convert -f $original_type -O $CONVERT $TO $tmpimage
|
||||
mv $tmpimage $TO
|
||||
fi
|
||||
}
|
||||
|
||||
# Unarchive only if the destination is filesystem
|
||||
if [ "$TO" != "-" ]; then
|
||||
unarchive "$TO"
|
||||
|
||||
if [ -n "$CONVERT" ] && [ -f "$TO" ]; then
|
||||
convert_image
|
||||
fi
|
||||
|
||||
elif [ -n "$CONVERT" ]; then
|
||||
convert_image
|
||||
fi
|
||||
|
@ -51,6 +51,7 @@ $LOAD_PATH << File.dirname(__FILE__)
|
||||
|
||||
require 'vcenter_driver'
|
||||
require 'open3'
|
||||
require 'rexml/document'
|
||||
|
||||
def file_location?(target_path, f)
|
||||
target_path == File.basename(f)
|
||||
@ -119,21 +120,56 @@ if VCenterDriver::FileHelper.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?
|
||||
unless VCenterDriver::FileHelper.from_s3?(img_path)
|
||||
downsh_args << '--convert vmdk'
|
||||
end
|
||||
|
||||
# Define downloader script and driver action variable
|
||||
downloader = "#{File.dirname(__FILE__)}/../downloader.sh #{downsh_args}"
|
||||
b64 = Base64.encode64(drv_action.to_xml).gsub!("\n", '')
|
||||
|
||||
rc = system("DRV_ACTION=#{b64} #{downloader} #{img_path} #{temp_file}")
|
||||
|
||||
# Fail if download fails
|
||||
if there_is_not_system_error?(rc)
|
||||
STDERR.puts "Error downloading #{img_path}"
|
||||
FileUtils.rm_rf(temp_file)
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
# Convert from current format to VMDK
|
||||
unless VCenterDriver::FileHelper.from_s3?(img_path)
|
||||
file_type=''
|
||||
begin
|
||||
Open3.popen3("qemu-img info #{temp_file}") do
|
||||
|_stdin, stdout, stderr, wait_thr|
|
||||
if !stderr.nil?
|
||||
STDERR.puts "'qemu-img info' stderr: #{stderr}"
|
||||
raise StandardError
|
||||
end
|
||||
file_type=stdout.read.split("\n")[1].split(':')[1].lstrip
|
||||
if file_type.nil? then raise StandardError end
|
||||
|
||||
wait_thr.join
|
||||
end
|
||||
rescue StandardError
|
||||
STDERR.puts "'qemu-img info' output appears to be invalid.' \
|
||||
' Cannot determine file type."
|
||||
STDERR.puts "Removing #{temp_file}..."
|
||||
FileUtils.rm_rf(temp_file)
|
||||
exit(-1)
|
||||
end
|
||||
unless file_type == 'vmdk'
|
||||
out_file = File.basename(temp_file, '.*')+'.tmp'
|
||||
convert=system("qemu-img convert -f #{file_type}"\
|
||||
" -O vmdk #{temp_file} #{out_file}")
|
||||
if there_is_not_system_error?(convert)
|
||||
STDERR.puts "Error converting #{temp_file}."
|
||||
STDERR.puts "Removing #{temp_file} and #{out_file}."
|
||||
File.Utils.rm_rf(out_file)
|
||||
File.Utils.rm_rf(temp_file)
|
||||
exit(-1)
|
||||
end
|
||||
FileUtils.mv(out_file, temp_file)
|
||||
end
|
||||
end
|
||||
|
||||
img_path = temp_file
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user