mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
feature #1091: Add extended information to the OCCI pools
This commit is contained in:
parent
59419f54df
commit
ab5db1ceb3
@ -14,20 +14,21 @@
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
require 'OpenNebula'
|
||||
|
||||
include OpenNebula
|
||||
require 'ImageOCCI'
|
||||
|
||||
class ImagePoolOCCI < ImagePool
|
||||
OCCI_IMAGE_POOL = %q{
|
||||
<STORAGE_COLLECTION>
|
||||
<% self.each{ |im| %>
|
||||
<% if verbose %>
|
||||
<%= im.to_occi(base_url) %>
|
||||
<% else %>
|
||||
<STORAGE href="<%= base_url %>/storage/<%= im.id.to_s %>" name="<%= im.name %>"/>
|
||||
<% end %>
|
||||
<% } %>
|
||||
</STORAGE_COLLECTION>
|
||||
}
|
||||
|
||||
|
||||
# Creates the OCCI representation of a Virtual Machine Pool
|
||||
def to_occi(base_url)
|
||||
begin
|
||||
@ -40,5 +41,9 @@ class ImagePoolOCCI < ImagePool
|
||||
|
||||
return occi_text.gsub(/\n\s*/,'')
|
||||
end
|
||||
|
||||
def factory(element_xml)
|
||||
ImageOCCI.new(element_xml,@client)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -62,11 +62,11 @@ class OCCIServer < CloudServer
|
||||
# Prepare the OCCI XML Response
|
||||
# resource:: _Pool_ or _PoolElement_ that represents a OCCI resource
|
||||
# [return] _String_,_Integer_ Resource Representation or error, status code
|
||||
def to_occi_xml(resource, code)
|
||||
xml_response = resource.to_occi(@base_url)
|
||||
def to_occi_xml(resource, opts)
|
||||
xml_response = resource.to_occi(@base_url, opts[:verbose])
|
||||
return xml_response, 500 if OpenNebula.is_error?(xml_response)
|
||||
|
||||
return xml_response, code
|
||||
return xml_response, opts[:code]
|
||||
end
|
||||
|
||||
############################################################################
|
||||
@ -122,7 +122,7 @@ class OCCIServer < CloudServer
|
||||
return rc, CloudServer::HTTP_ERROR_CODE[rc.errno]
|
||||
end
|
||||
|
||||
return to_occi_xml(vmpool, 200)
|
||||
return to_occi_xml(vmpool, :status=>200, :verbose=>request.params['verbose'])
|
||||
end
|
||||
|
||||
|
||||
@ -142,7 +142,7 @@ class OCCIServer < CloudServer
|
||||
return rc, CloudServer::HTTP_ERROR_CODE[rc.errno]
|
||||
end
|
||||
|
||||
return to_occi_xml(network_pool, 200)
|
||||
return to_occi_xml(network_pool, :status=>200, :verbose=>request.params['verbose'])
|
||||
end
|
||||
|
||||
# Gets the pool representation of STORAGES
|
||||
@ -161,7 +161,7 @@ class OCCIServer < CloudServer
|
||||
return rc, CloudServer::HTTP_ERROR_CODE[rc.errno]
|
||||
end
|
||||
|
||||
return to_occi_xml(image_pool, 200)
|
||||
return to_occi_xml(image_pool, :status=>200, :verbose=>request.params['verbose'])
|
||||
end
|
||||
|
||||
# Gets the pool representation of USERs
|
||||
@ -178,7 +178,7 @@ class OCCIServer < CloudServer
|
||||
return rc, CloudServer::HTTP_ERROR_CODE[rc.errno]
|
||||
end
|
||||
|
||||
return to_occi_xml(user_pool, 200)
|
||||
return to_occi_xml(user_pool, :status=>200, :verbose=>request.params['verbose'])
|
||||
end
|
||||
|
||||
############################################################################
|
||||
@ -214,7 +214,7 @@ class OCCIServer < CloudServer
|
||||
|
||||
# --- Prepare XML Response ---
|
||||
vm.info
|
||||
return to_occi_xml(vm, 201)
|
||||
return to_occi_xml(vm, :status=>201)
|
||||
end
|
||||
|
||||
# Get the representation of a COMPUTE resource
|
||||
@ -233,7 +233,7 @@ class OCCIServer < CloudServer
|
||||
return rc, CloudServer::HTTP_ERROR_CODE[rc.errno]
|
||||
end
|
||||
|
||||
return to_occi_xml(vm, 200)
|
||||
return to_occi_xml(vm, :status=>200)
|
||||
end
|
||||
|
||||
|
||||
@ -277,7 +277,7 @@ class OCCIServer < CloudServer
|
||||
return result, code
|
||||
else
|
||||
vm.info
|
||||
return to_occi_xml(vm, code)
|
||||
return to_occi_xml(vm, :status=>code)
|
||||
end
|
||||
end
|
||||
|
||||
@ -307,7 +307,7 @@ class OCCIServer < CloudServer
|
||||
|
||||
# --- Prepare XML Response ---
|
||||
network.info
|
||||
return to_occi_xml(network, 201)
|
||||
return to_occi_xml(network, :status=>201)
|
||||
end
|
||||
|
||||
# Retrieves a NETWORK resource
|
||||
@ -325,7 +325,7 @@ class OCCIServer < CloudServer
|
||||
return rc, CloudServer::HTTP_ERROR_CODE[rc.errno]
|
||||
end
|
||||
|
||||
return to_occi_xml(network, 200)
|
||||
return to_occi_xml(network, :status=>200)
|
||||
end
|
||||
|
||||
# Deletes a NETWORK resource
|
||||
@ -371,7 +371,7 @@ class OCCIServer < CloudServer
|
||||
|
||||
# --- Prepare XML Response ---
|
||||
vnet.info
|
||||
return to_occi_xml(vnet, 202)
|
||||
return to_occi_xml(vnet, :status=>202)
|
||||
end
|
||||
|
||||
############################################################################
|
||||
@ -411,7 +411,7 @@ class OCCIServer < CloudServer
|
||||
|
||||
# --- Prepare XML Response ---
|
||||
image.info
|
||||
return to_occi_xml(image, 201)
|
||||
return to_occi_xml(image, :status=>201)
|
||||
end
|
||||
|
||||
# Get a STORAGE resource
|
||||
@ -430,7 +430,7 @@ class OCCIServer < CloudServer
|
||||
end
|
||||
|
||||
# --- Prepare XML Response ---
|
||||
return to_occi_xml(image, 200)
|
||||
return to_occi_xml(image, :status=>200)
|
||||
end
|
||||
|
||||
# Deletes a STORAGE resource (Not yet implemented)
|
||||
@ -484,7 +484,7 @@ class OCCIServer < CloudServer
|
||||
|
||||
# --- Prepare XML Response ---
|
||||
image.info
|
||||
return to_occi_xml(image, 202)
|
||||
return to_occi_xml(image, :status=>202)
|
||||
end
|
||||
|
||||
# Get the representation of a USER
|
||||
@ -503,6 +503,6 @@ class OCCIServer < CloudServer
|
||||
return rc, CloudServer::HTTP_ERROR_CODE[rc.errno]
|
||||
end
|
||||
|
||||
return to_occi_xml(user, 200)
|
||||
return to_occi_xml(user, :status=>200)
|
||||
end
|
||||
end
|
||||
|
@ -14,20 +14,21 @@
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
require 'OpenNebula'
|
||||
|
||||
include OpenNebula
|
||||
require 'UserOCCI'
|
||||
|
||||
class UserPoolOCCI < UserPool
|
||||
OCCI_USER_POOL = %q{
|
||||
<USER_COLLECTION>
|
||||
<% self.each{ |user| %>
|
||||
<% if verbose %>
|
||||
<%= user.to_occi(base_url) %>
|
||||
<% else %>
|
||||
<USER href="<%= base_url %>/user/<%= user.id.to_s %>" name="<%= user.name %>"/>
|
||||
<% end %>
|
||||
<% } %>
|
||||
</USER_COLLECTION>
|
||||
}
|
||||
|
||||
|
||||
# Creates the OCCI representation of a User Pool
|
||||
def to_occi(base_url)
|
||||
begin
|
||||
@ -40,4 +41,8 @@ class UserPoolOCCI < UserPool
|
||||
|
||||
return occi_text.gsub(/\n\s*/,'')
|
||||
end
|
||||
|
||||
def factory(element_xml)
|
||||
UserOCCI.new(element_xml,@client)
|
||||
end
|
||||
end
|
@ -14,22 +14,24 @@
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
require 'OpenNebula'
|
||||
|
||||
include OpenNebula
|
||||
require 'VirtualMachineOCCI'
|
||||
|
||||
class VirtualMachinePoolOCCI < VirtualMachinePool
|
||||
OCCI_VM_POOL = %q{
|
||||
<COMPUTE_COLLECTION>
|
||||
<% self.each{ |vm| %>
|
||||
<% self.each{ |vm| %>
|
||||
<% if verbose %>
|
||||
<%= vm.to_occi(base_url) %>
|
||||
<% else %>
|
||||
<COMPUTE href="<%= base_url %>/compute/<%= vm.id.to_s %>" name="<%= vm.name %>"/>
|
||||
<% end %>
|
||||
<% } %>
|
||||
</COMPUTE_COLLECTION>
|
||||
}
|
||||
|
||||
|
||||
# Creates the OCCI representation of a Virtual Machine Pool
|
||||
def to_occi(base_url)
|
||||
def to_occi(base_url, verbose=false)
|
||||
begin
|
||||
occi = ERB.new(OCCI_VM_POOL)
|
||||
occi_text = occi.result(binding)
|
||||
@ -40,5 +42,9 @@ class VirtualMachinePoolOCCI < VirtualMachinePool
|
||||
|
||||
return occi_text.gsub(/\n\s*/,'')
|
||||
end
|
||||
|
||||
def factory(element_xml)
|
||||
VirtualMachineOCCI.new(element_xml,@client)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -14,15 +14,17 @@
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
require 'OpenNebula'
|
||||
|
||||
include OpenNebula
|
||||
require 'VirtualNetworkOCCI'
|
||||
|
||||
class VirtualNetworkPoolOCCI < VirtualNetworkPool
|
||||
OCCI_NETWORK_POOL = %q{
|
||||
<NETWORK_COLLECTION>
|
||||
<% self.each{ |vn| %>
|
||||
<% self.each{ |vn| %>
|
||||
<% if verbose %>
|
||||
<%= vn.to_occi(base_url) %>
|
||||
<% else %>
|
||||
<NETWORK href="<%= base_url %>/network/<%= vn.id.to_s %>" name="<%= vn.name %>"/>
|
||||
<% end %>
|
||||
<% } %>
|
||||
</NETWORK_COLLECTION>
|
||||
}
|
||||
@ -39,4 +41,8 @@ class VirtualNetworkPoolOCCI < VirtualNetworkPool
|
||||
|
||||
return occi_text.gsub(/\n\s*/,'')
|
||||
end
|
||||
|
||||
def factory(element_xml)
|
||||
VirtualNetworkOCCI.new(element_xml,@client)
|
||||
end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user