diff --git a/src/oca/ruby/OpenNebula.rb b/src/oca/ruby/OpenNebula.rb index c780c100ae..9dc67bb237 100644 --- a/src/oca/ruby/OpenNebula.rb +++ b/src/oca/ruby/OpenNebula.rb @@ -14,6 +14,7 @@ # limitations under the License. # #--------------------------------------------------------------------------- # + begin # require 'rubygems' require 'rubygems' rescue Exception @@ -44,12 +45,10 @@ require 'OpenNebula/AclPool' module OpenNebula - # ------------------------------------------------------------------------- # The Error Class represents a generic error in the OpenNebula # library. It contains a readable representation of the error. # Any function in the OpenNebula module will return an Error # object in case of error. - # ------------------------------------------------------------------------- class Error attr_reader :message @@ -63,18 +62,14 @@ module OpenNebula end end - # ------------------------------------------------------------------------- # Returns true if the object returned by a method of the OpenNebula # library is an Error - # ------------------------------------------------------------------------- def self.is_error?(value) value.class==OpenNebula::Error end - # ------------------------------------------------------------------------- # The client class, represents the connection with the core and handles the # xml-rpc calls. - # ------------------------------------------------------------------------- class Client attr_accessor :one_auth diff --git a/src/oca/ruby/OpenNebula/Acl.rb b/src/oca/ruby/OpenNebula/Acl.rb index b61bb24d22..146c05215f 100644 --- a/src/oca/ruby/OpenNebula/Acl.rb +++ b/src/oca/ruby/OpenNebula/Acl.rb @@ -14,7 +14,9 @@ # limitations under the License. # #--------------------------------------------------------------------------- # + module OpenNebula + # Abstract rules of the type USER RESOURCE RIGHTS # which are: # USER -> # diff --git a/src/oca/ruby/OpenNebula/AclPool.rb b/src/oca/ruby/OpenNebula/AclPool.rb index da81b45074..5ff4574ad9 100644 --- a/src/oca/ruby/OpenNebula/AclPool.rb +++ b/src/oca/ruby/OpenNebula/AclPool.rb @@ -14,6 +14,7 @@ # limitations under the License. # #--------------------------------------------------------------------------- # + require 'OpenNebula/Pool' module OpenNebula @@ -22,15 +23,15 @@ module OpenNebula ####################################################################### # Constants and Class Methods ####################################################################### + + ACL_POOL_METHODS = { :info => "acl.info", :addrule => "acl.addrule", :delrule => "acl.delrule" } - ####################################################################### # Class constructor - ####################################################################### def initialize(client) super('ACL_POOL','ACL',client) end diff --git a/src/oca/ruby/OpenNebula/Group.rb b/src/oca/ruby/OpenNebula/Group.rb index 98c359ed3a..ce50d68388 100644 --- a/src/oca/ruby/OpenNebula/Group.rb +++ b/src/oca/ruby/OpenNebula/Group.rb @@ -14,13 +14,16 @@ # limitations under the License. # #--------------------------------------------------------------------------- # + require 'OpenNebula/Pool' module OpenNebula class Group < PoolElement - # --------------------------------------------------------------------- + ####################################################################### # Constants and Class Methods - # --------------------------------------------------------------------- + ####################################################################### + + GROUP_METHODS = { :info => "group.info", :allocate => "group.allocate", @@ -54,18 +57,16 @@ module OpenNebula XMLElement.build_xml(group_xml,'GROUP') end - # --------------------------------------------------------------------- # Class constructor - # --------------------------------------------------------------------- def initialize(xml, client) super(xml,client) @client = client end - - # -------------------------------------------------------------------- + + ####################################################################### # Group utils - # -------------------------------------------------------------------- + ####################################################################### # Creates ACLs for the group. The ACL rules are described in a file def create_acls(filename = GROUP_DEFAULT) @@ -100,9 +101,9 @@ module OpenNebula return 0, msg end - # --------------------------------------------------------------------- + ####################################################################### # XML-RPC Methods for the Group Object - # --------------------------------------------------------------------- + ####################################################################### # Retrieves the information of the given Group. def info() @@ -128,7 +129,7 @@ module OpenNebula # Returns whether or not the user with id 'uid' is part of this group def contains(uid) # This doesn't work in ruby 1.8.5 -# return self["USERS/ID[.=#{uid}]"] != nil + # return self["USERS/ID[.=#{uid}]"] != nil id_array = retrieve_elements('USERS/ID') return id_array != nil && id_array.include?(uid.to_s) diff --git a/src/oca/ruby/OpenNebula/GroupPool.rb b/src/oca/ruby/OpenNebula/GroupPool.rb index 591889bd4f..316c51f005 100644 --- a/src/oca/ruby/OpenNebula/GroupPool.rb +++ b/src/oca/ruby/OpenNebula/GroupPool.rb @@ -14,21 +14,23 @@ # limitations under the License. # #--------------------------------------------------------------------------- # + require 'OpenNebula/Pool' module OpenNebula class GroupPool < Pool - # --------------------------------------------------------------------- + ####################################################################### # Constants and Class attribute accessors - # --------------------------------------------------------------------- + ####################################################################### + GROUP_POOL_METHODS = { :info => "grouppool.info" } - # --------------------------------------------------------------------- + ####################################################################### # Class constructor & Pool Methods - # --------------------------------------------------------------------- + ####################################################################### # +client+ a Client object that represents a XML-RPC connection def initialize(client) @@ -40,13 +42,13 @@ module OpenNebula OpenNebula::Group.new(element_xml,@client) end - # --------------------------------------------------------------------- + ####################################################################### # XML-RPC Methods for the User Object - # --------------------------------------------------------------------- + ####################################################################### # Retrieves all the Groups in the pool. def info() super(GROUP_POOL_METHODS[:info]) end end -end \ No newline at end of file +end diff --git a/src/oca/ruby/OpenNebula/Host.rb b/src/oca/ruby/OpenNebula/Host.rb index 1d6a0b9e30..24f205663c 100644 --- a/src/oca/ruby/OpenNebula/Host.rb +++ b/src/oca/ruby/OpenNebula/Host.rb @@ -14,6 +14,7 @@ # limitations under the License. # #--------------------------------------------------------------------------- # + require 'OpenNebula/Pool' module OpenNebula @@ -21,6 +22,8 @@ module OpenNebula ####################################################################### # Constants and Class Methods ####################################################################### + + HOST_METHODS = { :info => "host.info", :allocate => "host.allocate", @@ -56,9 +59,7 @@ module OpenNebula XMLElement.build_xml(host_xml, 'HOST') end - ####################################################################### # Class constructor - ####################################################################### def initialize(xml, client) super(xml,client) diff --git a/src/oca/ruby/OpenNebula/HostPool.rb b/src/oca/ruby/OpenNebula/HostPool.rb index 2e88140e96..30a9948219 100644 --- a/src/oca/ruby/OpenNebula/HostPool.rb +++ b/src/oca/ruby/OpenNebula/HostPool.rb @@ -14,6 +14,7 @@ # limitations under the License. # #--------------------------------------------------------------------------- # + require 'OpenNebula/Pool' module OpenNebula @@ -22,6 +23,7 @@ module OpenNebula # Constants and Class attribute accessors ####################################################################### + HOST_POOL_METHODS = { :info => "hostpool.info" } @@ -29,7 +31,8 @@ module OpenNebula ####################################################################### # Class constructor & Pool Methods ####################################################################### - + + # +client+ a Client object that represents a XML-RPC connection def initialize(client) super('HOST_POOL','HOST',client) diff --git a/src/oca/ruby/OpenNebula/Image.rb b/src/oca/ruby/OpenNebula/Image.rb index 0b49d943cc..668add9c0b 100644 --- a/src/oca/ruby/OpenNebula/Image.rb +++ b/src/oca/ruby/OpenNebula/Image.rb @@ -14,14 +14,17 @@ # limitations under the License. # #--------------------------------------------------------------------------- # + require 'OpenNebula/Pool' require 'fileutils' module OpenNebula class Image < PoolElement - # --------------------------------------------------------------------- + ####################################################################### # Constants and Class Methods - # --------------------------------------------------------------------- + ####################################################################### + + IMAGE_METHODS = { :info => "image.info", :allocate => "image.allocate", @@ -118,7 +121,7 @@ module OpenNebula def unpublish set_publish(false) end - + # Makes the Image persistent def persistent set_persistent(true) diff --git a/src/oca/ruby/OpenNebula/ImagePool.rb b/src/oca/ruby/OpenNebula/ImagePool.rb index 4cec6b3840..f58ffafc3b 100644 --- a/src/oca/ruby/OpenNebula/ImagePool.rb +++ b/src/oca/ruby/OpenNebula/ImagePool.rb @@ -14,6 +14,7 @@ # limitations under the License. # #--------------------------------------------------------------------------- # + require 'OpenNebula/Pool' module OpenNebula @@ -21,7 +22,8 @@ module OpenNebula ####################################################################### # Constants and Class attribute accessors ####################################################################### - + + IMAGE_POOL_METHODS = { :info => "imagepool.info" } @@ -29,7 +31,7 @@ module OpenNebula ####################################################################### # 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=-1) diff --git a/src/oca/ruby/OpenNebula/Pool.rb b/src/oca/ruby/OpenNebula/Pool.rb index 2608848e84..35a22bc807 100644 --- a/src/oca/ruby/OpenNebula/Pool.rb +++ b/src/oca/ruby/OpenNebula/Pool.rb @@ -14,10 +14,11 @@ # limitations under the License. # #--------------------------------------------------------------------------- # + module OpenNebula + # The Pool class represents a generic OpenNebula Pool in XML format # and provides the basic functionality to handle the Pool elements - class Pool < XMLPool include Enumerable diff --git a/src/oca/ruby/OpenNebula/Template.rb b/src/oca/ruby/OpenNebula/Template.rb index fa12eea96e..07beb53f89 100644 --- a/src/oca/ruby/OpenNebula/Template.rb +++ b/src/oca/ruby/OpenNebula/Template.rb @@ -14,13 +14,16 @@ # limitations under the License. # #--------------------------------------------------------------------------- # + require 'OpenNebula/Pool' module OpenNebula class Template < PoolElement - # --------------------------------------------------------------------- + ####################################################################### # Constants and Class Methods - # --------------------------------------------------------------------- + ####################################################################### + + TEMPLATE_METHODS = { :allocate => "template.allocate", :instantiate => "template.instantiate", @@ -48,18 +51,16 @@ module OpenNebula XMLElement.build_xml(obj_xml,'VMTEMPLATE') end - # --------------------------------------------------------------------- # Class constructor - # --------------------------------------------------------------------- def initialize(xml, client) super(xml,client) @client = client end - # --------------------------------------------------------------------- + ####################################################################### # XML-RPC Methods for the Template Object - # --------------------------------------------------------------------- + ####################################################################### # Retrieves the information of the given Template. def info() @@ -118,9 +119,9 @@ module OpenNebula super(TEMPLATE_METHODS[:chown], uid, gid) end - # --------------------------------------------------------------------- + ####################################################################### # Helpers to get Template information - # --------------------------------------------------------------------- + ####################################################################### # Returns the group identifier # [return] _Integer_ the element's group ID diff --git a/src/oca/ruby/OpenNebula/TemplatePool.rb b/src/oca/ruby/OpenNebula/TemplatePool.rb index c5174036bc..81013f957c 100644 --- a/src/oca/ruby/OpenNebula/TemplatePool.rb +++ b/src/oca/ruby/OpenNebula/TemplatePool.rb @@ -14,21 +14,23 @@ # limitations under the License. # #--------------------------------------------------------------------------- # + require 'OpenNebula/Pool' module OpenNebula class TemplatePool < Pool - # --------------------------------------------------------------------- + ####################################################################### # Constants and Class attribute accessors - # --------------------------------------------------------------------- + ####################################################################### + TEMPLATE_POOL_METHODS = { :info => "templatepool.info" } - # --------------------------------------------------------------------- + ####################################################################### # Class constructor & Pool Methods - # --------------------------------------------------------------------- + ####################################################################### # +client+ a Client object that represents an XML-RPC connection # +user_id+ used to refer to a Pool with Templates from that user @@ -43,9 +45,10 @@ module OpenNebula OpenNebula::Template.new(element_xml,@client) end - # --------------------------------------------------------------------- + ####################################################################### # XML-RPC Methods for the Template Object - # --------------------------------------------------------------------- + ####################################################################### + # Retrieves all or part of the VirtualMachines in the pool. def info(*args) case args.size diff --git a/src/oca/ruby/OpenNebula/User.rb b/src/oca/ruby/OpenNebula/User.rb index 03d7ed2195..7f2477c139 100644 --- a/src/oca/ruby/OpenNebula/User.rb +++ b/src/oca/ruby/OpenNebula/User.rb @@ -14,13 +14,16 @@ # limitations under the License. # #--------------------------------------------------------------------------- # + require 'OpenNebula/Pool' module OpenNebula class User < PoolElement - # --------------------------------------------------------------------- + ####################################################################### # Constants and Class Methods - # --------------------------------------------------------------------- + ####################################################################### + + USER_METHODS = { :info => "user.info", :allocate => "user.allocate", @@ -48,18 +51,16 @@ module OpenNebula XMLElement.build_xml(user_xml, 'USER') end - # --------------------------------------------------------------------- # Class constructor - # --------------------------------------------------------------------- def initialize(xml, client) super(xml,client) @client = client end - # --------------------------------------------------------------------- + ####################################################################### # XML-RPC Methods for the User Object - # --------------------------------------------------------------------- + ####################################################################### # Retrieves the information of the given User. def info() @@ -104,9 +105,9 @@ module OpenNebula return rc end - # --------------------------------------------------------------------- + ####################################################################### # Helpers to get User information - # --------------------------------------------------------------------- + ####################################################################### # Returns the group identifier # [return] _Integer_ the element's group ID diff --git a/src/oca/ruby/OpenNebula/UserPool.rb b/src/oca/ruby/OpenNebula/UserPool.rb index 9f9d035776..c93b675ca0 100644 --- a/src/oca/ruby/OpenNebula/UserPool.rb +++ b/src/oca/ruby/OpenNebula/UserPool.rb @@ -14,22 +14,23 @@ # limitations under the License. # #--------------------------------------------------------------------------- # + require 'OpenNebula/Pool' module OpenNebula class UserPool < Pool - # --------------------------------------------------------------------- + ####################################################################### # Constants and Class attribute accessors - # --------------------------------------------------------------------- + ####################################################################### USER_POOL_METHODS = { :info => "userpool.info" } - # --------------------------------------------------------------------- + ####################################################################### # Class constructor & Pool Methods - # --------------------------------------------------------------------- - + ####################################################################### + # +client+ a Client object that represents a XML-RPC connection def initialize(client) super('USER_POOL','USER',client) @@ -40,9 +41,9 @@ module OpenNebula OpenNebula::User.new(element_xml,@client) end - # --------------------------------------------------------------------- + ####################################################################### # XML-RPC Methods for the User Object - # --------------------------------------------------------------------- + ####################################################################### # Retrieves all the Users in the pool. def info() diff --git a/src/oca/ruby/OpenNebula/VirtualMachine.rb b/src/oca/ruby/OpenNebula/VirtualMachine.rb index 75e0aeaae5..7360be8ef0 100644 --- a/src/oca/ruby/OpenNebula/VirtualMachine.rb +++ b/src/oca/ruby/OpenNebula/VirtualMachine.rb @@ -14,6 +14,7 @@ # limitations under the License. # #--------------------------------------------------------------------------- # + require 'OpenNebula/Pool' module OpenNebula @@ -21,6 +22,8 @@ module OpenNebula ####################################################################### # Constants and Class Methods ####################################################################### + + VM_METHODS = { :info => "vm.info", :allocate => "vm.allocate", @@ -101,9 +104,7 @@ module OpenNebula reason_str end - ####################################################################### # Class constructor - ####################################################################### def initialize(xml, client) super(xml,client) diff --git a/src/oca/ruby/OpenNebula/VirtualMachinePool.rb b/src/oca/ruby/OpenNebula/VirtualMachinePool.rb index 43b9ecf4e1..d8e40a8403 100644 --- a/src/oca/ruby/OpenNebula/VirtualMachinePool.rb +++ b/src/oca/ruby/OpenNebula/VirtualMachinePool.rb @@ -14,6 +14,7 @@ # limitations under the License. # #--------------------------------------------------------------------------- # + require 'OpenNebula/Pool' module OpenNebula @@ -22,6 +23,7 @@ module OpenNebula # Constants and Class attribute accessors ####################################################################### + VM_POOL_METHODS = { :info => "vmpool.info" } @@ -33,7 +35,8 @@ module OpenNebula ####################################################################### # Class constructor & Pool Methods ####################################################################### - + + # +client+ a Client object that represents a XML-RPC connection # +user_id+ is to refer to a Pool with VirtualMachines from that user def initialize(client, user_id=0) @@ -50,7 +53,7 @@ module OpenNebula ####################################################################### # XML-RPC Methods for the Virtual Network Object ####################################################################### - + # Retrieves all or part of the VirtualMachines in the pool. # No arguments, returns the not-in-done VMs for the user # [user_id, start_id, end_id] @@ -107,9 +110,9 @@ module OpenNebula -1, INFO_NOT_DONE) end - + private - + def info_filter(xml_method, who, start_id, end_id, state) return xmlrpc_info(xml_method, who, start_id, end_id, state) end diff --git a/src/oca/ruby/OpenNebula/VirtualNetwork.rb b/src/oca/ruby/OpenNebula/VirtualNetwork.rb index 98a999ef1f..de1a06e746 100644 --- a/src/oca/ruby/OpenNebula/VirtualNetwork.rb +++ b/src/oca/ruby/OpenNebula/VirtualNetwork.rb @@ -14,13 +14,16 @@ # limitations under the License. # #--------------------------------------------------------------------------- # + require 'OpenNebula/Pool' module OpenNebula class VirtualNetwork < PoolElement - # --------------------------------------------------------------------- + ####################################################################### # Constants and Class Methods - # --------------------------------------------------------------------- + ####################################################################### + + VN_METHODS = { :info => "vn.info", :allocate => "vn.allocate", @@ -127,9 +130,9 @@ module OpenNebula super(VN_METHODS[:chown], uid, gid) end - # --------------------------------------------------------------------- + ####################################################################### # Helpers to get VirtualNetwork information - # --------------------------------------------------------------------- + ####################################################################### # Returns the group identifier # [return] _Integer_ the element's group ID diff --git a/src/oca/ruby/OpenNebula/VirtualNetworkPool.rb b/src/oca/ruby/OpenNebula/VirtualNetworkPool.rb index 4267ac1830..9b58ca5d4d 100644 --- a/src/oca/ruby/OpenNebula/VirtualNetworkPool.rb +++ b/src/oca/ruby/OpenNebula/VirtualNetworkPool.rb @@ -14,6 +14,7 @@ # limitations under the License. # #--------------------------------------------------------------------------- # + require 'OpenNebula/Pool' module OpenNebula @@ -21,7 +22,8 @@ module OpenNebula ####################################################################### # Constants and Class attribute accessors ####################################################################### - + + VN_POOL_METHODS = { :info => "vnpool.info" } diff --git a/src/oca/ruby/OpenNebula/XMLUtils.rb b/src/oca/ruby/OpenNebula/XMLUtils.rb index c71dece114..1dfa884532 100644 --- a/src/oca/ruby/OpenNebula/XMLUtils.rb +++ b/src/oca/ruby/OpenNebula/XMLUtils.rb @@ -14,6 +14,7 @@ # limitations under the License. # #--------------------------------------------------------------------------- # + module OpenNebula begin @@ -30,11 +31,9 @@ module OpenNebula REXML_FORMATTERS=false end - ########################################################################### # The XMLElement class provides an abstraction of the underlying # XML parser engine. It provides XML-related methods for the Pool and # PoolElement classes - ########################################################################### class XMLElement # xml:: _opaque xml object_ an xml object as returned by build_xml @@ -310,10 +309,8 @@ module OpenNebula end end - ########################################################################### # The XMLUtilsPool module provides an abstraction of the underlying # XML parser engine. It provides XML-related methods for the Pools - ########################################################################### class XMLPool < XMLElement def initialize(xml=nil)