mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-22 18:50:08 +03:00
Feature #523: Update OCCI Server to use the new Image Repository drivers
This commit is contained in:
parent
e9ee8599d1
commit
c3cdeed5c8
@ -46,6 +46,9 @@ class ImageOCCI < Image
|
||||
<% if @image_info['DESCRIPTION'] != nil %>
|
||||
DESCRIPTION = "<%= @image_info['DESCRIPTION'] %>"
|
||||
<% end %>
|
||||
<% if @image_file != nil %>
|
||||
PATH = "<%= @image_file %>"
|
||||
<% end %>
|
||||
<% if @image_info['PUBLIC'] != nil %>
|
||||
PUBLIC = "<%= @image_info['PUBLIC'] %>"
|
||||
<% end %>
|
||||
@ -64,9 +67,14 @@ class ImageOCCI < Image
|
||||
}.gsub(/^ /, '')
|
||||
|
||||
# Class constructor
|
||||
def initialize(xml, client, xml_info=nil)
|
||||
def initialize(xml, client, xml_info=nil, file=nil)
|
||||
super(xml, client)
|
||||
@image_info = nil
|
||||
@image_file = file
|
||||
|
||||
if file && file[:tempfile]
|
||||
@image_file = file[:tempfile].path
|
||||
end
|
||||
|
||||
if xml_info != nil
|
||||
xmldoc = XMLElement.build_xml(xml_info, 'STORAGE')
|
||||
|
@ -170,18 +170,18 @@ module OCCIClient
|
||||
return error
|
||||
end
|
||||
|
||||
if image_info.elements['URL'] == nil
|
||||
if image_info.elements['URL']
|
||||
file_path = image_info.elements['URL'].text
|
||||
|
||||
m = file_path.match(/^\w+:\/\/(.*)$/)
|
||||
|
||||
if m
|
||||
file_path="/"+m[1]
|
||||
end
|
||||
elsif !image_info.elements['TYPE'] == "DATABLOCK"
|
||||
return CloudClient::Error.new("Can not find URL")
|
||||
end
|
||||
|
||||
file_path = image_info.elements['URL'].text
|
||||
|
||||
m = file_path.match(/^\w+:\/\/(.*)$/)
|
||||
|
||||
if m
|
||||
file_path="/"+m[1]
|
||||
end
|
||||
|
||||
if curb
|
||||
if !CURL_LOADED
|
||||
error_msg = "curb gem not loaded"
|
||||
@ -197,10 +197,14 @@ module OCCIClient
|
||||
curl.multipart_form_post = true
|
||||
|
||||
begin
|
||||
curl.http_post(
|
||||
Curl::PostField.content('occixml', xml),
|
||||
Curl::PostField.file('file', file_path)
|
||||
)
|
||||
postfields = Array.new
|
||||
postfields << Curl::PostField.content('occixml', xml)
|
||||
|
||||
if file_path
|
||||
postfields << Curl::PostField.file('file', file_path)
|
||||
end
|
||||
|
||||
curl.http_post(*postfields)
|
||||
rescue Exception => e
|
||||
return CloudClient::Error.new(e.message)
|
||||
end
|
||||
@ -213,11 +217,13 @@ module OCCIClient
|
||||
return error
|
||||
end
|
||||
|
||||
file=File.open(file_path)
|
||||
|
||||
params=Hash.new
|
||||
params["file"]=UploadIO.new(file,
|
||||
'application/octet-stream', file_path)
|
||||
|
||||
if file_path
|
||||
file=File.open(file_path)
|
||||
params["file"]=UploadIO.new(file,
|
||||
'application/octet-stream', file_path)
|
||||
end
|
||||
|
||||
params['occixml'] = xml
|
||||
|
||||
@ -231,8 +237,8 @@ module OCCIClient
|
||||
http.request(req)
|
||||
end
|
||||
|
||||
file.close
|
||||
pp res
|
||||
file.close if file_path
|
||||
|
||||
if CloudClient::is_error?(res)
|
||||
return res
|
||||
else
|
||||
|
@ -401,16 +401,18 @@ class OCCIServer < CloudServer
|
||||
image = ImageOCCI.new(
|
||||
Image.build_xml,
|
||||
get_client(request.env),
|
||||
occixml)
|
||||
occixml,
|
||||
request.params['file'])
|
||||
|
||||
rc = add_image(image, request.params['file'])
|
||||
return rc, 500 if OpenNebula.is_error?(rc)
|
||||
# --- Generate the template and Allocate the new Instance ---
|
||||
template = image.to_one_template
|
||||
return template, 500 if OpenNebula.is_error?(template)
|
||||
|
||||
# --- Enable the new Image ---
|
||||
rc = image.enable
|
||||
rc = image.allocate(template)
|
||||
return rc, 500 if OpenNebula.is_error?(rc)
|
||||
|
||||
# --- Prepare XML Response ---
|
||||
image.info
|
||||
return to_occi_xml(image, 201)
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user