mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-27 10:50:10 +03:00
feature #2259: CreateVolume from Snapshot
This commit is contained in:
parent
2052d9f631
commit
8f5a102248
@ -55,7 +55,7 @@ class ImageEC2 < Image
|
||||
<% if @image_info[:persistent] != nil %>
|
||||
PERSISTENT = "YES"
|
||||
<% end %>
|
||||
<% if @image_info[:ebs] != nil %>
|
||||
<% if @image_info[:ebs_volume] != nil %>
|
||||
EBS_VOLUME = "YES"
|
||||
<% end %>
|
||||
<% if @image_file != nil %>
|
||||
|
@ -168,34 +168,65 @@ module EBS
|
||||
# the new volume (unsupported).
|
||||
# @option params [String] AvailabilityZone The Availability Zone in which
|
||||
# to create the new volume (unsupported)
|
||||
# TODO: Availability zone
|
||||
def create_volume(params)
|
||||
size = params['Size'].to_i # in GiBs
|
||||
size *= 1024
|
||||
snapshot_id = params['SnapshotId']
|
||||
if snapshot_id
|
||||
snapshot_id = snapshot_id.split('-')[1]
|
||||
|
||||
opts = {
|
||||
:type => "DATABLOCK",
|
||||
:size => size,
|
||||
:fstype => @config[:ebs_fstype]||DEFAULT_FSTYPE,
|
||||
:persistent => "YES",
|
||||
:ebs => "YES"
|
||||
}
|
||||
snapshot = ImageEC2.new(Image.build_xml(snapshot_id.to_i), @client)
|
||||
rc = snapshot.info
|
||||
if OpenNebula::is_error?(rc) || !snapshot.ebs_snapshot?
|
||||
rc ||= OpenNebula::Error.new()
|
||||
rc.ec2_code = "InvalidSnapshot.NotFound"
|
||||
return rc
|
||||
end
|
||||
|
||||
image = ImageEC2.new(Image.build_xml, @client, nil, opts)
|
||||
template = image.to_one_template
|
||||
# Clone
|
||||
volume_id = snapshot.clone(ImageEC2.generate_uuid)
|
||||
if OpenNebula::is_error?(volume_id)
|
||||
return volume_id
|
||||
end
|
||||
|
||||
if OpenNebula.is_error?(template)
|
||||
return template
|
||||
volume = ImageEC2.new(Image.build_xml(volume_id.to_i), @client)
|
||||
rc = volume.info
|
||||
if OpenNebula::is_error?(rc)
|
||||
return rc
|
||||
end
|
||||
|
||||
volume.delete_element("TEMPLATE/EBS_SNAPSHOT")
|
||||
volume.add_element('TEMPLATE', {
|
||||
"EBS_VOLUME" => "YES",
|
||||
"EBS_FROM_SNAPSHOT_ID" => snapshot.ec2_id})
|
||||
volume.update
|
||||
else
|
||||
size = params['Size'].to_i # in GiBs
|
||||
size *= 1024
|
||||
|
||||
opts = {
|
||||
:type => "DATABLOCK",
|
||||
:size => size,
|
||||
:fstype => @config[:ebs_fstype]||DEFAULT_FSTYPE,
|
||||
:persistent => "YES",
|
||||
:ebs_volume => "YES"
|
||||
}
|
||||
|
||||
volume = ImageEC2.new(Image.build_xml, @client, nil, opts)
|
||||
template = volume.to_one_template
|
||||
|
||||
if OpenNebula.is_error?(template)
|
||||
return template
|
||||
end
|
||||
|
||||
rc = volume.allocate(template, @config[:datastore_id]||1)
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
return rc
|
||||
end
|
||||
|
||||
volume.info
|
||||
end
|
||||
|
||||
rc = image.allocate(template, @config[:datastore_id]||1)
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
return rc
|
||||
end
|
||||
|
||||
# Response
|
||||
image.info
|
||||
|
||||
erb_version = params['Version']
|
||||
response = ERB.new(File.read(@config[:views]+"/create_volume.erb"))
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
<?xml version="1.0"?>
|
||||
<CreateVolumeResponse xmlns="http://ec2.amazonaws.com/doc/<%=erb_version%>/">
|
||||
<requestId><%= @request_id %></requestId>
|
||||
<volumeId>vol-<%= sprintf('%08i', image.id) %></volumeId>
|
||||
<size><%= image.render_size %></size>
|
||||
<volumeId><%= volume.ec2_id %></volumeId>
|
||||
<size><%= volume.render_size %></size>
|
||||
<snapshotId/>
|
||||
<availabilityZone/>
|
||||
<status><%= image.render_state %></status>
|
||||
<createTime><%= image.render_create_time %></createTime>
|
||||
<status><%= volume.render_state %></status>
|
||||
<createTime><%= volume.render_create_time %></createTime>
|
||||
</CreateVolumeResponse>
|
||||
|
@ -7,7 +7,7 @@
|
||||
<item>
|
||||
<volumeId>vol-<%= sprintf('%08i', im.id) %></volumeId>
|
||||
<size><%= im.render_size %></size>
|
||||
<snapshotId/>
|
||||
<snapshotId><%= im["TEMPLATE/EBS_FROM_SNAPSHOT_ID"] %></snapshotId>
|
||||
<availabilityZone/>
|
||||
<status><%= state_image %></status>
|
||||
<createTime><%= im.render_create_time %></createTime>
|
||||
|
Loading…
x
Reference in New Issue
Block a user