mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
Add instance types retrieval through OCCI
New get method over /compute/types, returns XML in the following format: <ALLOWED_COMPUTE_TYPES> <COMPUTE_TYPE> <NAME>XLARGE</NAME> <vCPU>4</vCPU> <vMEM>1024</vMEM> </COMPUTE_TYPE> <COMPUTE_TYPE> <NAME>SMALL</NAME> <vCPU>1</vCPU> <vMEM>512</vMEM> </COMPUTE_TYPE> </ALLOWED_COMPUTE_TYPES>
This commit is contained in:
parent
51cd4a26bb
commit
003a47fb8a
@ -504,4 +504,43 @@ class OCCIServer < CloudServer
|
||||
|
||||
return to_occi_xml(user, 200)
|
||||
end
|
||||
|
||||
############################################################################
|
||||
############################################################################
|
||||
# BonFIRE Specific
|
||||
############################################################################
|
||||
############################################################################
|
||||
def get_computes_types
|
||||
etc_location=ONE_LOCATION ? ONE_LOCATION+"/etc" : "/etc/one"
|
||||
begin
|
||||
xml_response = "<ALLOWED_COMPUTE_TYPES>\n"
|
||||
|
||||
Dir[etc_location + "/occi_templates/**"].each{| filename |
|
||||
next if File.basename(filename) == "common.erb"
|
||||
xml_response += "\t<COMPUTE_TYPE>"
|
||||
xml_response += "\t\t<NAME>#{File.basename(filename)[0..-5]}</NAME>"
|
||||
file = File.open(filename, "r")
|
||||
file.each_line{|line|
|
||||
next if line.match(/^#/)
|
||||
match=line.match(/^(.*)=(.*)/)
|
||||
next if !match
|
||||
case match[1].strip
|
||||
when "NAME"
|
||||
xml_response += "\t\t<NAME>#{match[2].strip}</NAME>"
|
||||
when "CPU"
|
||||
xml_response += "\t\t<vCPU>#{match[2].strip}</vCPU>"
|
||||
when "MEMORY"
|
||||
xml_response += "\t\t<vMEM>#{match[2].strip}</vMEM>"
|
||||
end
|
||||
}
|
||||
xml_response += "\t</COMPUTE_TYPE>"
|
||||
}
|
||||
|
||||
xml_response += "</ALLOWED_COMPUTE_TYPES>"
|
||||
|
||||
return xml_response, 200
|
||||
rescue Exception => e
|
||||
return "Error getting the instance types. Reason: #{e.message}", 500
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -172,7 +172,11 @@ end
|
||||
###################################################
|
||||
|
||||
get '/compute/:id' do
|
||||
result,rc = @occi_server.get_compute(request, params)
|
||||
if params[:id] == "types" # Specific BonFIRE functionality
|
||||
result,rc = @occi_server.get_computes_types
|
||||
else
|
||||
result,rc = @occi_server.get_compute(request, params)
|
||||
end
|
||||
treat_response(result,rc)
|
||||
end
|
||||
|
||||
@ -219,4 +223,4 @@ end
|
||||
get '/user/:id' do
|
||||
result,rc = @occi_server.get_user(request, params)
|
||||
treat_response(result,rc)
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user