mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-22 18:50:08 +03:00
Feature #523: Update EC2 Server to use the new Image Repository drivers
This commit is contained in:
parent
ecca012072
commit
e9ee8599d1
@ -62,8 +62,6 @@ class CloudServer
|
||||
|
||||
@one_client = Client.new(nil,@config[:one_xmlrpc])
|
||||
@user_pool = UserPool.new(@one_client)
|
||||
|
||||
@img_repo = OpenNebula::ImageRepository.new
|
||||
end
|
||||
|
||||
#
|
||||
@ -103,39 +101,6 @@ class CloudServer
|
||||
return @user_pool["USER[NAME=\"#{name}\"]/PASSWORD"]
|
||||
end
|
||||
|
||||
###########################################################################
|
||||
# Repository Methods
|
||||
###########################################################################
|
||||
|
||||
# Adds a new image to the repository and deletes the temp_file
|
||||
# uid:: _Integer_ owner of the image
|
||||
# path:: _String_ path of the tmp file
|
||||
# metadata:: Additional metadata for the file
|
||||
# [return] _Image_ Newly created image object
|
||||
def add_image(image, file=nil)
|
||||
template = image.to_one_template
|
||||
|
||||
if file
|
||||
if file[:tempfile]
|
||||
file_path = file[:tempfile].path
|
||||
template << "\nPATH = #{file_path}"
|
||||
else
|
||||
error_msg = "Image not present, aborting."
|
||||
error = OpenNebula::Error.new(error_msg)
|
||||
return error
|
||||
end
|
||||
end
|
||||
|
||||
rc = @img_repo.create(image, template)
|
||||
|
||||
file[:tempfile].unlink if file
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
return rc
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
# Finds out if a port is available on ip
|
||||
# ip:: _String_ IP address where the port to check is
|
||||
|
@ -111,11 +111,16 @@ class EC2QueryServer < CloudServer
|
||||
###########################################################################
|
||||
|
||||
def upload_image(params, one_client)
|
||||
image = ImageEC2.new(Image.build_xml, one_client)
|
||||
image = ImageEC2.new(Image.build_xml, one_client, params['file'])
|
||||
|
||||
rc = add_image(image, params['file'])
|
||||
template = image.to_one_template
|
||||
if OpenNebula.is_error?(template)
|
||||
return OpenNebula::Error.new('Unsupported'), 400
|
||||
end
|
||||
|
||||
rc = image.allocate(template)
|
||||
if OpenNebula.is_error?(rc)
|
||||
return OpenNebula::Error.new('Unsupported'),400
|
||||
return OpenNebula::Error.new('Unsupported'), 400
|
||||
end
|
||||
|
||||
erb_version = params['Version']
|
||||
|
@ -24,8 +24,21 @@ class ImageEC2 < Image
|
||||
ONE_IMAGE = %q{
|
||||
NAME = "ec2-<%= uuid %>"
|
||||
TYPE = OS
|
||||
<% if @image_file != nil %>
|
||||
PATH = "<%= @image_file %>"
|
||||
<% end %>
|
||||
}.gsub(/^ /, '')
|
||||
|
||||
|
||||
def initialize(xml, client, file=nil)
|
||||
super(xml, client)
|
||||
@image_info = nil
|
||||
@image_file = file
|
||||
|
||||
if file && file[:tempfile]
|
||||
@image_file = file[:tempfile].path
|
||||
end
|
||||
end
|
||||
|
||||
def to_one_template()
|
||||
uuid = UUID.generate
|
||||
|
||||
|
@ -1,25 +1,27 @@
|
||||
<?xml version="1.0"?>
|
||||
<DescribeImagesResponse xmlns="http://ec2.amazonaws.com/doc/<%=erb_version%>/">
|
||||
<imagesSet>
|
||||
<imagesSet>
|
||||
<% impool.each do |im| %>
|
||||
<% im.info %>
|
||||
<item>
|
||||
<item>
|
||||
<imageId>ami-<%= sprintf('%08i', im.id) %></imageId>
|
||||
<imageLocation><%= im['SOURCE'].split('/').last %></imageLocation>
|
||||
<% if im['STATE'] == '3' %>
|
||||
<imageState>deregistered</imageState>
|
||||
<% if im['STATE'] == '3' || im['STATE'] == '5' %>
|
||||
<imageState>failed</imageState>
|
||||
<% elsif im['STATE'] == '1' || im['STATE'] == '2' %>
|
||||
<imageState>available</imageState>
|
||||
<imageState>available</imageState>
|
||||
<% elsif im['STATE'] == '4'%>
|
||||
<imageState>pending</imageState>
|
||||
<% end %>
|
||||
<imageOwnerId><%= erb_user_name %></imageOwnerId>
|
||||
<imageOwnerId><%= erb_user_name %></imageOwnerId>
|
||||
<% if im['PUBLIC'] == '0' %>
|
||||
<isPublic>false</isPublic>
|
||||
<isPublic>false</isPublic>
|
||||
<% elsif im['PUBLIC'] == '1' %>
|
||||
<isPublic>true</isPublic>
|
||||
<isPublic>true</isPublic>
|
||||
<% end %>
|
||||
<architecture>i386</architecture>
|
||||
<imageType>machine</imageType>
|
||||
</item>
|
||||
<architecture>i386</architecture>
|
||||
<imageType>machine</imageType>
|
||||
</item>
|
||||
<% end %>
|
||||
</imagesSet>
|
||||
</DescribeImagesResponse>
|
||||
</imagesSet>
|
||||
</DescribeImagesResponse>
|
||||
|
Loading…
x
Reference in New Issue
Block a user