1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-29 11:21:30 +03:00

Add storage publishing and persistent functionality to OCCI

This commit is contained in:
Daniel Molina 2010-12-02 19:23:44 +01:00
parent 40f282cd8a
commit d38f7cc49b
5 changed files with 103 additions and 4 deletions

View File

@ -36,18 +36,23 @@ Usage:
Commands:
create <occi xml file>
* create <occi xml file>
creates a new storage resource described by the provided
<occi xml file>
list
* list
lists available storage resources
show <storage id>
* show <storage id>
retrieves the OCCI XML representation of the storage resource
identified by <storage id>
delete <storage id>
* 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>
@ -166,6 +171,16 @@ case ARGV[0].downcase
rc = occi_client.get_image(image_id)
when 'update'
image_xml = ARGV[1]
if !image_xml || !File.exists?(image_xml)
puts "#{cmd_name} update: missing OCCI-XML or file not found"
exit -1
end
rc = occi_client.put_image(image_xml)
when 'delete'
image_id = ARGV[1]

View File

@ -35,6 +35,8 @@ class ImageOCCI < Image
<% if fstype != nil %>
<FSTYPE><%= fstype %></FSTYPE>
<% end %>
<PUBLIC><%= self['PUBLIC'] == "0" ? "NO" : "YES"%></PUBLIC>
<PERSISTENT><%= self['PERSISTENT'] == "0" ? "NO" : "YES"%></PERSISTENT>
</STORAGE>
}
@ -44,6 +46,12 @@ class ImageOCCI < Image
<% if @image_info['DESCRIPTION'] != nil %>
DESCRIPTION = "<%= @image_info['DESCRIPTION'] %>"
<% end %>
<% if @image_info['PUBLIC'] != nil %>
PUBLIC = "<%= @image_info['PUBLIC'] %>"
<% end %>
<% if @image_info['PERSISTENT'] != nil %>
PERSISTENT = "<%= @image_info['PERSISTENT'] %>"
<% end %>
<% if @image_info['TYPE'] != nil %>
TYPE = <%= @image_info['TYPE'] %>
<% end %>

View File

@ -425,6 +425,43 @@ module OCCIClient
end
end
######################################################################
# Puts a new Storage representation in order to change its state
# :xmlfile Storage OCCI xml representation
######################################################################
def put_image(xmlfile)
xml = File.read(xmlfile)
begin
image_info = REXML::Document.new(xml).root
rescue Exception => e
error = OpenNebula::Error.new(e.message)
return error
end
if image_info.elements['ID'] == nil
return CloudClient::Error.new("Can not find STORAGE_ID")
end
image_id = image_info.elements['ID'].text
url = URI.parse(@endpoint+'/storage/' + image_id)
req = Net::HTTP::Put.new(url.path)
req.body = xml
req.basic_auth @occiauth[0], @occiauth[1]
res = CloudClient::http_start(url, @timeout) do |http|
http.request(req)
end
if CloudClient::is_error?(res)
return res
else
return res.body
end
end
######################################################################
# :id VM identifier
######################################################################

View File

@ -391,4 +391,38 @@ class OCCIServer < CloudServer
return "", 204
end
# Updates a STORAGE resource
# request:: _Hash_ hash containing the data of the request
# [return] _String_,_Integer_ Update confirmation msg or error,
# status code
def put_storage(request, params)
xmldoc = XMLElement.build_xml(request.body, 'STORAGE')
image_info = XMLElement.new(xmldoc) if xmldoc != nil
image = ImageOCCI.new(
Image.build_xml(params[:id]),
get_client(request.env))
rc = image.info
return rc, 400 if OpenNebula.is_error?(rc)
if image_info['PERSISTENT'] == 'YES'
rc = image.persistent
return rc, 400 if OpenNebula.is_error?(rc)
elsif image_info['PERSISTENT'] == 'NO'
rc = image.nonpersistent
return rc, 400 if OpenNebula.is_error?(rc)
elsif image_info['PUBLIC'] == 'YES'
rc = image.publish
return rc, 400 if OpenNebula.is_error?(rc)
elsif image_info['PUBLIC'] == 'NO'
rc = image.unpublish
return rc, 400 if OpenNebula.is_error?(rc)
end
# --- Prepare XML Response ---
image.info
return to_occi_xml(image, 202)
end
end

View File

@ -165,3 +165,8 @@ delete '/storage/:id' do
result,rc = $occi_server.delete_storage(request, params)
treat_response(result,rc)
end
put '/storage/:id' do
result,rc = $occi_server.put_storage(request, params)
treat_response(result,rc)
end