1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-02-23 21:57:43 +03:00

feature #1356: Add storage clone action

This commit is contained in:
Daniel Molina 2012-08-31 14:58:12 +02:00
parent 22e3c3fdd6
commit 9d07a15c9a
4 changed files with 77 additions and 4 deletions

View File

@ -51,10 +51,14 @@ Commands:
* update <occi xml file>
updates the representation of the storage resource represented by the
provided <occi xml file>
* delete <storage id>
deletes the storage resource idenfitied by <storage id>
* clone <storage id> <name>
clones the storage resource idenfitied by <storage id> in a new one
using the given <name>
Options:
@ -205,6 +209,28 @@ case ARGV[0].downcase
rc = occi_client.delete_image(image_id)
when 'clone'
image_id = ARGV[1]
name = ARGV[2]
if !image_id
puts "#{cmd_name} clone: missing storage id parameter"
exit(-1)
end
if !name
puts "#{cmd_name} clone: missing name parameter"
exit(-1)
end
xml = "<ACTION>"
xml << " <PERFORM>CLONE</PERFORM>"
xml << " <PARAMS>"
xml << " <NAME>#{name}</NAME>"
xml << " </PARAMS>"
xml << "</ACTION>"
rc = occi_client.action_image(image_id, xml)
else
puts "Command #{ARGV[0]} not valid."
exit(-1)
@ -213,7 +239,7 @@ end
if CloudClient::is_error?(rc)
puts rc.to_s()
exit(-1)
else
else
str, code = print_xml(rc)
puts str
exit(code)

View File

@ -279,6 +279,10 @@ module OCCIClient
delete('/storage/'+id.to_s)
end
def action_image(id, xml)
post('/storage/'+id.to_s+'/action', xml, false)
end
private
def get(path, verbose=false)
@ -289,11 +293,15 @@ module OCCIClient
do_request(url, req)
end
def post(path, xmlfile)
def post(path, xmlfile, file=true)
url = URI.parse(@endpoint+path)
req = Net::HTTP::Post.new(url.path)
req.body=File.read(xmlfile)
if file
req.body=File.read(xmlfile)
else
req.body=xmlfile
end
do_request(url, req)
end

View File

@ -481,6 +481,31 @@ class OCCIServer < CloudServer
return to_occi_xml(image, :code=>200)
end
# Clone a STORAGE resource
# request:: _Hash_ hash containing the data of the request
# [return] _String_,_Integer_ STORAGE occi representation or error,
# status code
def clone_storage(request, params, action_xml)
# --- Get the Image ---
image = ImageOCCI.new(
Image.build_xml(params[:id]),
@client)
rc = image.clone(action_xml["PARAMS/NAME"])
if OpenNebula.is_error?(rc)
return rc, CloudServer::HTTP_ERROR_CODE[rc.errno]
end
new_image = ImageOCCI.new(
Image.build_xml(rc),
@client)
new_image.info
# --- Prepare XML Response ---
return to_occi_xml(new_image, :code=>201)
end
# Deletes a STORAGE resource (Not yet implemented)
# request:: _Hash_ hash containing the data of the request
# [return] _String_,_Integer_ Delete confirmation msg or error,

View File

@ -345,6 +345,20 @@ get '/storage/:id' do
treat_response(result,rc)
end
post '/storage/:id/action' do
xml = XMLElement.new
xml.initialize_xml(request.body, "ACTION")
result, rc = case xml['PERFORM'].downcase
when 'clone' then
@occi_server.clone_storage(request, params, xml)
else
halt 403, "Action #{xml['PERFORM']} not supported"
end
treat_response(result,rc)
end
delete '/storage/:id' do
result,rc = @occi_server.delete_storage(request, params)
treat_response(result,rc)