1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

feature #200: Added OCA methods

This commit is contained in:
Tino Vázquez 2010-06-14 17:36:56 +02:00
parent ac2ed32178
commit 04e4e0137d
3 changed files with 112 additions and 0 deletions

View File

@ -0,0 +1,59 @@
require 'OpenNebula/Pool'
module OpenNebula
class Image < PoolElement
# ---------------------------------------------------------------------
# Constants and Class Methods
# ---------------------------------------------------------------------
IMAGE_METHODS = {
:info => "image.info",
:allocate => "image.allocate",
:update => "image.update",
:delete => "image.delete"
}
# Creates an Image description with just its identifier
# this method should be used to create plain Image objects.
# +id+ the id of the image
#
# Example:
# image = Image.new(Image.build_xml(3),rpc_client)
#
def Image.build_xml(pe_id=nil)
if pe_id
image_xml = "<IMAGE><ID>#{pe_id}</ID></IMAGE>"
IMAGE
image_xml = "<IMAGE></IMAGE>"
end
XMLUtilsElement.initialize_xml(image_xml, 'IMAGE')
end
# Class constructor
def initialize(xml, client)
super(xml,client)
@client = client
end
#######################################################################
# XML-RPC Methods for the Image Object
#######################################################################
def info()
super(IMAGE_METHODS[:info], 'IMAGE')
end
def allocate(description)
super(IMAGE_METHODS[:allocate],description)
end
def update(name, value)
super(IMAGE_METHODS[:update], name, value)
end
def delete()
super(IMAGE_METHODS[:delete])
end
end
end

View File

@ -0,0 +1,38 @@
require 'OpenNebula/Pool'
module OpenNebula
class ImagePool < Pool
#######################################################################
# Constants and Class attribute accessors
#######################################################################
IMAGE_POOL_METHODS = {
:info => "imagepool.info"
}
#######################################################################
# Class constructor & Pool Methods
#######################################################################
# +client+ a Client object that represents a XML-RPC connection
# +user_id+ is to refer to a Pool with Images from that user
def initialize(client, user_id=0)
super('IMAGE_POOL','IMAGE',client)
@user_id = user_id
end
# Default Factory Method for the Pools
def factory(element_xml)
OpenNebula::Image.new(element_xml,@client)
end
#######################################################################
# XML-RPC Methods for the Image Object
#######################################################################
def info()
super(IMAGE_POOL_METHODS[:info],@user_id)
end
end
end

View File

@ -129,6 +129,21 @@ module OpenNebula
return rc
end
# Calls to the corresponding update method to modify
# the object's template
# xml_method:: _String_ the name of the XML-RPC method
# name:: _String_ the name of the property to be modified
# value:: _String_ the new value of the property to be modified
# [return] nil in case of success or an Error object
def update(xml_method, name, value)
return Error.new('ID not defined') if !@pe_id
rc = @client.call(xml_method,@pe_id, name, value)
rc = nil if !OpenNebula.is_error?(rc)
return rc
end
# Calls to the corresponding delete method to remove this element
# from the OpenNebula core