diff --git a/src/cloud/occi/lib/OCCIServer.rb b/src/cloud/occi/lib/OCCIServer.rb index 1b38ca0807..193132c30b 100755 --- a/src/cloud/occi/lib/OCCIServer.rb +++ b/src/cloud/occi/lib/OCCIServer.rb @@ -40,7 +40,7 @@ require 'pp' # OpenNebula Engine ############################################################################## -COLLECTIONS = ["compute", "instance_type", "network", "storage"] +COLLECTIONS = ["compute", "instance_type", "network", "storage", "user"] # FLAG that will filter the elements retrieved from the Pools POOL_FILTER = Pool::INFO_ALL @@ -92,18 +92,36 @@ class OCCIServer < CloudServer return xml_resp, 200 end + + INSTANCE_TYPE = %q{ + + <%= name.to_s %> + <%= name.to_s %> + <% opts.each { |elem, value| + next if elem==:template + str = elem.to_s.upcase %> + <<%= str %>><%= value %>> + <% } %> + + } + def get_instance_types(request) xml_resp = "\n" - @config[:instance_types].each { |k, v| - xml_resp << "\t\n" - xml_resp << "\t\t#{k.to_s}\n" - v.each { |elem, value| - next if elem==:template - str = elem.to_s.upcase - xml_resp << "\t\t<#{str}>#{value}\n" - } - xml_resp << "\t\n" + @config[:instance_types].each { |name, opts| + if request.params['verbose'] + begin + occi_it = ERB.new(INSTANCE_TYPE) + occi_it = occi_it.result(binding) + rescue Exception => e + error = OpenNebula::Error.new(e.message) + return error, CloudServer::HTTP_ERROR_CODE[error.errno] + end + + xml_resp << occi_it.gsub(/\n\s*/,'') + else + xml_resp << "\t\n" + end } xml_resp << "" @@ -111,6 +129,24 @@ class OCCIServer < CloudServer return xml_resp, 200 end + def get_instance_type(request, params) + name = params[:id].to_sym + unless @config[:instance_types].keys.include?(name) + error = OpenNebula::Error.new("INSTANCE_TYPE #{name} not found") + return error, 404 + else + opts = @config[:instance_types][name] + begin + occi_it = ERB.new(INSTANCE_TYPE) + occi_it = occi_it.result(binding) + rescue Exception => e + error = OpenNebula::Error.new(e.message) + return error, CloudServer::HTTP_ERROR_CODE[error.errno] + end + + return occi_it.gsub(/\n\s*/,''), 200 + end + end # Gets the pool representation of COMPUTES # request:: _Hash_ hash containing the data of the request diff --git a/src/cloud/occi/lib/occi-server.rb b/src/cloud/occi/lib/occi-server.rb index 8bee03b296..10b814e5f2 100755 --- a/src/cloud/occi/lib/occi-server.rb +++ b/src/cloud/occi/lib/occi-server.rb @@ -305,6 +305,11 @@ get '/user/:id' do treat_response(result,rc) end +get '/instance_type/:id' do + result,rc = @occi_server.get_instance_type(request, params) + treat_response(result,rc) +end + ############################################## ## OCCI UI (Self-Service) ##############################################