From 04e4e0137dcdd6c2361b77a08bd691a9890f00ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tino=20V=C3=A1zquez?= Date: Mon, 14 Jun 2010 17:36:56 +0200 Subject: [PATCH] feature #200: Added OCA methods --- src/oca/ruby/OpenNebula/Image.rb | 59 ++++++++++++++++++++++++++++ src/oca/ruby/OpenNebula/ImagePool.rb | 38 ++++++++++++++++++ src/oca/ruby/OpenNebula/Pool.rb | 15 +++++++ 3 files changed, 112 insertions(+) create mode 100644 src/oca/ruby/OpenNebula/Image.rb create mode 100644 src/oca/ruby/OpenNebula/ImagePool.rb diff --git a/src/oca/ruby/OpenNebula/Image.rb b/src/oca/ruby/OpenNebula/Image.rb new file mode 100644 index 0000000000..f8cff1f7b6 --- /dev/null +++ b/src/oca/ruby/OpenNebula/Image.rb @@ -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 = "#{pe_id}" + IMAGE + image_xml = "" + 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 diff --git a/src/oca/ruby/OpenNebula/ImagePool.rb b/src/oca/ruby/OpenNebula/ImagePool.rb new file mode 100644 index 0000000000..91e86b9d15 --- /dev/null +++ b/src/oca/ruby/OpenNebula/ImagePool.rb @@ -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 diff --git a/src/oca/ruby/OpenNebula/Pool.rb b/src/oca/ruby/OpenNebula/Pool.rb index e28151045f..f2138abf2e 100644 --- a/src/oca/ruby/OpenNebula/Pool.rb +++ b/src/oca/ruby/OpenNebula/Pool.rb @@ -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