mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-19 03:12:55 +09:00
feature #2259: Add CreateImage
This commit is contained in:
1 parent
336b926ad8
commit
0b68e9b59a
5 files changed
+42
No files matched your search
@@ -1296,6 +1296,7 @@ ECO_LIB_VIEW_FILES="src/cloud/ec2/lib/views/describe_images.erb \
|
||||
src/cloud/ec2/lib/views/describe_regions.erb \
|
||||
src/cloud/ec2/lib/views/describe_availability_zones.erb \
|
||||
src/cloud/ec2/lib/views/create_volume.erb \
|
||||
src/cloud/ec2/lib/views/create_image.erb \
|
||||
src/cloud/ec2/lib/views/describe_volumes.erb \
|
||||
src/cloud/ec2/lib/views/attach_volume.erb \
|
||||
src/cloud/ec2/lib/views/detach_volume.erb \
|
||||
|
||||
@@ -182,6 +182,40 @@ class EC2QueryServer < CloudServer
|
||||
return response.result(binding), 200
|
||||
end
|
||||
|
||||
# TODO: NoReboot = false, cleanly shut down the instance before image
|
||||
# creation and then reboots the instance.
|
||||
# TODO: If you customized your instance with instance store volumes
|
||||
# or EBS volumes in addition to the root device volume, the
|
||||
# new AMI contains block device mapping information for those volumes
|
||||
def create_image(params)
|
||||
instance_id = params['InstanceId']
|
||||
instance_id = instance_id.split('-')[1]
|
||||
|
||||
vm = VirtualMachine.new(
|
||||
VirtualMachine.build_xml(instance_id),
|
||||
@client)
|
||||
|
||||
rc = vm.info
|
||||
if OpenNebula::is_error?(rc)
|
||||
rc.ec2_code = "InvalidInstanceID.NotFound"
|
||||
return rc
|
||||
end
|
||||
|
||||
image_id = vm.disk_snapshot(1,
|
||||
params["Name"],
|
||||
OpenNebula::Image::IMAGE_TYPES[0],
|
||||
true)
|
||||
|
||||
if OpenNebula::is_error?(image_id)
|
||||
return image_id
|
||||
end
|
||||
|
||||
erb_version = params['Version']
|
||||
|
||||
response = ERB.new(File.read(@config[:views]+"/create_image.erb"))
|
||||
return response.result(binding), 200
|
||||
end
|
||||
|
||||
###########################################################################
|
||||
# Helper functions
|
||||
###########################################################################
|
||||
|
||||
@@ -134,6 +134,8 @@ class EC2Application
|
||||
result,rc = econe_server.describe_regions(params)
|
||||
when 'DescribeAvailabilityZones'
|
||||
result,rc = econe_server.describe_availability_zones(params)
|
||||
when 'CreateImage'
|
||||
result,rc = econe_server.create_image(params)
|
||||
when 'CreateVolume'
|
||||
result,rc = econe_server.create_volume(params)
|
||||
when 'DescribeVolumes'
|
||||
|
||||
@@ -205,6 +205,7 @@ module Instance
|
||||
|
||||
rc = vm.info
|
||||
if OpenNebula::is_error?(rc)
|
||||
rc.ec2_code = "InvalidInstanceID.NotFound"
|
||||
return rc
|
||||
end
|
||||
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
<CreateImageResponse xmlns="http://ec2.amazonaws.com/doc/2013-06-15/">
|
||||
<requestId><%= @request_id %></requestId>
|
||||
<imageId>ami-<%= sprintf('%08i', image_id) %></imageId>
|
||||
</CreateImageResponse>
|
||||
Reference in new issue
Block a user