mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-25 02:50:08 +03:00
Feature #4217: Remove image download functionality
This commit is contained in:
parent
f4f280ce68
commit
d751456cfd
@ -176,19 +176,6 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
end
|
||||
end
|
||||
|
||||
download_desc = <<-EOT.unindent
|
||||
Downloads an image to a file
|
||||
EOT
|
||||
|
||||
command :download, download_desc, :imageid, :path,
|
||||
:options => [OpenNebulaHelper::FORCE] do
|
||||
|
||||
helper.perform_action(args[0],options,"downloaded") do |image|
|
||||
download_args = [:image, args[0], args[1], options[:force]]
|
||||
OpenNebulaHelper.download_resource_sunstone(*download_args)
|
||||
end
|
||||
end
|
||||
|
||||
delete_desc = <<-EOT.unindent
|
||||
Deletes the given Image
|
||||
EOT
|
||||
|
@ -217,75 +217,35 @@ class SunstoneServer < CloudServer
|
||||
############################################################################
|
||||
#
|
||||
############################################################################
|
||||
def download_resource(kind, id)
|
||||
case kind
|
||||
when "image"
|
||||
# Get Image
|
||||
image = Image.new(Image.build_xml(id.to_i), @client)
|
||||
rc = image.info
|
||||
def download_marketplaceapp(id)
|
||||
# Get MarketPlaceApp
|
||||
marketapp = MarketPlaceApp.new(MarketPlaceApp.build_xml(id.to_i), @client)
|
||||
|
||||
return [500, rc.message] if OpenNebula.is_error?(rc)
|
||||
rc = marketapp.info
|
||||
return [500, rc.message] if OpenNebula.is_error?(rc)
|
||||
|
||||
# Get Datastore
|
||||
ds_id = image['DATASTORE_ID']
|
||||
# Get Datastore
|
||||
market_id = marketapp['MARKETPLACE_ID']
|
||||
|
||||
ds = Datastore.new(Datastore.build_xml(ds_id), @client)
|
||||
rc = ds.info
|
||||
market = MarketPlace.new(MarketPlace.build_xml(market_id), @client)
|
||||
rc = market.info
|
||||
|
||||
return [500, rc.message] if OpenNebula.is_error?(rc)
|
||||
return [500, rc.message] if OpenNebula.is_error?(rc)
|
||||
|
||||
# Build Driver message
|
||||
drv_message = "<DS_DRIVER_ACTION_DATA>" <<
|
||||
"#{image.to_xml}#{ds.to_xml}" <<
|
||||
"</DS_DRIVER_ACTION_DATA>"
|
||||
# Build Driver message
|
||||
drv_message = "<DS_DRIVER_ACTION_DATA>" <<
|
||||
"#{market.to_xml}" <<
|
||||
"</DS_DRIVER_ACTION_DATA>"
|
||||
|
||||
drv_message_64 = Base64::strict_encode64(drv_message)
|
||||
drv_message_64 = Base64::strict_encode64(drv_message)
|
||||
|
||||
begin
|
||||
export = "#{VAR_LOCATION}/remotes/datastore/#{ds['DS_MAD']}/export"
|
||||
|
||||
export_stdout = `#{export} #{drv_message_64} #{id}`
|
||||
|
||||
doc = REXML::Document.new(export_stdout).root
|
||||
|
||||
source = doc.elements['IMPORT_SOURCE'].text
|
||||
rescue Exception => e
|
||||
return [500, "#{e.message}\n#{e.backtrace}"]
|
||||
end
|
||||
when "marketplaceapp"
|
||||
# Get MarketPlaceApp
|
||||
marketapp = MarketPlaceApp.new(MarketPlaceApp.build_xml(id.to_i), @client)
|
||||
|
||||
rc = marketapp.info
|
||||
return [500, rc.message] if OpenNebula.is_error?(rc)
|
||||
|
||||
# Get Datastore
|
||||
market_id = marketapp['MARKETPLACE_ID']
|
||||
|
||||
market = MarketPlace.new(MarketPlace.build_xml(market_id), @client)
|
||||
rc = market.info
|
||||
|
||||
return [500, rc.message] if OpenNebula.is_error?(rc)
|
||||
|
||||
# Build Driver message
|
||||
drv_message = "<DS_DRIVER_ACTION_DATA>" <<
|
||||
"#{market.to_xml}" <<
|
||||
"</DS_DRIVER_ACTION_DATA>"
|
||||
|
||||
drv_message_64 = Base64::strict_encode64(drv_message)
|
||||
|
||||
source = marketapp['SOURCE']
|
||||
|
||||
else
|
||||
return [404, "Unknown resource."]
|
||||
end
|
||||
source = marketapp['SOURCE']
|
||||
|
||||
download_cmd = "DRV_ACTION=#{drv_message_64} "<<
|
||||
"#{VAR_LOCATION}/remotes/datastore/downloader.sh " <<
|
||||
"#{source} -"
|
||||
|
||||
|
||||
filename = "one-#{kind}-#{id}"
|
||||
filename = "one-marketplaceapp-#{id}"
|
||||
|
||||
return [download_cmd, filename]
|
||||
end
|
||||
|
@ -720,12 +720,10 @@ post '/upload_chunk' do
|
||||
end
|
||||
|
||||
##############################################################################
|
||||
# Download image or marketapp
|
||||
# Download marketplaceapp
|
||||
##############################################################################
|
||||
READ_LENGTH = 10*1024*1024
|
||||
|
||||
get '/:resource/:id/download' do
|
||||
dl_resource = @SunstoneServer.download_resource(params[:resource], params[:id])
|
||||
get '/marketplaceapp/:id/download' do
|
||||
dl_resource = @SunstoneServer.download_marketplaceapp(params[:id])
|
||||
|
||||
# If the first element of dl_resource is a number, it is the exit_code after
|
||||
# an error happend, so return it.
|
||||
@ -734,8 +732,9 @@ get '/:resource/:id/download' do
|
||||
download_cmd, filename = dl_resource
|
||||
|
||||
# Send headers
|
||||
headers['Cache-Control'] = "no-transform" # Do not use Rack::Deflater
|
||||
headers['Cache-Control'] = "no-transform" # Do not use Rack::Deflater
|
||||
headers['Content-Disposition'] = "attachment; filename=\"#{filename}\""
|
||||
|
||||
content_type :'application/octet-stream'
|
||||
|
||||
# Start stream
|
||||
@ -743,7 +742,8 @@ get '/:resource/:id/download' do
|
||||
Open3.popen3(download_cmd) do |_,o,e,w|
|
||||
|
||||
until o.eof?
|
||||
out << o.read(READ_LENGTH)
|
||||
# Read in chunks of 10MB
|
||||
out << o.read(10*1024*1024)
|
||||
end
|
||||
|
||||
if !w.value.success?
|
||||
|
Loading…
x
Reference in New Issue
Block a user