1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-15 23:24:09 +03:00

Add save_as functionality to OCCI

This commit is contained in:
Daniel Molina 2010-12-02 19:26:02 +01:00
parent d38f7cc49b
commit 3e9627c946
2 changed files with 35 additions and 11 deletions

View File

@ -213,19 +213,40 @@ class OCCIServer < CloudServer
xmldoc = XMLElement.build_xml(request.body, 'COMPUTE')
vm_info = XMLElement.new(xmldoc) if xmldoc != nil
# --- Get the VM and Action on it ---
if vm_info['STATE'] != nil
vm = VirtualMachineOCCI.new(
VirtualMachine.build_xml(params[:id]),
get_client(request.env))
vm = VirtualMachineOCCI.new(
VirtualMachine.build_xml(params[:id]),
get_client(request.env))
rc = vm.info
return rc, 400 if OpenNebula.is_error?(rc)
if image_name = vm_info.attr('DISK/SAVE_AS', 'name')
# Get the disk id
disk_id = vm_info.attr('DISK/SAVE_AS/..', 'id')
if disk_id.nil?
error_msg = "DISK id attribute not specified"
return OpenNebula::Error.new(error_msg), 400
else
disk_id = disk_id.to_i
end
# Create a new Image to save the disk
template = "NAME=\"#{image_name}\"\n"
template << "TYPE=OS\n"
rc = vm.mk_action(vm_info['STATE'])
image = Image.new(Image.build_xml, one_client)
rc = image.allocate(template)
return rc, 400 if OpenNebula.is_error?(rc)
rc = vm.save_as(disk_id, image.id)
if OpenNebula.is_error?(rc)
image.delete
return rc, 400
end
elsif state = vm_info['STATE']
rc = vm.mk_action(state)
return rc, 400 if OpenNebula.is_error?(rc)
else
error_msg = "State not defined in the OCCI XML"
error = OpenNebula::Error.new(error_msg)
return error, 400
end
# --- Prepare XML Response ---

View File

@ -30,7 +30,10 @@ class VirtualMachineOCCI < VirtualMachine
<% end %>
<STATE><%= self.state_str %></STATE>
<% self.each('TEMPLATE/DISK') do |disk| %>
<DISK>
<DISK id="<%= disk['DISK_ID']%>">
<% if disk['SAVE_AS'] %>
<SAVE_AS href="<%= base_url %>/storage/<%= disk['SAVE_AS'] %>"/>
<% end %>
<STORAGE href="<%= base_url %>/storage/<%= disk['IMAGE_ID'] %>" name="<%= disk['IMAGE'] %>"/>
<TYPE><%= disk['TYPE'] %></TYPE>
<TARGET><%= disk['TARGET'] %></TARGET>