From c562e7206f0599ecc4891916bb646c348c22c5d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Fri, 7 Dec 2012 18:32:38 +0100 Subject: [PATCH 001/324] Feature #1686: Implement one.*.rename methods in core --- include/PoolObjectSQL.h | 5 + include/RequestManagerRename.h | 180 ++++++++++++++++++++++++++++ src/oca/ruby/OpenNebula/Template.rb | 13 +- src/rm/RequestManager.cc | 13 ++ src/rm/RequestManagerRename.cc | 111 +++++++++++++++++ src/rm/SConstruct | 3 +- 6 files changed, 323 insertions(+), 2 deletions(-) create mode 100644 include/RequestManagerRename.h create mode 100644 src/rm/RequestManagerRename.cc diff --git a/include/PoolObjectSQL.h b/include/PoolObjectSQL.h index 220e66b51a..31428d4577 100644 --- a/include/PoolObjectSQL.h +++ b/include/PoolObjectSQL.h @@ -140,6 +140,11 @@ public: return name; }; + void set_name(const string& _name) + { + name = _name; + }; + int get_uid() const { return uid; diff --git a/include/RequestManagerRename.h b/include/RequestManagerRename.h new file mode 100644 index 0000000000..f459c8b91f --- /dev/null +++ b/include/RequestManagerRename.h @@ -0,0 +1,180 @@ +/* -------------------------------------------------------------------------- */ +/* Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) */ +/* */ +/* Licensed under the Apache License, Version 2.0 (the "License"); you may */ +/* not use this file except in compliance with the License. You may obtain */ +/* a copy of the License at */ +/* */ +/* http://www.apache.org/licenses/LICENSE-2.0 */ +/* */ +/* Unless required by applicable law or agreed to in writing, software */ +/* distributed under the License is distributed on an "AS IS" BASIS, */ +/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ +/* See the License for the specific language governing permissions and */ +/* limitations under the License. */ +/* -------------------------------------------------------------------------- */ + +#ifndef REQUEST_MANAGER_RENAME_H_ +#define REQUEST_MANAGER_RENAME_H_ + +#include "Request.h" +#include "Nebula.h" + +using namespace std; + +/* ------------------------------------------------------------------------- */ +/* ------------------------------------------------------------------------- */ +/* ------------------------------------------------------------------------- */ + +class RequestManagerRename : public Request +{ +protected: + RequestManagerRename(const string& method_name, + const string& help, + const string& params = "A:sis") + :Request(method_name,params,help) + { + auth_op = AuthRequest::MANAGE; + }; + + ~RequestManagerRename(){}; + + /* -------------------------------------------------------------------- */ + + void request_execute(xmlrpc_c::paramList const& _paramList, + RequestAttributes& att); + + PoolObjectSQL * get_and_quota(int oid, + int new_uid, + int new_gid, + RequestAttributes& att); + + virtual PoolObjectSQL * get(const string& name, int uid, bool lock) = 0; +}; + +/* ------------------------------------------------------------------------- */ +/* ------------------------------------------------------------------------- */ + +class VirtualMachineRename : public RequestManagerRename +{ +public: + VirtualMachineRename(): + RequestManagerRename("VirtualMachineRename", + "Renames a virtual machine") + { + Nebula& nd = Nebula::instance(); + pool = nd.get_vmpool(); + auth_object = PoolObjectSQL::VM; + }; + + ~VirtualMachineRename(){}; + + int check_name_unique(int oid, int noid, RequestAttributes& att) + { + return 0; + }; + + PoolObjectSQL * get(const string& name, int uid, bool lock) + { + return 0; + }; +}; + +/* ------------------------------------------------------------------------- */ +/* ------------------------------------------------------------------------- */ + +class TemplateRename : public RequestManagerRename +{ +public: + TemplateRename(): + RequestManagerRename("TemplateRename", + "Renames a virtual machine template") + { + Nebula& nd = Nebula::instance(); + pool = nd.get_tpool(); + auth_object = PoolObjectSQL::TEMPLATE; + }; + + ~TemplateRename(){}; + + PoolObjectSQL * get(const string& name, int uid, bool lock) + { + return static_cast(pool)->get(name, uid, lock); + }; +}; + +/* ------------------------------------------------------------------------- */ +/* ------------------------------------------------------------------------- */ + + +class VirtualNetworkRename: public RequestManagerRename +{ +public: + VirtualNetworkRename(): + RequestManagerRename("VirtualNetworkRename", + "Renames a virtual network") + { + Nebula& nd = Nebula::instance(); + pool = nd.get_vnpool(); + auth_object = PoolObjectSQL::NET; + }; + + ~VirtualNetworkRename(){}; + + PoolObjectSQL * get(const string& name, int uid, bool lock) + { + return static_cast(pool)->get(name, uid, lock); + }; +}; + +/* ------------------------------------------------------------------------- */ +/* ------------------------------------------------------------------------- */ + +class ImageRename: public RequestManagerRename +{ +public: + ImageRename(): + RequestManagerRename("ImageRename", + "Renames an image") + { + Nebula& nd = Nebula::instance(); + pool = nd.get_ipool(); + auth_object = PoolObjectSQL::IMAGE; + }; + + ~ImageRename(){}; + + PoolObjectSQL * get(const string& name, int uid, bool lock) + { + return static_cast(pool)->get(name, uid, lock); + }; +}; + +/* ------------------------------------------------------------------------- */ +/* ------------------------------------------------------------------------- */ + +class DocumentRename : public RequestManagerRename +{ +public: + DocumentRename(): + RequestManagerRename("DocumentRename", + "Renames a generic document") + { + Nebula& nd = Nebula::instance(); + pool = nd.get_docpool(); + auth_object = PoolObjectSQL::DOCUMENT; + }; + + ~DocumentRename(){}; + + PoolObjectSQL * get(const string& name, int uid, bool lock) + { + return 0; + }; +}; + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +#endif diff --git a/src/oca/ruby/OpenNebula/Template.rb b/src/oca/ruby/OpenNebula/Template.rb index aa209d3f3d..c8a8cb886d 100644 --- a/src/oca/ruby/OpenNebula/Template.rb +++ b/src/oca/ruby/OpenNebula/Template.rb @@ -32,7 +32,8 @@ module OpenNebula :delete => "template.delete", :chown => "template.chown", :chmod => "template.chmod", - :clone => "template.clone" + :clone => "template.clone", + :rename => "template.rename" } # Creates a Template description with just its identifier @@ -157,6 +158,16 @@ module OpenNebula return rc end + # Renames this Template + # + # @param name [String] New name for the new Template. + # + # @return [nil, OpenNebula::Error] nil in case of success, Error + # otherwise + def rename(name) + return call(TEMPLATE_METHODS[:rename], @pe_id, name) + end + ####################################################################### # Helpers to get Template information ####################################################################### diff --git a/src/rm/RequestManager.cc b/src/rm/RequestManager.cc index 1ba7f4b8bf..004c3e2d82 100644 --- a/src/rm/RequestManager.cc +++ b/src/rm/RequestManager.cc @@ -26,6 +26,7 @@ #include "RequestManagerChown.h" #include "RequestManagerChmod.h" #include "RequestManagerClone.h" +#include "RequestManagerRename.h" #include "RequestManagerVirtualNetwork.h" #include "RequestManagerVirtualMachine.h" @@ -374,6 +375,13 @@ void RequestManager::register_xml_methods() xmlrpc_c::methodPtr group_get_default_quota(new GroupQuotaInfo()); xmlrpc_c::methodPtr group_set_default_quota(new GroupQuotaUpdate()); + // Rename Methods + xmlrpc_c::methodPtr vm_rename(new VirtualMachineRename()); + xmlrpc_c::methodPtr template_rename(new TemplateRename()); + xmlrpc_c::methodPtr vn_rename(new VirtualNetworkRename()); + xmlrpc_c::methodPtr image_rename(new ImageRename()); + xmlrpc_c::methodPtr doc_rename(new DocumentRename()); + /* VM related methods */ RequestManagerRegistry.addMethod("one.vm.deploy", vm_deploy); RequestManagerRegistry.addMethod("one.vm.action", vm_action); @@ -386,6 +394,7 @@ void RequestManager::register_xml_methods() RequestManagerRegistry.addMethod("one.vm.monitoring", vm_monitoring); RequestManagerRegistry.addMethod("one.vm.attach", vm_attach); RequestManagerRegistry.addMethod("one.vm.detach", vm_detach); + RequestManagerRegistry.addMethod("one.vm.rename", vm_rename); RequestManagerRegistry.addMethod("one.vmpool.info", vm_pool_info); RequestManagerRegistry.addMethod("one.vmpool.accounting", vm_pool_acct); @@ -400,6 +409,7 @@ void RequestManager::register_xml_methods() RequestManagerRegistry.addMethod("one.template.chown", template_chown); RequestManagerRegistry.addMethod("one.template.chmod", template_chmod); RequestManagerRegistry.addMethod("one.template.clone", template_clone); + RequestManagerRegistry.addMethod("one.template.rename", template_rename); RequestManagerRegistry.addMethod("one.templatepool.info",template_pool_info); @@ -436,6 +446,7 @@ void RequestManager::register_xml_methods() RequestManagerRegistry.addMethod("one.vn.info", vn_info); RequestManagerRegistry.addMethod("one.vn.chown", vn_chown); RequestManagerRegistry.addMethod("one.vn.chmod", vn_chmod); + RequestManagerRegistry.addMethod("one.vn.rename", vn_rename); RequestManagerRegistry.addMethod("one.vnpool.info", vnpool_info); @@ -465,6 +476,7 @@ void RequestManager::register_xml_methods() RequestManagerRegistry.addMethod("one.image.chmod", image_chmod); RequestManagerRegistry.addMethod("one.image.chtype", image_chtype); RequestManagerRegistry.addMethod("one.image.clone", image_clone); + RequestManagerRegistry.addMethod("one.image.rename", image_rename); RequestManagerRegistry.addMethod("one.imagepool.info", imagepool_info); @@ -506,6 +518,7 @@ void RequestManager::register_xml_methods() RequestManagerRegistry.addMethod("one.document.chown", doc_chown); RequestManagerRegistry.addMethod("one.document.chmod", doc_chmod); RequestManagerRegistry.addMethod("one.document.clone", doc_clone); + RequestManagerRegistry.addMethod("one.document.rename", doc_rename); RequestManagerRegistry.addMethod("one.documentpool.info",docpool_info); diff --git a/src/rm/RequestManagerRename.cc b/src/rm/RequestManagerRename.cc new file mode 100644 index 0000000000..e681f96fe3 --- /dev/null +++ b/src/rm/RequestManagerRename.cc @@ -0,0 +1,111 @@ +/* -------------------------------------------------------------------------- */ +/* Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) */ +/* */ +/* Licensed under the Apache License, Version 2.0 (the "License"); you may */ +/* not use this file except in compliance with the License. You may obtain */ +/* a copy of the License at */ +/* */ +/* http://www.apache.org/licenses/LICENSE-2.0 */ +/* */ +/* Unless required by applicable law or agreed to in writing, software */ +/* distributed under the License is distributed on an "AS IS" BASIS, */ +/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ +/* See the License for the specific language governing permissions and */ +/* limitations under the License. */ +/* -------------------------------------------------------------------------- */ + +#include "RequestManagerRename.h" +#include "PoolObjectSQL.h" + +#include "NebulaLog.h" +#include "Nebula.h" + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +void RequestManagerRename::request_execute(xmlrpc_c::paramList const& paramList, + RequestAttributes& att) +{ + int oid = xmlrpc_c::value_int(paramList.getInt(1)); + string new_name = xmlrpc_c::value_string(paramList.getString(2)); + + int rc; + + string old_name; + + PoolObjectAuth operms; + + PoolObjectSQL * object; + + string obj_name; + + rc = get_info(pool, oid, auth_object, att, operms, old_name); + + if ( rc == -1 ) + { + return; + } + + // ------------- Set authorization request for non-oneadmin's -------------- + + if ( att.uid != 0 ) + { + AuthRequest ar(att.uid, att.gid); + + ar.add_auth(auth_op, operms); // MANAGE OBJECT + + if (UserPool::authorize(ar) == -1) + { + failure_response(AUTHORIZATION, + authorization_error(ar.message, att), + att); + + return; + } + } + + // --------------- Check name uniqueness ----------------------------------- + + object = get(new_name, operms.uid, true); + + if ( object != 0 ) + { + ostringstream oss; + + int duplicate_obj_oid = object->get_oid(); + object->unlock(); + + oss << PoolObjectSQL::type_to_str(auth_object) << " [" + << oid << "] cannot be renamed to " << new_name + << " because it collides with " + << PoolObjectSQL::type_to_str(auth_object) << " [" + << duplicate_obj_oid << "]"; + + failure_response(INTERNAL, request_error(oss.str(), ""), att); + return; + } + + // --------------- Update the object --------------------------------------- + + object = pool->get(oid,true); + + if ( object == 0 ) + { + failure_response(NO_EXISTS, + get_error(object_name(auth_object), oid), + att); + } + + object->set_name(new_name); + + pool->update(object); + + object->unlock(); + + pool->update_cache_index(old_name, operms.uid, new_name, operms.uid); + + success_response(oid, att); + + return; +} + diff --git a/src/rm/SConstruct b/src/rm/SConstruct index 4420593001..a4e9bea234 100644 --- a/src/rm/SConstruct +++ b/src/rm/SConstruct @@ -41,7 +41,8 @@ source_files=[ 'RequestManagerChmod.cc', 'RequestManagerCluster.cc', 'RequestManagerClone.cc', - 'RequestManagerSystem.cc' + 'RequestManagerSystem.cc', + 'RequestManagerRename.cc' ] # Build library From 9061812849a4915f2722be979b4138cc1ab3f641 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Mon, 10 Dec 2012 11:42:05 +0100 Subject: [PATCH 002/324] Feature #1686: Do not return failure when the same name is set --- src/rm/RequestManagerRename.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/rm/RequestManagerRename.cc b/src/rm/RequestManagerRename.cc index e681f96fe3..3fd976b9cf 100644 --- a/src/rm/RequestManagerRename.cc +++ b/src/rm/RequestManagerRename.cc @@ -75,6 +75,15 @@ void RequestManagerRename::request_execute(xmlrpc_c::paramList const& paramList, int duplicate_obj_oid = object->get_oid(); object->unlock(); + if ( duplicate_obj_oid == oid ) + { + // Setting the same name for the object, do nothing but consider + // it a success + success_response(oid, att); + return; + } + + oss << PoolObjectSQL::type_to_str(auth_object) << " [" << oid << "] cannot be renamed to " << new_name << " because it collides with " From e1b033f8cc3385c455d018fa62fca67dc4b127ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Mon, 10 Dec 2012 11:46:32 +0100 Subject: [PATCH 003/324] Feature #1686: Add rename methods to ruby OCA and CLI --- src/cli/oneimage | 10 ++++++++++ src/cli/onetemplate | 10 ++++++++++ src/cli/onevm | 10 ++++++++++ src/cli/onevnet | 10 ++++++++++ src/oca/ruby/OpenNebula/Document.rb | 11 +++++++++++ src/oca/ruby/OpenNebula/Image.rb | 13 ++++++++++++- src/oca/ruby/OpenNebula/Template.rb | 2 +- src/oca/ruby/OpenNebula/VirtualMachine.rb | 13 ++++++++++++- src/oca/ruby/OpenNebula/VirtualNetwork.rb | 13 ++++++++++++- 9 files changed, 88 insertions(+), 4 deletions(-) diff --git a/src/cli/oneimage b/src/cli/oneimage index e57b1dd413..4a78d3b33e 100755 --- a/src/cli/oneimage +++ b/src/cli/oneimage @@ -304,6 +304,16 @@ cmd=CommandParser::CmdParser.new(ARGV) do end end + rename_desc = <<-EOT.unindent + Renames the Image + EOT + + command :rename, rename_desc, :imageid, :name do + helper.perform_action(args[0],options,"renamed") do |o| + o.rename(args[1]) + end + end + list_desc = <<-EOT.unindent Lists Images in the pool EOT diff --git a/src/cli/onetemplate b/src/cli/onetemplate index 396add5082..b82bc5c3de 100755 --- a/src/cli/onetemplate +++ b/src/cli/onetemplate @@ -265,6 +265,16 @@ cmd=CommandParser::CmdParser.new(ARGV) do Lists Templates in the pool EOT + rename_desc = <<-EOT.unindent + Renames the Template + EOT + + command :rename, rename_desc, :templateid, :name do + helper.perform_action(args[0],options,"renamed") do |o| + o.rename(args[1]) + end + end + command :list, list_desc, [:filterflag, nil], :options=>list_options do helper.list_pool(options, false, args[0]) end diff --git a/src/cli/onevm b/src/cli/onevm index 0e1f3c15de..7949e0fcab 100755 --- a/src/cli/onevm +++ b/src/cli/onevm @@ -515,6 +515,16 @@ cmd=CommandParser::CmdParser.new(ARGV) do Lists VMs in the pool EOT + rename_desc = <<-EOT.unindent + Renames the VM + EOT + + command :rename, rename_desc, :vmid, :name do + helper.perform_action(args[0],options,"renamed") do |o| + o.rename(args[1]) + end + end + command :list, list_desc, [:filterflag, nil], :options=>CLIHelper::OPTIONS+OpenNebulaHelper::OPTIONS+ [OpenNebulaHelper::DESCRIBE] do diff --git a/src/cli/onevnet b/src/cli/onevnet index 12638fc2a8..d931f3ce0b 100755 --- a/src/cli/onevnet +++ b/src/cli/onevnet @@ -228,4 +228,14 @@ cmd=CommandParser::CmdParser.new(ARGV) do vnet.update(str) end end + + rename_desc = <<-EOT.unindent + Renames the Virtual Network + EOT + + command :rename, rename_desc, :vnetid, :name do + helper.perform_action(args[0],options,"renamed") do |o| + o.rename(args[1]) + end + end end diff --git a/src/oca/ruby/OpenNebula/Document.rb b/src/oca/ruby/OpenNebula/Document.rb index 494ebcf3dd..bcb186c8e5 100644 --- a/src/oca/ruby/OpenNebula/Document.rb +++ b/src/oca/ruby/OpenNebula/Document.rb @@ -44,6 +44,7 @@ module OpenNebula :chown => "document.chown", :chmod => "document.chmod", :clone => "document.clone", + :rename => "document.rename" } # Creates a Document Object description with just its identifier @@ -185,6 +186,16 @@ module OpenNebula return rc end + # Renames this Document + # + # @param name [String] New name for the Document. + # + # @return [nil, OpenNebula::Error] nil in case of success, Error + # otherwise + def rename(name) + return call(DOCUMENT_METHODS[:rename], @pe_id, name) + end + ####################################################################### # Helpers to get Document information ####################################################################### diff --git a/src/oca/ruby/OpenNebula/Image.rb b/src/oca/ruby/OpenNebula/Image.rb index e8224871f8..53a2f8aea7 100644 --- a/src/oca/ruby/OpenNebula/Image.rb +++ b/src/oca/ruby/OpenNebula/Image.rb @@ -35,7 +35,8 @@ module OpenNebula :chown => "image.chown", :chmod => "image.chmod", :chtype => "image.chtype", - :clone => "image.clone" + :clone => "image.clone", + :rename => "image.rename" } IMAGE_STATES=%w{INIT READY USED DISABLED LOCKED ERROR CLONE DELETE USED_PERS} @@ -205,6 +206,16 @@ module OpenNebula return rc end + # Renames this Image + # + # @param name [String] New name for the Image. + # + # @return [nil, OpenNebula::Error] nil in case of success, Error + # otherwise + def rename(name) + return call(IMAGE_METHODS[:rename], @pe_id, name) + end + ####################################################################### # Helpers to get Image information ####################################################################### diff --git a/src/oca/ruby/OpenNebula/Template.rb b/src/oca/ruby/OpenNebula/Template.rb index c8a8cb886d..73a6d48aac 100644 --- a/src/oca/ruby/OpenNebula/Template.rb +++ b/src/oca/ruby/OpenNebula/Template.rb @@ -160,7 +160,7 @@ module OpenNebula # Renames this Template # - # @param name [String] New name for the new Template. + # @param name [String] New name for the Template. # # @return [nil, OpenNebula::Error] nil in case of success, Error # otherwise diff --git a/src/oca/ruby/OpenNebula/VirtualMachine.rb b/src/oca/ruby/OpenNebula/VirtualMachine.rb index 5e7c061c8b..08e1bafff3 100644 --- a/src/oca/ruby/OpenNebula/VirtualMachine.rb +++ b/src/oca/ruby/OpenNebula/VirtualMachine.rb @@ -35,7 +35,8 @@ module OpenNebula :chmod => "vm.chmod", :monitoring => "vm.monitoring", :attach => "vm.attach", - :detach => "vm.detach" + :detach => "vm.detach", + :rename => "vm.rename" } VM_STATE=%w{INIT PENDING HOLD ACTIVE STOPPED SUSPENDED DONE FAILED @@ -352,6 +353,16 @@ module OpenNebula return @client.call(VM_METHODS[:monitoring], @pe_id) end + # Renames this VM + # + # @param name [String] New name for the VM. + # + # @return [nil, OpenNebula::Error] nil in case of success, Error + # otherwise + def rename(name) + return call(VM_METHODS[:rename], @pe_id, name) + end + ####################################################################### # Helpers to get VirtualMachine information ####################################################################### diff --git a/src/oca/ruby/OpenNebula/VirtualNetwork.rb b/src/oca/ruby/OpenNebula/VirtualNetwork.rb index bb5c0933b3..b6964b4d0e 100644 --- a/src/oca/ruby/OpenNebula/VirtualNetwork.rb +++ b/src/oca/ruby/OpenNebula/VirtualNetwork.rb @@ -34,7 +34,8 @@ module OpenNebula :chmod => "vn.chmod", :update => "vn.update", :hold => "vn.hold", - :release => "vn.release" + :release => "vn.release", + :rename => "vn.rename" } VN_TYPES=%w{RANGED FIXED} @@ -191,6 +192,16 @@ module OpenNebula super(VN_METHODS[:chmod], owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u, other_m, other_a) end + + # Renames this virtual network + # + # @param name [String] New name for the virtual network. + # + # @return [nil, OpenNebula::Error] nil in case of success, Error + # otherwise + def rename(name) + return call(VN_METHODS[:rename], @pe_id, name) + end ####################################################################### # Helpers to get VirtualNetwork information From 2335460901d9943c1e379cb04b4dc4d5ae03e569 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Mon, 10 Dec 2012 12:24:09 +0100 Subject: [PATCH 004/324] Feature #1686: Add rename methods to java OCA --- .../opennebula/client/document/Document.java | 12 +++++++++ .../org/opennebula/client/image/Image.java | 25 +++++++++++++++++ .../opennebula/client/template/Template.java | 25 +++++++++++++++++ .../opennebula/client/vm/VirtualMachine.java | 25 +++++++++++++++++ .../client/vnet/VirtualNetwork.java | 27 ++++++++++++++++++- 5 files changed, 113 insertions(+), 1 deletion(-) diff --git a/src/oca/java/src/org/opennebula/client/document/Document.java b/src/oca/java/src/org/opennebula/client/document/Document.java index 281e9617b6..7f287a73f1 100644 --- a/src/oca/java/src/org/opennebula/client/document/Document.java +++ b/src/oca/java/src/org/opennebula/client/document/Document.java @@ -65,6 +65,7 @@ public abstract class Document extends PoolElement private static final String CHOWN = METHOD_PREFIX + "chown"; private static final String CHMOD = METHOD_PREFIX + "chmod"; private static final String CLONE = METHOD_PREFIX + "clone"; + private static final String RENAME = METHOD_PREFIX + "rename"; /** * Creates a new Document representation. @@ -215,6 +216,17 @@ public abstract class Document extends PoolElement return client.call(CLONE, id, name); } + /** + * Renames this document + * + * @param name New name for the document. + * @return If an error occurs the error message contains the reason. + */ + public OneResponse rename(String name) + { + return client.call(RENAME, id, name); + } + // ================================= // Helpers // ================================= diff --git a/src/oca/java/src/org/opennebula/client/image/Image.java b/src/oca/java/src/org/opennebula/client/image/Image.java index 62d8185790..700371bd2a 100644 --- a/src/oca/java/src/org/opennebula/client/image/Image.java +++ b/src/oca/java/src/org/opennebula/client/image/Image.java @@ -38,6 +38,7 @@ public class Image extends PoolElement private static final String CHMOD = METHOD_PREFIX + "chmod"; private static final String CHTYPE = METHOD_PREFIX + "chtype"; private static final String CLONE = METHOD_PREFIX + "clone"; + private static final String RENAME = METHOD_PREFIX + "rename"; private static final String[] IMAGE_STATES = {"INIT", "READY", "USED", "DISABLED", "LOCKED", @@ -265,6 +266,19 @@ public class Image extends PoolElement return client.call(CLONE, id, name); } + /** + * Renames this Image + * + * @param client XML-RPC Client. + * @param id The Image id of the target Image. + * @param name New name for the Image. + * @return If an error occurs the error message contains the reason. + */ + public static OneResponse rename(Client client, int id, String name) + { + return client.call(RENAME, id, name); + } + // ================================= // Instanced object XML-RPC methods // ================================= @@ -498,6 +512,17 @@ public class Image extends PoolElement return clone(client, id, name); } + /** + * Renames this Image + * + * @param name New name for the Image. + * @return If an error occurs the error message contains the reason. + */ + public OneResponse rename(String name) + { + return rename(client, id, name); + } + // ================================= // Helpers // ================================= diff --git a/src/oca/java/src/org/opennebula/client/template/Template.java b/src/oca/java/src/org/opennebula/client/template/Template.java index dd48c96254..a3a39c8755 100644 --- a/src/oca/java/src/org/opennebula/client/template/Template.java +++ b/src/oca/java/src/org/opennebula/client/template/Template.java @@ -36,6 +36,7 @@ public class Template extends PoolElement private static final String CHMOD = METHOD_PREFIX + "chmod"; private static final String INSTANTIATE = METHOD_PREFIX + "instantiate"; private static final String CLONE = METHOD_PREFIX + "clone"; + private static final String RENAME = METHOD_PREFIX + "rename"; /** * Creates a new Template representation. @@ -219,6 +220,19 @@ public class Template extends PoolElement return client.call(CLONE, id, name); } + /** + * Renames this Template + * + * @param client XML-RPC Client. + * @param id The Template id of the target Template. + * @param name New name for the Template. + * @return If an error occurs the error message contains the reason. + */ + public static OneResponse rename(Client client, int id, String name) + { + return client.call(RENAME, id, name); + } + // ================================= // Instanced object XML-RPC methods // ================================= @@ -400,6 +414,17 @@ public class Template extends PoolElement return clone(client, id, name); } + /** + * Renames this Template + * + * @param name New name for the Template. + * @return If an error occurs the error message contains the reason. + */ + public OneResponse rename(String name) + { + return rename(client, id, name); + } + // ================================= // Helpers // ================================= diff --git a/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java b/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java index d402c835d2..0b7d837f87 100644 --- a/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java +++ b/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java @@ -39,6 +39,7 @@ public class VirtualMachine extends PoolElement{ private static final String MONITORING = METHOD_PREFIX + "monitoring"; private static final String ATTACH = METHOD_PREFIX + "attach"; private static final String DETACH = METHOD_PREFIX + "detach"; + private static final String RENAME = METHOD_PREFIX + "rename"; private static final String[] VM_STATES = { @@ -273,6 +274,19 @@ public class VirtualMachine extends PoolElement{ return client.call(DETACH, id, diskId); } + /** + * Renames this VM + * + * @param client XML-RPC Client. + * @param id The VM id of the target VM. + * @param name New name for the VM. + * @return If an error occurs the error message contains the reason. + */ + public static OneResponse rename(Client client, int id, String name) + { + return client.call(RENAME, id, name); + } + // ================================= // Instanced object XML-RPC methods // ================================= @@ -486,6 +500,17 @@ public class VirtualMachine extends PoolElement{ return detachdisk(client, id, diskId); } + /** + * Renames this VM + * + * @param name New name for the VM. + * @return If an error occurs the error message contains the reason. + */ + public OneResponse rename(String name) + { + return rename(client, id, name); + } + // ================================= // Helpers // ================================= diff --git a/src/oca/java/src/org/opennebula/client/vnet/VirtualNetwork.java b/src/oca/java/src/org/opennebula/client/vnet/VirtualNetwork.java index 112d4adec5..fd65e5584c 100644 --- a/src/oca/java/src/org/opennebula/client/vnet/VirtualNetwork.java +++ b/src/oca/java/src/org/opennebula/client/vnet/VirtualNetwork.java @@ -38,6 +38,7 @@ public class VirtualNetwork extends PoolElement{ private static final String UPDATE = METHOD_PREFIX + "update"; private static final String HOLD = METHOD_PREFIX + "hold"; private static final String RELEASE = METHOD_PREFIX + "release"; + private static final String RENAME = METHOD_PREFIX + "rename"; /** * Creates a new virtual network representation. @@ -263,7 +264,7 @@ public class VirtualNetwork extends PoolElement{ * Replaces the VirtualNetwork template contents. * * @param client XML-RPC Client. - * @param id The user id of the target vnet we want to modify. + * @param id The vnet id of the target vnet we want to modify. * @param new_template New template contents. * @return If successful the message contains the vnet id. */ @@ -272,6 +273,19 @@ public class VirtualNetwork extends PoolElement{ return client.call(UPDATE, id, new_template); } + /** + * Renames this VirtualNetwork + * + * @param client XML-RPC Client. + * @param id The VirtualNetwork id of the target VirtualNetwork. + * @param name New name for the VirtualNetwork. + * @return If an error occurs the error message contains the reason. + */ + public static OneResponse rename(Client client, int id, String name) + { + return client.call(RENAME, id, name); + } + // ================================= // Instanced object XML-RPC methods // ================================= @@ -491,6 +505,17 @@ public class VirtualNetwork extends PoolElement{ return update(client, id, new_template); } + /** + * Renames this VirtualNetwork + * + * @param name New name for the VirtualNetwork. + * @return If an error occurs the error message contains the reason. + */ + public OneResponse rename(String name) + { + return rename(client, id, name); + } + // ================================= // Helpers // ================================= From 84120fc36897389bb2f864413c1d4253d8689f53 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Fri, 16 Nov 2012 17:49:45 +0100 Subject: [PATCH 005/324] Feature #1592: Apply SZTAKI LPDS patch as is. --- src/datastore_mad/remotes/iscsi/clone | 8 ++----- src/datastore_mad/remotes/iscsi/cp | 10 ++------ src/datastore_mad/remotes/iscsi/mkfs | 7 +----- src/mad/sh/scripts_common.sh | 19 ++++++++++----- src/tm_mad/iscsi/clone | 34 ++++++++++++++++++++------- src/tm_mad/iscsi/ln | 28 ++++++++++++++++++---- src/tm_mad/iscsi/mv | 28 ++++++++++++++++++---- src/tm_mad/iscsi/mvds | 2 +- 8 files changed, 92 insertions(+), 44 deletions(-) diff --git a/src/datastore_mad/remotes/iscsi/clone b/src/datastore_mad/remotes/iscsi/clone index f60dd02fa8..926c9c8074 100755 --- a/src/datastore_mad/remotes/iscsi/clone +++ b/src/datastore_mad/remotes/iscsi/clone @@ -76,13 +76,9 @@ DEV_SRC="/dev/$VG_NAME/$LV_SRC" CLONE_CMD=$(cat <&2" +} + function iqn_get_host { IQN="$1" TARGET=`echo "$IQN"|$CUT -d: -f2` @@ -426,10 +433,10 @@ function vmfs_set_up { if [ "$USE_SSH" != "yes" ]; then USERNAME=`echo $(cat $VMWARERC |grep ":username:"|cut -d":" -f 3|tr -d '"')` PASSWORD=`echo $(cat $VMWARERC |grep ":password:"|cut -d":" -f 3|tr -d '"')` - if [ -z $PASSWORD ]; then - VI_PARAMS="--server $DST_HOST --username $USERNAME --password \"\"" - else - VI_PARAMS="--server $DST_HOST --username $USERNAME --password $PASSWORD" + if [ -z $PASSWORD ]; then + VI_PARAMS="--server $DST_HOST --username $USERNAME --password \"\"" + else + VI_PARAMS="--server $DST_HOST --username $USERNAME --password $PASSWORD" fi fi } diff --git a/src/tm_mad/iscsi/clone b/src/tm_mad/iscsi/clone index ccce7f0df8..00b92aa330 100755 --- a/src/tm_mad/iscsi/clone +++ b/src/tm_mad/iscsi/clone @@ -81,14 +81,10 @@ CLONE_CMD=$(cat < Date: Tue, 11 Dec 2012 14:36:04 +0100 Subject: [PATCH 006/324] Feature #1592: Merge SSH connections into a single one --- src/tm_mad/iscsi/clone | 23 ++++++----------------- src/tm_mad/iscsi/ln | 26 +++++++------------------- src/tm_mad/iscsi/mv | 38 ++++++++++++++------------------------ 3 files changed, 27 insertions(+), 60 deletions(-) diff --git a/src/tm_mad/iscsi/clone b/src/tm_mad/iscsi/clone index 00b92aa330..89feebfc55 100755 --- a/src/tm_mad/iscsi/clone +++ b/src/tm_mad/iscsi/clone @@ -92,31 +92,20 @@ EOF ssh_exec_and_log "$TARGET_HOST" "$CLONE_CMD" \ "Error cloning $DST_HOST:$TARGET_DEV" -DISCOVERY_CMD=$(cat < Date: Tue, 11 Dec 2012 14:38:35 +0100 Subject: [PATCH 007/324] Feature #1592: Upload a patched version of the 'tgt-setup-lun' script provided by SZTAKI LPDS. --- share/scripts/tgt/tgt-setup-lun-one | 279 ++++++++++++++++++++++++++++ src/mad/sh/scripts_common.sh | 2 +- 2 files changed, 280 insertions(+), 1 deletion(-) create mode 100755 share/scripts/tgt/tgt-setup-lun-one diff --git a/share/scripts/tgt/tgt-setup-lun-one b/share/scripts/tgt/tgt-setup-lun-one new file mode 100755 index 0000000000..faf08949b5 --- /dev/null +++ b/share/scripts/tgt/tgt-setup-lun-one @@ -0,0 +1,279 @@ +#!/bin/bash + +# LUN assignment script +# +# Copyright (C) 2007 Erez Zilber +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation, version 2 of the +# License. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA +# 02110-1301 USA + +usage() +{ + name=$(basename $0); + echo "usage:"; + echo -e "\t$name -n tgt_name -d dev -b bs_name -t transport [initiator_IP1 initiator_IP2 ...]"; + echo "defaults:"; + echo -e "\tbacking store: rdwr"; + echo -e "\ttransport: iscsi"; + echo -e "\tinitiator: ALL"; + echo "examples:"; + echo -e "\t$name -n tgt-1 -d /dev/sdb1 192.168.1.2"; + echo -e "\t$name -n tgt-2 -d /tmp/null -b null -t iser"; + echo -e "\t$name -n tgt-3 -d ~/disk3.bin -b rdwr 192.168.1.2 192.168.1.3"; +} + +verify_params() +{ + if ! [ "$dev" -o "$bs_type" == "null" ]; then + echo "Error: a device is mandatory"; + exit 1; + else + return; + fi + + # Make sure that the device exists + if ! [ -b $dev -o -f $dev -o -c $dev ]; then + echo "Error: $dev is not a device"; + exit 1; + fi + + if ! [ "$tgt_name" ]; then + echo "Error: target name is mandatory"; + exit 1; + fi + + if ! [ "$lld_name" ]; then + echo "Error: lld name empty"; + exit 1; + fi +} + +find_vacant_tgt_id() +{ + tmp_file=`mktemp` + tgtadm --lld $lld_name --op show --mode target | strings > $tmp_file + id_list=$(cat $tmp_file | grep Target | cut -d" " -f2 | sed s/://) + next_vacant_id=1 + for id in $id_list; do + if (($id > $next_vacant_id)); then + break; + else + next_vacant_id=$((next_vacant_id+1)) + fi + done + rm -f $tmp_file + echo $next_vacant_id +} + +find_vacant_lun() +{ + tid=$1 + tgt_found=0 + next_vacant_lun=0 + tmp_file=`mktemp` + + tgtadm --lld $lld_name --op show --mode target | strings | tgt-admin -s | grep 'LUN\|Target' > $tmp_file + retcode=$? + while read line; do + # Check if we finished going over this target + if ((tgt_found == 1 && $(echo $line | grep -c "^Target") == 1)); then + break + fi + + # Check if we found the requested target + if (($(echo $line | grep -c "Target $tid:") == 1)); then + tgt_found=1 + continue + fi + + if ((tgt_found == 1 && $(echo $line | grep -c "LUN:") == 1)); then + curr_lun=$(echo $line | cut -d" " -f2) + if (($curr_lun > $next_vacant_lun)); then + break + else + next_vacant_lun=$((next_vacant_lun+1)) + fi + fi + done < $tmp_file + + rm -f $tmp_file + + if ((tgt_found == 0)); then + echo "Error: could not find a LUN for target $tid, guessing 1 as next vacant LUN" + return 1 + fi + if ((next_vacant_lun == 0)); then + echo "Error: could not find a LUN for target $tid, guessing 1 as next vacant LUN" + return 1 + fi + + return $next_vacant_lun +} + +err_exit() +{ + if ((new_tgt == 0)); then + exit 1 + fi + + echo "Deleting new target, tid=$tid" + tgtadm --lld $lld_name --op delete --mode target --tid $tid + res=$? + + if [ $res -ne 0 ]; then + echo "Error: failed to delete target, tid=$tid" + fi + + exit 1 +} + +check_if_tgt_exists() +{ + tgt_list=$(tgtadm --lld $lld_name --op show --mode target | strings | grep Target | cut -d" " -f3) + + for curr_tgt in $tgt_list; do + if [ $tgt_name = $curr_tgt ]; then + return 1 + fi + done + + return 0 +} + +if [ $# -eq 0 ]; then + usage + exit 1 +fi + +lld_name="iscsi" + +while getopts "d:n:b:t:h:" opt +do + case ${opt} in + d) + dev=$OPTARG;; + n) + tgt_name=$OPTARG;; + b) + bs_type=$OPTARG;; + t) + lld_name=$OPTARG;; + h*) + usage + exit 1 + esac +done + +shift $(($OPTIND - 1)) + +initiators=$* + +verify_params + +# Check if tgtd is running (we should have 2 daemons) +tgtd_count=`pidof tgtd | wc -w` +if [ $tgtd_count -lt 1 ]; then + echo "tgtd is not running" + echo "Exiting..." + exit 1 +fi + +echo "Using transport: $lld_name" + +if ! [[ $tgt_name =~ ^iqn ]]; then + tgt_name="iqn.2001-04.com.$(hostname -s)-$tgt_name" +fi + +# Make sure that a target with the same name doesn't exist +check_if_tgt_exists +if [ $? -eq 1 ]; then + echo "Error: target named $tgt_name already exists" + read -p "Add a new lun to the existing target? (yes/NO): " add_lun + if [ $add_lun != "yes" ]; then + exit 1 + fi + tid=$(tgtadm --lld $lld_name --op show --mode target | strings | grep $tgt_name | cut -d" " -f2) + tid=${tid%:} + new_tgt=0 +else + + i=0 + while [ true ] + do + let i=i+1 + tid=`find_vacant_tgt_id` + #tid=$? + # Create the new target + echo -n "Creating new target (name=$tgt_name, tid=$tid)..." + tgtoutput=`tgtadm --lld $lld_name --op new --mode target --tid $tid -T $tgt_name 2>&1` + res=$? + if [ "$tgtoutput" == "tgtadm: this target already exists" ]; then + echo "Target already exists (this should not happen)... Attempt $i" + elif [ $res -eq 0 ]; then # output is not about duplication and return value is zero, this is the normal condition + break + fi + if [ $i -eq 100 ]; then + echo "Too many attempts, giving up" + break + fi + done + if [ $res -ne 0 ]; then + echo "Error: failed to create target (name=$tgt_name, tid=$tid)" + exit 1 + fi + new_tgt=1 +fi +echo "OK" +find_vacant_lun $tid +lun=$? +echo "LUN ok, $lun" + +# Add a logical unit to the target +echo "Adding a logical unit ($dev) to target, tid=$tid" +if [ $bs_type ]; then + echo "Setting backing store type: $bs_type" + bs_opt="-E $bs_type" +fi +tgtadm --lld $lld_name --op new --mode logicalunit --tid $tid --lun $lun -b $dev $bs_opt +res=$? + +if [ $res -ne 0 ]; then + echo "Error: failed to add a logical unit ($dev) to target, tid=$tid" + err_exit +fi + +# Define which initiators can use this target +if test "$initiators" ; then + # Allow access only for specific initiators + echo "Accepting connections only from $initiators" + for initiator in $initiators; do + tgtadm --lld $lld_name --op bind --mode target --tid $tid -I $initiator + res=$? + + if [ $res -ne 0 ]; then + echo "Error: could not assign initiator $initiator to the target" + fi + done +else + # Allow access for everyone + echo "Accepting connections from all initiators" + tgtadm --lld $lld_name --op bind --mode target --tid $tid -I ALL + res=$? + + if [ $res -ne 0 ]; then + echo "Error: failed to set access for all initiators" + err_exit + fi +fi diff --git a/src/mad/sh/scripts_common.sh b/src/mad/sh/scripts_common.sh index adb73704d2..22ac39bc44 100644 --- a/src/mad/sh/scripts_common.sh +++ b/src/mad/sh/scripts_common.sh @@ -44,7 +44,7 @@ SYNC=sync TAR=tar TGTADM=tgtadm TGTADMIN=tgt-admin -TGTSETUPLUN=tgt-setup-lun +TGTSETUPLUN=tgt-setup-lun-one VMKFSTOOLS=vmkfstools WGET=wget From 11d0f29abafc0843626de62d37c04d3b9e9efe6d Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Tue, 11 Dec 2012 14:45:02 +0100 Subject: [PATCH 008/324] Feature #1592: Add TGT_SHARE_FILES. --- install.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/install.sh b/install.sh index 4d16a24a9f..9a2d9409b3 100755 --- a/install.sh +++ b/install.sh @@ -183,7 +183,8 @@ else CHOWN_DIRS="$ROOT" fi -SHARE_DIRS="$SHARE_LOCATION/examples" +SHARE_DIRS="$SHARE_LOCATION/examples \ + $SHARE_LOCATION/tgt" ETC_DIRS="$ETC_LOCATION/im_ec2 \ $ETC_LOCATION/vmm_ec2 \ @@ -451,6 +452,7 @@ INSTALL_FILES=( NETWORK_OVSWITCH_FILES:$VAR_LOCATION/remotes/vnm/ovswitch NETWORK_VMWARE_FILES:$VAR_LOCATION/remotes/vnm/vmware EXAMPLE_SHARE_FILES:$SHARE_LOCATION/examples + TGT_SHARE_FILES:$SHARE_LOCATION/tgt INSTALL_NOVNC_SHARE_FILE:$SHARE_LOCATION INSTALL_GEMS_SHARE_FILE:$SHARE_LOCATION HOOK_FT_FILES:$VAR_LOCATION/remotes/hooks/ft @@ -1065,6 +1067,12 @@ EXAMPLE_SHARE_FILES="share/examples/vm.template \ share/examples/private.net \ share/examples/public.net" +#------------------------------------------------------------------------------- +# File required to interact with a tgtd server +#------------------------------------------------------------------------------- + +TGT_SHARE_FILES="share/scripts/tgt/tgt-setup-lun-one" + #------------------------------------------------------------------------------- # HOOK scripts, to be installed under $VAR_LOCATION/remotes/hooks #------------------------------------------------------------------------------- From 7d1df849beca39dd8d7c310d17351f0bb6cc79b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Tue, 11 Dec 2012 15:41:59 +0100 Subject: [PATCH 009/324] Feature #1338: Add new param to enforce host capacity in one.vm.deploy and one.vm.migrate --- include/RequestManagerVirtualMachine.h | 8 ++- src/rm/RequestManagerVirtualMachine.cc | 80 ++++++++++++++++++++++---- 2 files changed, 75 insertions(+), 13 deletions(-) diff --git a/include/RequestManagerVirtualMachine.h b/include/RequestManagerVirtualMachine.h index 6530741303..879ec92527 100644 --- a/include/RequestManagerVirtualMachine.h +++ b/include/RequestManagerVirtualMachine.h @@ -62,7 +62,9 @@ protected: string& vnm, string& tm, string& ds_location, - int& ds_id, + int& ds_id, + int& free_cpu, + int& free_mem, RequestAttributes& att, PoolObjectAuth& host_perms); @@ -106,7 +108,7 @@ public: VirtualMachineDeploy(): RequestManagerVirtualMachine("VirtualMachineDeploy", "Deploys a virtual machine", - "A:sii") + "A:siib") { auth_op = AuthRequest::ADMIN; }; @@ -126,7 +128,7 @@ public: VirtualMachineMigrate(): RequestManagerVirtualMachine("VirtualMachineMigrate", "Migrates a virtual machine", - "A:siib") + "A:siibb") { auth_op = AuthRequest::ADMIN; }; diff --git a/src/rm/RequestManagerVirtualMachine.cc b/src/rm/RequestManagerVirtualMachine.cc index 016354557d..c0ca8f0e08 100644 --- a/src/rm/RequestManagerVirtualMachine.cc +++ b/src/rm/RequestManagerVirtualMachine.cc @@ -102,6 +102,8 @@ int RequestManagerVirtualMachine::get_host_information(int hid, string& tm, string& ds_location, int& ds_id, + int& free_cpu, + int& free_mem, RequestAttributes& att, PoolObjectAuth& host_perms) { @@ -129,6 +131,9 @@ int RequestManagerVirtualMachine::get_host_information(int hid, vmm = host->get_vmm_mad(); vnm = host->get_vnm_mad(); + free_cpu = host->get_share_max_cpu() - host->get_share_cpu_usage(); + free_mem = host->get_share_max_mem() - host->get_share_mem_usage(); + host->get_permissions(host_perms); cluster_id = host->get_cluster_id(); @@ -386,15 +391,18 @@ void VirtualMachineDeploy::request_execute(xmlrpc_c::paramList const& paramList, string tm_mad; string ds_location; int ds_id; + int free_cpu; + int free_mem; - int id = xmlrpc_c::value_int(paramList.getInt(1)); - int hid = xmlrpc_c::value_int(paramList.getInt(2)); + int id = xmlrpc_c::value_int(paramList.getInt(1)); + int hid = xmlrpc_c::value_int(paramList.getInt(2)); + bool enforce = xmlrpc_c::value_boolean(paramList.getBoolean(3)); bool auth = false; if (get_host_information( - hid, hostname, vmm_mad, vnm_mad, tm_mad, ds_location, ds_id, att, - host_perms) != 0) + hid, hostname, vmm_mad, vnm_mad, tm_mad, ds_location, ds_id, + free_cpu, free_mem, att, host_perms) != 0) { return; } @@ -421,6 +429,30 @@ void VirtualMachineDeploy::request_execute(xmlrpc_c::paramList const& paramList, return; } + if ( enforce ) + { + int vm_cpu, vm_mem, vm_disk; + + vm->get_requirements(vm_cpu, vm_mem, vm_disk); + + if ( free_cpu < vm_cpu || free_mem < vm_mem ) + { + ostringstream oss; + + oss << object_name(PoolObjectSQL::HOST) + << " [" << hid << "] does not have enough capacity. CPU: Free " + << free_cpu << " Requested " << vm_cpu << ", MEMORY: Free " + << free_mem << " Requested " << vm_mem; + + failure_response(ACTION, + request_error(oss.str(),""), + att); + + vm->unlock(); + return; + } + } + if ( add_history( vm,hid,hostname,vmm_mad,vnm_mad,tm_mad,ds_location,ds_id,att) != 0) { @@ -453,21 +485,25 @@ void VirtualMachineMigrate::request_execute(xmlrpc_c::paramList const& paramList string tm_mad; string ds_location; int ds_id; + int free_cpu; + int free_mem; PoolObjectAuth aux_perms; int current_ds_id; string aux_st; int current_hid; + int aux_int; - int id = xmlrpc_c::value_int(paramList.getInt(1)); - int hid = xmlrpc_c::value_int(paramList.getInt(2)); - bool live = xmlrpc_c::value_boolean(paramList.getBoolean(3)); + int id = xmlrpc_c::value_int(paramList.getInt(1)); + int hid = xmlrpc_c::value_int(paramList.getInt(2)); + bool live = xmlrpc_c::value_boolean(paramList.getBoolean(3)); + bool enforce = xmlrpc_c::value_boolean(paramList.getBoolean(4)); bool auth = false; if (get_host_information( - hid, hostname, vmm_mad, vnm_mad, tm_mad, ds_location, ds_id, att, - host_perms) != 0) + hid, hostname, vmm_mad, vnm_mad, tm_mad, ds_location, ds_id, + free_cpu, free_mem, att, host_perms) != 0) { return; } @@ -502,7 +538,7 @@ void VirtualMachineMigrate::request_execute(xmlrpc_c::paramList const& paramList if (get_host_information( current_hid, aux_st, aux_st, aux_st, aux_st, aux_st, current_ds_id, - att, aux_perms) != 0) + aux_int, aux_int, att, aux_perms) != 0) { return; } @@ -529,6 +565,30 @@ void VirtualMachineMigrate::request_execute(xmlrpc_c::paramList const& paramList return; } + if ( enforce ) + { + int vm_cpu, vm_mem, vm_disk; + + vm->get_requirements(vm_cpu, vm_mem, vm_disk); + + if ( free_cpu < vm_cpu || free_mem < vm_mem ) + { + ostringstream oss; + + oss << object_name(PoolObjectSQL::HOST) + << " [" << hid << "] does not have enough capacity. CPU: Free " + << free_cpu << " Requested " << vm_cpu << ", MEMORY: Free " + << free_mem << " Requested " << vm_mem; + + failure_response(ACTION, + request_error(oss.str(),""), + att); + + vm->unlock(); + return; + } + } + if ( add_history(vm, hid, hostname, vmm_mad, vnm_mad, tm_mad, ds_location, ds_id, att) != 0) { From 6ebd41e2188730649f128e9ea34ce2762fe574c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Tue, 11 Dec 2012 15:42:36 +0100 Subject: [PATCH 010/324] Feature #1338: Update scheduler deploy and migrate xml-rpc calls --- src/scheduler/src/pool/VirtualMachinePoolXML.cc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/scheduler/src/pool/VirtualMachinePoolXML.cc b/src/scheduler/src/pool/VirtualMachinePoolXML.cc index 1b4852cb69..244d6afd57 100644 --- a/src/scheduler/src/pool/VirtualMachinePoolXML.cc +++ b/src/scheduler/src/pool/VirtualMachinePoolXML.cc @@ -112,27 +112,28 @@ int VirtualMachinePoolXML::dispatch(int vid, int hid, bool resched) const try { - //TODO Get live migration from config file if (resched == true) { client->call(client->get_endpoint(), // serverUrl "one.vm.migrate", // methodName - "siib", // arguments format + "siibb", // arguments format &deploy_result, // resultP client->get_oneauth().c_str(), // argument 0 (AUTH) vid, // argument 1 (VM) hid, // argument 2 (HOST) - live_resched); // argument 3 (LIVE) + live_resched, // argument 3 (LIVE) + false); // argument 4 (ENFORCE) } else { client->call(client->get_endpoint(), // serverUrl "one.vm.deploy", // methodName - "sii", // arguments format + "siib", // arguments format &deploy_result, // resultP client->get_oneauth().c_str(), // argument 0 (AUTH) vid, // argument 1 (VM) - hid); // argument 2 (HOST) + hid, // argument 2 (HOST) + false); // argument 3 (ENFORCE) } } catch (exception const& e) From 06eceb43cb6b0540a5d7770b8ae5c853bb575576 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Tue, 11 Dec 2012 15:43:31 +0100 Subject: [PATCH 011/324] Feature #1338: Add enforce param to CLI and Ruby OCA --- src/cli/onevm | 31 ++++++++++--- src/oca/ruby/OpenNebula/VirtualMachine.rb | 55 +++++++++++++---------- 2 files changed, 57 insertions(+), 29 deletions(-) diff --git a/src/cli/onevm b/src/cli/onevm index 0e1f3c15de..fc1cf77cb5 100755 --- a/src/cli/onevm +++ b/src/cli/onevm @@ -56,6 +56,13 @@ cmd=CommandParser::CmdParser.new(ARGV) do :description => "Device where the image will be attached" } + ENFORCE={ + :name => "enforce", + :short => "-e", + :large => "--enforce", + :description => "Enforce that the host capacity is not exceeded" + } + ######################################################################## # Global Options ######################################################################## @@ -287,12 +294,16 @@ cmd=CommandParser::CmdParser.new(ARGV) do States: PENDING EOT - command :deploy, deploy_desc, [:range,:vmid_list], :hostid do + command :deploy, deploy_desc, [:range,:vmid_list], :hostid, :options=>[ENFORCE] do host_id = args[1] verbose = "deploying in host #{host_id}" helper.perform_actions(args[0],options,verbose) do |vm| - vm.deploy(host_id) + if !options[:enforce].nil? + vm.deploy(host_id, options[:enforce]) + else + vm.deploy(host_id) + end end end @@ -302,12 +313,16 @@ cmd=CommandParser::CmdParser.new(ARGV) do States: RUNNING EOT - command :livemigrate, livemigrate_desc, [:range,:vmid_list], :hostid do + command :livemigrate, livemigrate_desc, [:range,:vmid_list], :hostid, :options=>[ENFORCE] do host_id = args[1] verbose = "live migrating to #{host_id}" helper.perform_actions(args[0],options,verbose) do |vm| - vm.live_migrate(host_id) + if !options[:enforce].nil? + vm.live_migrate(host_id, options[:enforce]) + else + vm.live_migrate(host_id) + end end end @@ -317,12 +332,16 @@ cmd=CommandParser::CmdParser.new(ARGV) do States: RUNNING EOT - command :migrate, migrate_desc, [:range,:vmid_list], :hostid do + command :migrate, migrate_desc, [:range,:vmid_list], :hostid, :options=>[ENFORCE] do host_id = args[1] verbose = "migrating to #{host_id}" helper.perform_actions(args[0],options,verbose) do |vm| - vm.migrate(host_id) + if !options[:enforce].nil? + vm.migrate(host_id, options[:enforce]) + else + vm.migrate(host_id) + end end end diff --git a/src/oca/ruby/OpenNebula/VirtualMachine.rb b/src/oca/ruby/OpenNebula/VirtualMachine.rb index 5e7c061c8b..d4efcb6a18 100644 --- a/src/oca/ruby/OpenNebula/VirtualMachine.rb +++ b/src/oca/ruby/OpenNebula/VirtualMachine.rb @@ -140,15 +140,16 @@ module OpenNebula # Initiates the instance of the VM on the target host. # - # +host_id+ The host id (hid) of the target host where - # the VM will be instantiated. - def deploy(host_id) - return Error.new('ID not defined') if !@pe_id - - rc = @client.call(VM_METHODS[:deploy], @pe_id, host_id.to_i) - rc = nil if !OpenNebula.is_error?(rc) - - return rc + # @param host_id [Interger] The host id (hid) of the target host where + # the VM will be instantiated. + # @param enforce [true|false] If it is set to true, the host capacity + # will be checked, and the deployment will fail if the host is + # overcommited. Defaults to false + # + # @return [nil, OpenNebula::Error] nil in case of success, Error + # otherwise + def deploy(host_id, enforce=false) + return call(VM_METHODS[:deploy], @pe_id, host_id.to_i, enforce) end # Shutdowns an already deployed VM @@ -247,23 +248,31 @@ module OpenNebula end # Saves a running VM and starts it again in the specified host - def migrate(host_id) - return Error.new('ID not defined') if !@pe_id - - rc = @client.call(VM_METHODS[:migrate], @pe_id, host_id.to_i, false) - rc = nil if !OpenNebula.is_error?(rc) - - return rc + # + # @param host_id [Interger] The host id (hid) of the target host where + # the VM will be migrated. + # @param enforce [true|false] If it is set to true, the host capacity + # will be checked, and the deployment will fail if the host is + # overcommited. Defaults to false + # + # @return [nil, OpenNebula::Error] nil in case of success, Error + # otherwise + def migrate(host_id, enforce=false) + return call(VM_METHODS[:migrate], @pe_id, host_id.to_i, false, enforce) end # Migrates a running VM to another host without downtime - def live_migrate(host_id) - return Error.new('ID not defined') if !@pe_id - - rc = @client.call(VM_METHODS[:migrate], @pe_id, host_id.to_i, true) - rc = nil if !OpenNebula.is_error?(rc) - - return rc + # + # @param host_id [Interger] The host id (hid) of the target host where + # the VM will be migrated. + # @param enforce [true|false] If it is set to true, the host capacity + # will be checked, and the deployment will fail if the host is + # overcommited. Defaults to false + # + # @return [nil, OpenNebula::Error] nil in case of success, Error + # otherwise + def live_migrate(host_id, enforce=false) + return call(VM_METHODS[:migrate], @pe_id, host_id.to_i, true, enforce) end # Set the specified vm's disk to be saved in a new image From b79a9fc6c6ae5c410b9abea238ac36b91be6ab7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Tue, 11 Dec 2012 15:46:25 +0100 Subject: [PATCH 012/324] Feature #1338: Add enforce param to Java OCA --- .../opennebula/client/vm/VirtualMachine.java | 63 +++++++++++++++++-- 1 file changed, 59 insertions(+), 4 deletions(-) diff --git a/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java b/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java index d402c835d2..f32359bda6 100644 --- a/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java +++ b/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java @@ -290,6 +290,21 @@ public class VirtualMachine extends PoolElement{ return response; } + /** + * Initiates the instance of the VM on the target host. + * + * @param hostId The host id (hid) of the target host where + * the VM will be instantiated. + * @param enforce If it is set to true, the host capacity + * will be checked, and the deployment will fail if the host is + * overcommited. Defaults to false + * @return If an error occurs the error message contains the reason. + */ + public OneResponse deploy(int hostId, boolean enforce) + { + return client.call(DEPLOY, id, hostId, enforce); + } + /** * Initiates the instance of the VM on the target host. * @@ -299,7 +314,7 @@ public class VirtualMachine extends PoolElement{ */ public OneResponse deploy(int hostId) { - return client.call(DEPLOY, id, hostId); + return deploy(hostId, false); } /** @@ -337,11 +352,14 @@ public class VirtualMachine extends PoolElement{ * the vm. * @param live If true we are indicating that we want livemigration, * otherwise false. + * @param enforce If it is set to true, the host capacity + * will be checked, and the deployment will fail if the host is + * overcommited. Defaults to false * @return If an error occurs the error message contains the reason. */ - public OneResponse migrate(int hostId, boolean live) + public OneResponse migrate(int hostId, boolean live, boolean enforce) { - return client.call(MIGRATE, id, hostId, live); + return client.call(MIGRATE, id, hostId, live, enforce); } /** @@ -628,6 +646,24 @@ public class VirtualMachine extends PoolElement{ return action("unresched"); } + /** + * Migrates the virtual machine to the target host (hid). + *
+ * It does the same as {@link VirtualMachine#migrate(int, boolean)} + * with live set to false. + * + * @param hostId The target host id (hid) where we want to migrate + * the vm. + * @param enforce If it is set to true, the host capacity + * will be checked, and the deployment will fail if the host is + * overcommited. Defaults to false + * @return If an error occurs the error message contains the reason. + */ + public OneResponse migrate(int hostId, boolean enforce) + { + return migrate(hostId, false, enforce); + } + /** * Migrates the virtual machine to the target host (hid). *
@@ -643,6 +679,25 @@ public class VirtualMachine extends PoolElement{ return migrate(hostId, false); } + /** + * Performs a live migration of the virtual machine to the + * target host (hid). + *
+ * It does the same as {@link VirtualMachine#migrate(int, boolean)} + * with live set to true. + * + * @param hostId The target host id (hid) where we want to migrate + * the vm. + * @param enforce If it is set to true, the host capacity + * will be checked, and the deployment will fail if the host is + * overcommited. Defaults to false + * @return If an error occurs the error message contains the reason. + */ + public OneResponse liveMigrate(int hostId, boolean enforce) + { + return migrate(hostId, true, enforce); + } + /** * Performs a live migration of the virtual machine to the * target host (hid). @@ -656,7 +711,7 @@ public class VirtualMachine extends PoolElement{ */ public OneResponse liveMigrate(int hostId) { - return migrate(hostId, true); + return liveMigrate(hostId, false); } public int state() From 95e86aafced9cc30fe575a6bfc4399f55b615766 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Fri, 14 Dec 2012 11:47:04 +0100 Subject: [PATCH 013/324] Feature #1544: Move configuration call to new System class, and add a method to check if the OCA and oned versions are compatible --- .../src/org/opennebula/client/Client.java | 10 --- .../src/org/opennebula/client/OneSystem.java | 72 +++++++++++++++++++ src/oca/java/test/SessionTest.java | 26 +++++-- src/oca/ruby/OpenNebula.rb | 4 -- src/oca/ruby/OpenNebula/System.rb | 44 +++++++++++- 5 files changed, 135 insertions(+), 21 deletions(-) diff --git a/src/oca/java/src/org/opennebula/client/Client.java b/src/oca/java/src/org/opennebula/client/Client.java index 2fff759a34..7d4c87ad83 100644 --- a/src/oca/java/src/org/opennebula/client/Client.java +++ b/src/oca/java/src/org/opennebula/client/Client.java @@ -129,16 +129,6 @@ public class Client{ return call("system.version"); } - /** - * Calls OpenNebula and retrieves oned configuration - * - * @return The server's xml-rpc response encapsulated - */ - public OneResponse get_config() - { - return call("system.config"); - } - //-------------------------------------------------------------------------- // PRIVATE ATTRIBUTES AND METHODS //-------------------------------------------------------------------------- diff --git a/src/oca/java/src/org/opennebula/client/OneSystem.java b/src/oca/java/src/org/opennebula/client/OneSystem.java index d40aa83bae..88c61edf19 100644 --- a/src/oca/java/src/org/opennebula/client/OneSystem.java +++ b/src/oca/java/src/org/opennebula/client/OneSystem.java @@ -32,12 +32,84 @@ public class OneSystem private static final String GROUP_QUOTA_INFO = "groupquota.info"; private static final String GROUP_QUOTA_UPDATE = "groupquota.update"; + public static final String VERSION = "3.9.0"; public OneSystem(Client client) { this.client = client; } + /** + * Calls OpenNebula and retrieves the oned version + * + * @return The server's xml-rpc response encapsulated + */ + public OneResponse getOnedVersion() + { + return client.call("system.version"); + } + + /** + * Returns whether of not the oned version is the same as the OCA version + * + * @return true if oned is the same version + */ + public boolean compatibleVersion() + { + OneResponse r = getOnedVersion(); + + if (r.isError()) + { + return false; + } + + String[] ocaVersion = VERSION.split("\\.", 3); + String[] onedVersion = r.getMessage().split("\\.", 3); + + return ocaVersion.length == onedVersion.length && + ocaVersion[0].equals(onedVersion[0]) && + ocaVersion[1].equals(onedVersion[1]); + } + + /** + * Calls OpenNebula and retrieves oned configuration + * + * @return The server's xml-rpc response encapsulated + */ + public OneResponse getConfiguration() + { + return client.call("system.config"); + } + + /** + * Calls OpenNebula and retrieves oned configuration + * + * @return The xml root node in case of success, null otherwise + */ + public Node getConfigurationXML() + { + OneResponse r = getConfiguration(); + Node xml = null; + + if (r.isError()) + { + return null; + } + + try + { + DocumentBuilder builder = + DocumentBuilderFactory.newInstance().newDocumentBuilder(); + Document doc = builder.parse( + new ByteArrayInputStream(r.getMessage().getBytes())); + + xml = doc.getDocumentElement(); + } + catch (Exception e) {} + + return xml; + } + /** * Gets the default user quota limits * diff --git a/src/oca/java/test/SessionTest.java b/src/oca/java/test/SessionTest.java index 2bb971162b..d6b94c6e2b 100644 --- a/src/oca/java/test/SessionTest.java +++ b/src/oca/java/test/SessionTest.java @@ -1,12 +1,12 @@ /******************************************************************************* * Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,6 +17,7 @@ import static org.junit.Assert.*; import org.junit.Test; import org.opennebula.client.*; +import org.w3c.dom.Node; public class SessionTest { @@ -51,7 +52,7 @@ public class SessionTest { } assertNull("Client should complain about misspelled url", oneClient); - } + } @Test public void version() @@ -63,11 +64,24 @@ public class SessionTest { } catch (Exception e) { - System.out.println(e.getMessage()); + assertTrue( e.getMessage(), false ); } - OneResponse res = oneClient.get_version(); + OneSystem system = new OneSystem(oneClient); + OneResponse res = system.getOnedVersion(); assertTrue( res.getErrorMessage(), !res.isError() ); + + res = system.getConfiguration(); + assertTrue( res.getErrorMessage(), !res.isError() ); + + Node config = system.getConfigurationXML(); + assertTrue( "XML configuration is null", config != null ); + + boolean compatible = system.compatibleVersion(); + assertTrue( + "Incompatible version reported, " + + OneSystem.VERSION + ", " + system.getOnedVersion().getMessage(), + compatible ); } } diff --git a/src/oca/ruby/OpenNebula.rb b/src/oca/ruby/OpenNebula.rb index a2e7f4f8ca..9e60d0be8f 100644 --- a/src/oca/ruby/OpenNebula.rb +++ b/src/oca/ruby/OpenNebula.rb @@ -172,9 +172,5 @@ module OpenNebula def get_version() call("system.version") end - - def get_config() - call("system.config") - end end end diff --git a/src/oca/ruby/OpenNebula/System.rb b/src/oca/ruby/OpenNebula/System.rb index d7e0b1aa78..9092e0be85 100644 --- a/src/oca/ruby/OpenNebula/System.rb +++ b/src/oca/ruby/OpenNebula/System.rb @@ -27,7 +27,9 @@ module OpenNebula :userquotainfo => "userquota.info", :userquotaupdate => "userquota.update", :groupquotainfo => "groupquota.info", - :groupquotaupdate => "groupquota.update" + :groupquotaupdate => "groupquota.update", + :version => "system.version", + :config => "system.config" } ####################################################################### @@ -44,6 +46,46 @@ module OpenNebula # XML-RPC Methods ####################################################################### + # Gets the oned version + # + # @return [String, OpenNebula::Error] the oned version in case + # of success, Error otherwise + def get_oned_version() + return @client.call("system.version") + end + + # Returns whether of not the oned version is the same as the OCA version + # + # @return [true, false, OpenNebula::Error] true if oned is the same + # version + def compatible_version() + no_revision = VERSION[/^\d+\.\d+\./] + oned_v = get_oned_version + + if OpenNebula.is_error?(oned_v) + return oned_v + end + + return (oned_v =~ /#{no_revision}/) != nil + end + + # Gets the oned configuration + # + # @return [XMLElement, OpenNebula::Error] the oned configuration in case + # of success, Error otherwise + def get_configuration() + rc = @client.call(SYSTEM_METHODS[:config]) + + if OpenNebula.is_error?(rc) + return rc + end + + config = XMLElement.new + config.initialize_xml(rc, 'TEMPLATE') + + return config + end + # Gets the default user quota limits # # @return [XMLElement, OpenNebula::Error] the default user quota in case From 2178d9defedf45776d130911f58c6c69a1890909 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Sat, 15 Dec 2012 00:58:47 +0100 Subject: [PATCH 014/324] bug #1659: Better check for integerness --- src/um/Quota.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/um/Quota.cc b/src/um/Quota.cc index d42dda0b48..581a969ce6 100644 --- a/src/um/Quota.cc +++ b/src/um/Quota.cc @@ -15,6 +15,7 @@ /* -------------------------------------------------------------------------- */ #include "Quota.h" +#include /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ @@ -435,7 +436,7 @@ string Quota::float_to_str(const float &num) { ostringstream oss; - if ( num - (int)num == 0.0 ) + if ( num == ceil(num) ) { oss.precision(0); } From d28b234c9cc16914317519d1d8e62512143b96d4 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Sat, 15 Dec 2012 03:11:30 +0100 Subject: [PATCH 015/324] feature #1338: Make use of Host::test_capacity in core checks. --- include/RequestManagerVirtualMachine.h | 8 +- src/rm/RequestManagerVirtualMachine.cc | 191 ++++++++++++++++--------- 2 files changed, 128 insertions(+), 71 deletions(-) diff --git a/include/RequestManagerVirtualMachine.h b/include/RequestManagerVirtualMachine.h index 879ec92527..ca61931a76 100644 --- a/include/RequestManagerVirtualMachine.h +++ b/include/RequestManagerVirtualMachine.h @@ -63,11 +63,15 @@ protected: string& tm, string& ds_location, int& ds_id, - int& free_cpu, - int& free_mem, RequestAttributes& att, PoolObjectAuth& host_perms); + bool check_host(int hid, + int cpu, + int mem, + int disk, + string& error); + int add_history(VirtualMachine * vm, int hid, const string& hostname, diff --git a/src/rm/RequestManagerVirtualMachine.cc b/src/rm/RequestManagerVirtualMachine.cc index c0ca8f0e08..5ebda25003 100644 --- a/src/rm/RequestManagerVirtualMachine.cc +++ b/src/rm/RequestManagerVirtualMachine.cc @@ -102,8 +102,6 @@ int RequestManagerVirtualMachine::get_host_information(int hid, string& tm, string& ds_location, int& ds_id, - int& free_cpu, - int& free_mem, RequestAttributes& att, PoolObjectAuth& host_perms) { @@ -131,9 +129,6 @@ int RequestManagerVirtualMachine::get_host_information(int hid, vmm = host->get_vmm_mad(); vnm = host->get_vnm_mad(); - free_cpu = host->get_share_max_cpu() - host->get_share_cpu_usage(); - free_mem = host->get_share_max_mem() - host->get_share_mem_usage(); - host->get_permissions(host_perms); cluster_id = host->get_cluster_id(); @@ -205,6 +200,46 @@ int RequestManagerVirtualMachine::get_host_information(int hid, /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ +bool RequestManagerVirtualMachine::check_host(int hid, + int cpu, + int mem, + int disk, + string& error) +{ + Nebula& nd = Nebula::instance(); + HostPool * hpool = nd.get_hpool(); + + Host * host; + bool test; + + host = hpool->get(hid, true); + + if (host == 0) + { + error = "Host no longer exists"; + return false; + } + + test = host->test_capacity(cpu, mem, disk); + + if (!test) + { + ostringstream oss; + + oss << object_name(PoolObjectSQL::HOST) + << " " << hid << " does not have enough capacity."; + + error = oss.str(); + } + + host->unlock(); + + return test; +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + VirtualMachine * RequestManagerVirtualMachine::get_vm(int id, RequestAttributes& att) { @@ -391,8 +426,6 @@ void VirtualMachineDeploy::request_execute(xmlrpc_c::paramList const& paramList, string tm_mad; string ds_location; int ds_id; - int free_cpu; - int free_mem; int id = xmlrpc_c::value_int(paramList.getInt(1)); int hid = xmlrpc_c::value_int(paramList.getInt(2)); @@ -400,26 +433,32 @@ void VirtualMachineDeploy::request_execute(xmlrpc_c::paramList const& paramList, bool auth = false; - if (get_host_information( - hid, hostname, vmm_mad, vnm_mad, tm_mad, ds_location, ds_id, - free_cpu, free_mem, att, host_perms) != 0) + if (get_host_information(hid, + hostname, + vmm_mad, + vnm_mad, + tm_mad, + ds_location, + ds_id, + att, + host_perms) != 0) { return; } auth = vm_authorization(id, 0, 0, att, &host_perms, 0, auth_op); - if ( auth == false ) + if (auth == false) { return; } - if ( (vm = get_vm(id, att)) == 0 ) + if ((vm = get_vm(id, att)) == 0) { return; } - if ( vm->get_state() != VirtualMachine::PENDING ) + if (vm->get_state() != VirtualMachine::PENDING) { failure_response(ACTION, request_error("Wrong state to perform action",""), @@ -429,32 +468,36 @@ void VirtualMachineDeploy::request_execute(xmlrpc_c::paramList const& paramList, return; } - if ( enforce ) + if (enforce) { - int vm_cpu, vm_mem, vm_disk; + int cpu, mem, disk; + string error; - vm->get_requirements(vm_cpu, vm_mem, vm_disk); + vm->get_requirements(cpu, mem, disk); - if ( free_cpu < vm_cpu || free_mem < vm_mem ) + vm->unlock(); + + if (check_host(hid, cpu, mem, disk, error) == false) { - ostringstream oss; + failure_response(ACTION, request_error(error,""), att); + return; + } - oss << object_name(PoolObjectSQL::HOST) - << " [" << hid << "] does not have enough capacity. CPU: Free " - << free_cpu << " Requested " << vm_cpu << ", MEMORY: Free " - << free_mem << " Requested " << vm_mem; - - failure_response(ACTION, - request_error(oss.str(),""), - att); - - vm->unlock(); + if ((vm = get_vm(id, att)) == 0) + { return; } } - if ( add_history( - vm,hid,hostname,vmm_mad,vnm_mad,tm_mad,ds_location,ds_id,att) != 0) + if (add_history(vm, + hid, + hostname, + vmm_mad, + vnm_mad, + tm_mad, + ds_location, + ds_id, + att) != 0) { vm->unlock(); return; @@ -485,14 +528,11 @@ void VirtualMachineMigrate::request_execute(xmlrpc_c::paramList const& paramList string tm_mad; string ds_location; int ds_id; - int free_cpu; - int free_mem; PoolObjectAuth aux_perms; int current_ds_id; string aux_st; int current_hid; - int aux_int; int id = xmlrpc_c::value_int(paramList.getInt(1)); int hid = xmlrpc_c::value_int(paramList.getInt(2)); @@ -501,21 +541,27 @@ void VirtualMachineMigrate::request_execute(xmlrpc_c::paramList const& paramList bool auth = false; - if (get_host_information( - hid, hostname, vmm_mad, vnm_mad, tm_mad, ds_location, ds_id, - free_cpu, free_mem, att, host_perms) != 0) + if (get_host_information(hid, + hostname, + vmm_mad, + vnm_mad, + tm_mad, + ds_location, + ds_id, + att, + host_perms) != 0) { return; } auth = vm_authorization(id, 0, 0, att, &host_perms, 0, auth_op); - if ( auth == false ) + if (auth == false) { return; } - if ( (vm = get_vm(id, att)) == 0 ) + if ((vm = get_vm(id, att)) == 0) { return; } @@ -534,11 +580,35 @@ void VirtualMachineMigrate::request_execute(xmlrpc_c::paramList const& paramList current_hid = vm->get_hid(); - vm->unlock(); + if (enforce) + { + int cpu, mem, disk; + string error; - if (get_host_information( - current_hid, aux_st, aux_st, aux_st, aux_st, aux_st, current_ds_id, - aux_int, aux_int, att, aux_perms) != 0) + vm->get_requirements(cpu, mem, disk); + + vm->unlock(); + + if (check_host(hid, cpu, mem, disk, error) == false) + { + failure_response(ACTION, request_error(error,""), att); + return; + } + } + else + { + vm->unlock(); + } + + if (get_host_information(current_hid, + aux_st, + aux_st, + aux_st, + aux_st, + aux_st, + current_ds_id, + att, + aux_perms) != 0) { return; } @@ -565,38 +635,21 @@ void VirtualMachineMigrate::request_execute(xmlrpc_c::paramList const& paramList return; } - if ( enforce ) - { - int vm_cpu, vm_mem, vm_disk; - - vm->get_requirements(vm_cpu, vm_mem, vm_disk); - - if ( free_cpu < vm_cpu || free_mem < vm_mem ) - { - ostringstream oss; - - oss << object_name(PoolObjectSQL::HOST) - << " [" << hid << "] does not have enough capacity. CPU: Free " - << free_cpu << " Requested " << vm_cpu << ", MEMORY: Free " - << free_mem << " Requested " << vm_mem; - - failure_response(ACTION, - request_error(oss.str(),""), - att); - - vm->unlock(); - return; - } - } - - if ( add_history(vm, hid, hostname, vmm_mad, vnm_mad, tm_mad, ds_location, - ds_id, att) != 0) + if (add_history(vm, + hid, + hostname, + vmm_mad, + vnm_mad, + tm_mad, + ds_location, + ds_id, + att) != 0) { vm->unlock(); return; } - if ( live == true ) + if (live == true) { dm->live_migrate(vm); } From 889eb1502842bf80599082a6ec0f54c39a31a91b Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Sat, 15 Dec 2012 04:19:52 +0100 Subject: [PATCH 016/324] feature #1686: Removed unused method definitions. Moved "same-name" check. Backup object pointer to use it after deleting iterator --- include/RequestManagerRename.h | 32 +++++++++----------------------- src/pool/PoolSQL.cc | 5 ++++- src/rm/RequestManagerRename.cc | 33 +++++++++++++-------------------- 3 files changed, 26 insertions(+), 44 deletions(-) diff --git a/include/RequestManagerRename.h b/include/RequestManagerRename.h index f459c8b91f..5560cbd03c 100644 --- a/include/RequestManagerRename.h +++ b/include/RequestManagerRename.h @@ -37,18 +37,13 @@ protected: auth_op = AuthRequest::MANAGE; }; - ~RequestManagerRename(){}; + virtual ~RequestManagerRename(){}; /* -------------------------------------------------------------------- */ void request_execute(xmlrpc_c::paramList const& _paramList, RequestAttributes& att); - PoolObjectSQL * get_and_quota(int oid, - int new_uid, - int new_gid, - RequestAttributes& att); - virtual PoolObjectSQL * get(const string& name, int uid, bool lock) = 0; }; @@ -59,9 +54,8 @@ class VirtualMachineRename : public RequestManagerRename { public: VirtualMachineRename(): - RequestManagerRename("VirtualMachineRename", - "Renames a virtual machine") - { + RequestManagerRename("VirtualMachineRename","Renames a virtual machine") + { Nebula& nd = Nebula::instance(); pool = nd.get_vmpool(); auth_object = PoolObjectSQL::VM; @@ -69,11 +63,6 @@ public: ~VirtualMachineRename(){}; - int check_name_unique(int oid, int noid, RequestAttributes& att) - { - return 0; - }; - PoolObjectSQL * get(const string& name, int uid, bool lock) { return 0; @@ -88,7 +77,7 @@ class TemplateRename : public RequestManagerRename public: TemplateRename(): RequestManagerRename("TemplateRename", - "Renames a virtual machine template") + "Renames a virtual machine template") { Nebula& nd = Nebula::instance(); pool = nd.get_tpool(); @@ -111,9 +100,8 @@ class VirtualNetworkRename: public RequestManagerRename { public: VirtualNetworkRename(): - RequestManagerRename("VirtualNetworkRename", - "Renames a virtual network") - { + RequestManagerRename("VirtualNetworkRename","Renames a virtual network") + { Nebula& nd = Nebula::instance(); pool = nd.get_vnpool(); auth_object = PoolObjectSQL::NET; @@ -134,9 +122,8 @@ class ImageRename: public RequestManagerRename { public: ImageRename(): - RequestManagerRename("ImageRename", - "Renames an image") - { + RequestManagerRename("ImageRename", "Renames an image") + { Nebula& nd = Nebula::instance(); pool = nd.get_ipool(); auth_object = PoolObjectSQL::IMAGE; @@ -157,8 +144,7 @@ class DocumentRename : public RequestManagerRename { public: DocumentRename(): - RequestManagerRename("DocumentRename", - "Renames a generic document") + RequestManagerRename("DocumentRename", "Renames a generic document") { Nebula& nd = Nebula::instance(); pool = nd.get_docpool(); diff --git a/src/pool/PoolSQL.cc b/src/pool/PoolSQL.cc index 2acc5a662d..6a31a2992d 100644 --- a/src/pool/PoolSQL.cc +++ b/src/pool/PoolSQL.cc @@ -364,6 +364,7 @@ void PoolSQL::update_cache_index(string& old_name, int new_uid) { map::iterator index; + PoolObjectSQL * the_object; lock(); @@ -380,11 +381,13 @@ void PoolSQL::update_cache_index(string& old_name, if ( index != name_pool.end() ) { + the_object = index->second; + name_pool.erase(old_key); if ( name_pool.find(new_key) == name_pool.end()) { - name_pool.insert(make_pair(new_key, index->second)); + name_pool.insert(make_pair(new_key, the_object)); } } diff --git a/src/rm/RequestManagerRename.cc b/src/rm/RequestManagerRename.cc index 3fd976b9cf..ff9dabab62 100644 --- a/src/rm/RequestManagerRename.cc +++ b/src/rm/RequestManagerRename.cc @@ -29,16 +29,12 @@ void RequestManagerRename::request_execute(xmlrpc_c::paramList const& paramList, int oid = xmlrpc_c::value_int(paramList.getInt(1)); string new_name = xmlrpc_c::value_string(paramList.getString(2)); - int rc; - + int rc; string old_name; PoolObjectAuth operms; - PoolObjectSQL * object; - string obj_name; - rc = get_info(pool, oid, auth_object, att, operms, old_name); if ( rc == -1 ) @@ -46,6 +42,12 @@ void RequestManagerRename::request_execute(xmlrpc_c::paramList const& paramList, return; } + if (old_name == new_name) + { + success_response(oid, att); + return; + } + // ------------- Set authorization request for non-oneadmin's -------------- if ( att.uid != 0 ) @@ -71,24 +73,15 @@ void RequestManagerRename::request_execute(xmlrpc_c::paramList const& paramList, if ( object != 0 ) { ostringstream oss; + int id = object->get_oid(); - int duplicate_obj_oid = object->get_oid(); object->unlock(); - if ( duplicate_obj_oid == oid ) - { - // Setting the same name for the object, do nothing but consider - // it a success - success_response(oid, att); - return; - } - - - oss << PoolObjectSQL::type_to_str(auth_object) << " [" - << oid << "] cannot be renamed to " << new_name + oss << PoolObjectSQL::type_to_str(auth_object) + << " cannot be renamed to " << new_name << " because it collides with " - << PoolObjectSQL::type_to_str(auth_object) << " [" - << duplicate_obj_oid << "]"; + << PoolObjectSQL::type_to_str(auth_object) << " " + << id; failure_response(INTERNAL, request_error(oss.str(), ""), att); return; @@ -96,7 +89,7 @@ void RequestManagerRename::request_execute(xmlrpc_c::paramList const& paramList, // --------------- Update the object --------------------------------------- - object = pool->get(oid,true); + object = pool->get(oid, true); if ( object == 0 ) { From 3ad38d445f88dfb0b7289b7f9f35e586099d3756 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Mon, 17 Dec 2012 12:34:19 +0100 Subject: [PATCH 017/324] feature #1692: show commands parameters on error help --- src/cli/command_parser.rb | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/cli/command_parser.rb b/src/cli/command_parser.rb index 41bcce9b78..9094183cd4 100644 --- a/src/cli/command_parser.rb +++ b/src/cli/command_parser.rb @@ -498,15 +498,9 @@ module CommandParser else puts "one parameter to run" end - puts - puts "Usage:" - if @main - print " #{@usage}\n" - else - print " #{name} " - print_command(@commands[name]) - end + print_command_help(name) + exit -1 else id=0 From 1c826bced52fb82932d09a0e76dab786099087cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Mon, 17 Dec 2012 14:43:23 +0100 Subject: [PATCH 018/324] Bug #1694: Rollback cluster id when system DS is added to any cluster --- src/rm/RequestManagerCluster.cc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/rm/RequestManagerCluster.cc b/src/rm/RequestManagerCluster.cc index 73bcd3da75..6107511910 100644 --- a/src/rm/RequestManagerCluster.cc +++ b/src/rm/RequestManagerCluster.cc @@ -149,6 +149,18 @@ void RequestManagerCluster::add_generic( request_error("Cannot add object to cluster", err_msg), att); + // Rollback + get(object_id, true, &object, &cluster_obj); + + if ( object != 0 ) + { + cluster_obj->set_cluster(old_cluster_id, old_cluster_name); + + pool->update(object); + + object->unlock(); + } + return; } From cdab2668d13a438b4f95c3374725d1d423fd5eb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Mon, 17 Dec 2012 16:23:16 +0100 Subject: [PATCH 019/324] Bug #1694: Add new attribute system_ds to Cluster. Template attribute is now ignored --- include/Cluster.h | 56 ++++++-------------------- src/cluster/Cluster.cc | 89 +++++++++++++++++++++++++++++++++++++++--- 2 files changed, 95 insertions(+), 50 deletions(-) diff --git a/include/Cluster.h b/include/Cluster.h index 2aa93e5e8d..274720ff3f 100644 --- a/include/Cluster.h +++ b/include/Cluster.h @@ -32,20 +32,13 @@ class Cluster : public PoolObjectSQL public: /** - * Returns the SYSTEM_DS attribute, or the system DS id if it is not defined + * Returns the SYSTEM_DS attribute * - * @return the SYSTEM_DS attribute, or the system DS id if it is not defined + * @return the SYSTEM_DS attribute */ int get_ds_id() { - int ds_id; - - if ( obj_template->get("SYSTEM_DS", ds_id) == false ) - { - ds_id = DatastorePool::SYSTEM_DS_ID; - } - - return ds_id; + return system_ds; } /** @@ -103,29 +96,7 @@ public: * @param error_msg Error message, if any * @return 0 on success */ - int add_datastore(int id, string& error_msg) - { - // TODO: should fail for any system DS? - if ( id == DatastorePool::SYSTEM_DS_ID ) - { - ostringstream oss; - oss << "Datastore '"<< DatastorePool::SYSTEM_DS_NAME - << "' cannot be added to any cluster."; - - error_msg = oss.str(); - - return -1; - } - - int rc = datastores.add_collection_id(id); - - if ( rc < 0 ) - { - error_msg = "Datastore ID is already in the cluster set."; - } - - return rc; - } + int add_datastore(int id, string& error_msg); /** * Deletes this datastore ID from the set. @@ -133,17 +104,7 @@ public: * @param error_msg Error message, if any * @return 0 on success */ - int del_datastore(int id, string& error_msg) - { - int rc = datastores.del_collection_id(id); - - if ( rc < 0 ) - { - error_msg = "Datastore ID is not part of the cluster set."; - } - - return rc; - } + int del_datastore(int id, string& error_msg); /** * Adds this vnet ID to the set. @@ -219,13 +180,18 @@ private: virtual ~Cluster(){}; // ************************************************************************* - // Object Collections (Private) + // Attributes (Private) // ************************************************************************* ObjectCollection hosts; ObjectCollection datastores; ObjectCollection vnets; + /** + * System datastore id + */ + int system_ds; + // ************************************************************************* // DataBase implementation (Private) // ************************************************************************* diff --git a/src/cluster/Cluster.cc b/src/cluster/Cluster.cc index 8c25673843..cc220f55e3 100644 --- a/src/cluster/Cluster.cc +++ b/src/cluster/Cluster.cc @@ -45,7 +45,8 @@ Cluster::Cluster( PoolObjectSQL(id,CLUSTER,name,-1,-1,"","",table), hosts("HOSTS"), datastores("DATASTORES"), - vnets("VNETS") + vnets("VNETS"), + system_ds(DatastorePool::SYSTEM_DS_ID) { if (cl_template != 0) { @@ -113,6 +114,82 @@ string& Cluster::get_ds_location(string &ds_location) return ds_location; } +/* ------------------------------------------------------------------------ */ +/* ------------------------------------------------------------------------ */ + +int Cluster::add_datastore(int id, string& error_msg) +{ + if ( id == DatastorePool::SYSTEM_DS_ID ) + { + ostringstream oss; + oss << "Datastore '"<< DatastorePool::SYSTEM_DS_NAME + << "' cannot be added to any cluster."; + + error_msg = oss.str(); + + return -1; + } + + // TODO: Do not lock DS here, take ds_type as an argument + + Datastore *ds = Nebula::instance().get_dspool()->get(id, true); + + if ( ds == 0 ) + { + return -1; + } + + Datastore::DatastoreType ds_type = ds->get_type(); + + ds->unlock(); + + if ( ds_type == Datastore::SYSTEM_DS ) + { + if ( system_ds != DatastorePool::SYSTEM_DS_ID ) + { + ostringstream oss; + oss << "Cluster " << oid << " already contains the System Datastore " + << system_ds << "."; + + error_msg = oss.str(); + + return -1; + } + } + + int rc = datastores.add_collection_id(id); + + if ( rc < 0 ) + { + error_msg = "Datastore ID is already in the cluster set."; + } + else if ( ds_type == Datastore::SYSTEM_DS ) + { + system_ds = id; + } + + return rc; +} + +/* ------------------------------------------------------------------------ */ +/* ------------------------------------------------------------------------ */ + +int Cluster::del_datastore(int id, string& error_msg) +{ + int rc = datastores.del_collection_id(id); + + if ( rc < 0 ) + { + error_msg = "Datastore ID is not part of the cluster set."; + } + else if ( system_ds == id ) + { + system_ds = DatastorePool::SYSTEM_DS_ID; + } + + return rc; +} + /* ************************************************************************ */ /* Cluster :: Database Access Functions */ /* ************************************************************************ */ @@ -215,8 +292,9 @@ string& Cluster::to_xml(string& xml) const oss << "" << - "" << oid << "" << - "" << name << "" << + "" << oid << "" << + "" << name << "" << + "" << system_ds << "" << hosts.to_xml(host_collection_xml) << datastores.to_xml(ds_collection_xml) << @@ -241,8 +319,9 @@ int Cluster::from_xml(const string& xml) update_from_str(xml); // Get class base attributes - rc += xpath(oid, "/CLUSTER/ID", -1); - rc += xpath(name,"/CLUSTER/NAME", "not_found"); + rc += xpath(oid, "/CLUSTER/ID", -1); + rc += xpath(name, "/CLUSTER/NAME", "not_found"); + rc += xpath(system_ds, "/CLUSTER/SYSTEM_DS", -1); // Set oneadmin as the owner set_user(0,""); From 3c6871b2c02f80cfea1dda115030b10389fd8580 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Mon, 17 Dec 2012 16:54:17 +0100 Subject: [PATCH 020/324] Bug #1694: Remove potential deadlock --- include/Cluster.h | 3 ++- include/RequestManagerAllocate.h | 45 ++++++++++++++++++++++++++++---- include/RequestManagerCluster.h | 44 +++++++++++++++++++++++++++---- src/cluster/Cluster.cc | 15 +---------- src/rm/RequestManagerAllocate.cc | 4 ++- src/rm/RequestManagerCluster.cc | 6 ++++- 6 files changed, 90 insertions(+), 27 deletions(-) diff --git a/include/Cluster.h b/include/Cluster.h index 274720ff3f..9f47652c07 100644 --- a/include/Cluster.h +++ b/include/Cluster.h @@ -93,10 +93,11 @@ public: /** * Adds this datastore ID to the set. * @param id to be added to the cluster + * @param ds_type Datastore type * @param error_msg Error message, if any * @return 0 on success */ - int add_datastore(int id, string& error_msg); + int add_datastore(int id, Datastore::DatastoreType ds_type, string& error_msg); /** * Deletes this datastore ID from the set. diff --git a/include/RequestManagerAllocate.h b/include/RequestManagerAllocate.h index 4957ded508..3dbe8da1c7 100644 --- a/include/RequestManagerAllocate.h +++ b/include/RequestManagerAllocate.h @@ -86,11 +86,20 @@ protected: return ClusterPool::NONE_CLUSTER_ID; }; - virtual int add_to_cluster(Cluster* cluster, int id, string& error_msg) + virtual int add_to_cluster( + Cluster* cluster, + int id, + Datastore::DatastoreType ds_type, + string& error_msg) { return -1; }; + virtual Datastore::DatastoreType get_ds_type(int oid) + { + return Datastore::FILE_DS; + }; + protected: ClusterPool * clpool; @@ -176,7 +185,11 @@ public: return xmlrpc_c::value_int(paramList.getInt(2)); }; - int add_to_cluster(Cluster* cluster, int id, string& error_msg) + int add_to_cluster( + Cluster* cluster, + int id, + Datastore::DatastoreType ds_type, + string& error_msg) { return cluster->add_vnet(id, error_msg); }; @@ -274,7 +287,11 @@ public: return xmlrpc_c::value_int(paramList.getInt(5)); }; - int add_to_cluster(Cluster* cluster, int id, string& error_msg) + int add_to_cluster( + Cluster* cluster, + int id, + Datastore::DatastoreType ds_type, + string& error_msg) { return cluster->add_host(id, error_msg); }; @@ -376,9 +393,27 @@ public: return xmlrpc_c::value_int(paramList.getInt(2)); }; - int add_to_cluster(Cluster* cluster, int id, string& error_msg) + virtual Datastore::DatastoreType get_ds_type(int oid) { - return cluster->add_datastore(id, error_msg); + Datastore::DatastoreType ds_type = Datastore::FILE_DS; + Datastore *ds = static_cast(pool)->get(oid, true); + + if ( ds != 0 ) + { + ds_type = ds->get_type(); + ds->unlock(); + } + + return ds_type; + }; + + int add_to_cluster( + Cluster* cluster, + int id, + Datastore::DatastoreType ds_type, + string& error_msg) + { + return cluster->add_datastore(id, ds_type, error_msg); }; }; diff --git a/include/RequestManagerCluster.h b/include/RequestManagerCluster.h index 22ab693207..ec424ffefe 100644 --- a/include/RequestManagerCluster.h +++ b/include/RequestManagerCluster.h @@ -65,7 +65,24 @@ protected: PoolSQL * pool, PoolObjectSQL::ObjectType type); - virtual int add_object(Cluster* cluster, int id, string& error_msg) = 0; + virtual Datastore::DatastoreType get_ds_type(PoolObjectSQL *obj) + { + return Datastore::FILE_DS; + }; + + /** + * Add object to cluster id collection + * @param cluster where to add the object + * @param id of the object + * @param ds_type Datastore type, will be ignored for different objects + * @param error_msg Error reason, if any + * @return 0 on success + */ + virtual int add_object( + Cluster* cluster, + int id, + Datastore::DatastoreType ds_type, + string& error_msg) = 0; virtual int del_object(Cluster* cluster, int id, string& error_msg) = 0; @@ -86,7 +103,11 @@ public: ~RequestManagerClusterHost(){}; - virtual int add_object(Cluster* cluster, int id, string& error_msg) + virtual int add_object( + Cluster* cluster, + int id, + Datastore::DatastoreType ds_type, + string& error_msg) { return cluster->add_host(id, error_msg); }; @@ -169,9 +190,18 @@ public: ~RequestManagerClusterDatastore(){}; - virtual int add_object(Cluster* cluster, int id, string& error_msg) + virtual Datastore::DatastoreType get_ds_type(PoolObjectSQL *obj) { - return cluster->add_datastore(id, error_msg); + return static_cast(obj)->get_type(); + }; + + virtual int add_object( + Cluster* cluster, + int id, + Datastore::DatastoreType ds_type, + string& error_msg) + { + return cluster->add_datastore(id, ds_type, error_msg); }; virtual int del_object(Cluster* cluster, int id, string& error_msg) @@ -253,7 +283,11 @@ public: ~RequestManagerClusterVNet(){}; - virtual int add_object(Cluster* cluster, int id, string& error_msg) + virtual int add_object( + Cluster* cluster, + int id, + Datastore::DatastoreType ds_type, + string& error_msg) { return cluster->add_vnet(id, error_msg); }; diff --git a/src/cluster/Cluster.cc b/src/cluster/Cluster.cc index cc220f55e3..975d7413ec 100644 --- a/src/cluster/Cluster.cc +++ b/src/cluster/Cluster.cc @@ -117,7 +117,7 @@ string& Cluster::get_ds_location(string &ds_location) /* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */ -int Cluster::add_datastore(int id, string& error_msg) +int Cluster::add_datastore(int id, Datastore::DatastoreType ds_type, string& error_msg) { if ( id == DatastorePool::SYSTEM_DS_ID ) { @@ -130,19 +130,6 @@ int Cluster::add_datastore(int id, string& error_msg) return -1; } - // TODO: Do not lock DS here, take ds_type as an argument - - Datastore *ds = Nebula::instance().get_dspool()->get(id, true); - - if ( ds == 0 ) - { - return -1; - } - - Datastore::DatastoreType ds_type = ds->get_type(); - - ds->unlock(); - if ( ds_type == Datastore::SYSTEM_DS ) { if ( system_ds != DatastorePool::SYSTEM_DS_ID ) diff --git a/src/rm/RequestManagerAllocate.cc b/src/rm/RequestManagerAllocate.cc index 84dcd007c0..ef57836170 100644 --- a/src/rm/RequestManagerAllocate.cc +++ b/src/rm/RequestManagerAllocate.cc @@ -189,6 +189,8 @@ void RequestManagerAllocate::request_execute(xmlrpc_c::paramList const& params, if ( cluster_id != ClusterPool::NONE_CLUSTER_ID ) { + Datastore::DatastoreType ds_type = get_ds_type(id); + cluster = clpool->get(cluster_id, true); if ( cluster == 0 ) @@ -200,7 +202,7 @@ void RequestManagerAllocate::request_execute(xmlrpc_c::paramList const& params, return; } - rc = add_to_cluster(cluster, id, error_str); + rc = add_to_cluster(cluster, id, ds_type, error_str); if ( rc < 0 ) { diff --git a/src/rm/RequestManagerCluster.cc b/src/rm/RequestManagerCluster.cc index 6107511910..a2b98c0ad6 100644 --- a/src/rm/RequestManagerCluster.cc +++ b/src/rm/RequestManagerCluster.cc @@ -45,6 +45,8 @@ void RequestManagerCluster::add_generic( int old_cluster_id; string old_cluster_name; + Datastore::DatastoreType ds_type; + if ( cluster_id != ClusterPool::NONE_CLUSTER_ID ) { rc = get_info(clpool, cluster_id, PoolObjectSQL::CLUSTER, att, c_perms, cluster_name); @@ -102,6 +104,8 @@ void RequestManagerCluster::add_generic( old_cluster_id = cluster_obj->get_cluster_id(); old_cluster_name = cluster_obj->get_cluster_name(); + ds_type = get_ds_type(object); + if ( old_cluster_id == cluster_id ) { object->unlock(); @@ -141,7 +145,7 @@ void RequestManagerCluster::add_generic( return; } - if ( add_object(cluster, object_id, err_msg) < 0 ) + if ( add_object(cluster, object_id, ds_type, err_msg) < 0 ) { cluster->unlock(); From ca4504f984d65ed9500dbd08ac530d6b2ae7ed99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Mon, 17 Dec 2012 18:15:02 +0100 Subject: [PATCH 021/324] Bug #1694: If a DS updates its type to system_ds, update the cluster system_ds --- include/Cluster.h | 10 ++ include/Datastore.h | 9 +- include/RequestManagerUpdateTemplate.h | 5 +- src/cli/one_helper/onecluster_helper.rb | 3 +- src/datastore/Datastore.cc | 20 +++- src/rm/RequestManagerUpdateTemplate.cc | 123 ++++++++++++++++++++++++ 6 files changed, 165 insertions(+), 5 deletions(-) diff --git a/include/Cluster.h b/include/Cluster.h index 9f47652c07..eeada0ef3c 100644 --- a/include/Cluster.h +++ b/include/Cluster.h @@ -41,6 +41,16 @@ public: return system_ds; } + /** + * Sets the SYSTEM_DS attribute + * + * @param ds_id The new system datastore + */ + void set_ds_id(int ds_id) + { + system_ds = ds_id; + } + /** * Returns the DATASTORE_LOCATION for the hosts of the cluster. If not * defined that in oned.conf is returned. diff --git a/include/Datastore.h b/include/Datastore.h index a4b8d4243d..6db87fd919 100644 --- a/include/Datastore.h +++ b/include/Datastore.h @@ -57,11 +57,18 @@ public: /** * Return the string representation of a DatastoreType - * @param str_type string representing the DatastoreTypr + * @param str_type string representing the DatastoreType * @return the DatastoreType (defaults to IMAGE_DS) */ static DatastoreType str_to_type(string& str_type); + /** + * Returns the DS type found in the string template + * @param str_template string template + * @return the DatastoreType (defaults to IMAGE_DS) + */ + static DatastoreType type_in_template(string& str_template); + /** * Function to print the Datastore object into a string in XML format * @param xml the resulting XML string diff --git a/include/RequestManagerUpdateTemplate.h b/include/RequestManagerUpdateTemplate.h index 511f149ce7..07a19e93d3 100644 --- a/include/RequestManagerUpdateTemplate.h +++ b/include/RequestManagerUpdateTemplate.h @@ -40,7 +40,7 @@ protected: /* -------------------------------------------------------------------- */ - void request_execute(xmlrpc_c::paramList const& _paramList, + virtual void request_execute(xmlrpc_c::paramList const& _paramList, RequestAttributes& att); }; @@ -150,6 +150,9 @@ public: }; ~DatastoreUpdateTemplate(){}; + + virtual void request_execute(xmlrpc_c::paramList const& _paramList, + RequestAttributes& att); }; /* ------------------------------------------------------------------------- */ diff --git a/src/cli/one_helper/onecluster_helper.rb b/src/cli/one_helper/onecluster_helper.rb index 2cd5716f2d..2edb601224 100644 --- a/src/cli/one_helper/onecluster_helper.rb +++ b/src/cli/one_helper/onecluster_helper.rb @@ -96,12 +96,13 @@ class OneClusterHelper < OpenNebulaHelper::OneHelper end def format_resource(cluster) - str="%-15s: %-20s" + str="%-18s: %-20s" str_h1="%-80s" CLIHelper.print_header(str_h1 % "CLUSTER #{cluster['ID']} INFORMATION") puts str % ["ID", cluster.id.to_s] puts str % ["NAME", cluster.name] + puts str % ["SYSTEM DATASTORE", cluster['SYSTEM_DS']] puts CLIHelper.print_header(str_h1 % "CLUSTER TEMPLATE", false) diff --git a/src/datastore/Datastore.cc b/src/datastore/Datastore.cc index 6e93122920..1fe0bf2ae6 100644 --- a/src/datastore/Datastore.cc +++ b/src/datastore/Datastore.cc @@ -122,6 +122,22 @@ Datastore::DatastoreType Datastore::str_to_type(string& str_type) /* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */ +Datastore::DatastoreType Datastore::type_in_template(string& str_template) +{ + string s_ds_type; + string error_str; + + Template tmp_template; + tmp_template.parse_str_or_xml(str_template, error_str); + + tmp_template.get("TYPE", s_ds_type); + + return Datastore::str_to_type(s_ds_type); +} + +/* ------------------------------------------------------------------------ */ +/* ------------------------------------------------------------------------ */ + int Datastore::insert(SqlDB *db, string& error_str) { int rc; @@ -431,10 +447,10 @@ int Datastore::replace_template(const string& tmpl_str, string& error_str) else { type = str_to_type(s_ds_type); - - replace_template_attribute("TYPE", type_to_str(type)); } + replace_template_attribute("TYPE", type_to_str(type)); + if ( type == SYSTEM_DS ) { new_ds_mad = "-"; diff --git a/src/rm/RequestManagerUpdateTemplate.cc b/src/rm/RequestManagerUpdateTemplate.cc index 1c8988ccbb..6bcfde31a5 100644 --- a/src/rm/RequestManagerUpdateTemplate.cc +++ b/src/rm/RequestManagerUpdateTemplate.cc @@ -70,3 +70,126 @@ void RequestManagerUpdateTemplate::request_execute( return; } +/* ------------------------------------------------------------------------- */ +/* ------------------------------------------------------------------------- */ + +void DatastoreUpdateTemplate::request_execute( + xmlrpc_c::paramList const& paramList, + RequestAttributes& att) +{ + int rc; + string error_str; + + int oid = xmlrpc_c::value_int(paramList.getInt(1)); + string tmpl = xmlrpc_c::value_string(paramList.getString(2)); + + Datastore * object; + + if ( basic_authorization(oid, att) == false ) + { + return; + } + + object = static_cast(pool)->get(oid,true); + + if ( object == 0 ) + { + failure_response(NO_EXISTS, + get_error(object_name(auth_object),oid), + att); + + return; + } + + Datastore::DatastoreType prev_type = object->get_type(); + Datastore::DatastoreType new_type = Datastore::type_in_template(tmpl); + + int cluster_id = object->get_cluster_id(); + + if ( (prev_type == Datastore::SYSTEM_DS || new_type == Datastore::SYSTEM_DS) && + prev_type != new_type && + cluster_id != ClusterPool::NONE_CLUSTER_ID ) + { + object->unlock(); + + Cluster *cluster = Nebula::instance().get_clpool()->get(cluster_id, true); + + if ( cluster == 0 ) + { + failure_response(NO_EXISTS, + get_error(object_name(PoolObjectSQL::CLUSTER),cluster_id), + att); + + return; + } + + if ( new_type == Datastore::SYSTEM_DS ) + { + if ( cluster->get_ds_id() == DatastorePool::SYSTEM_DS_ID ) + { + // Cluster has a new system ds + cluster->set_ds_id(oid); + } + else + { + ostringstream oss; + oss << "Cannot change datastore type to " + << Datastore::type_to_str(Datastore::SYSTEM_DS) + << ". Cluster " << cluster_id + << " already contains the System Datastore " + << cluster->get_ds_id() << "."; + + failure_response(INTERNAL, + request_error(oss.str(),error_str), + att); + + cluster->unlock(); + + return; + } + } + else if ( cluster->get_ds_id() == oid ) + { + // This was the cluster's system DS, now it must be set to '0' + cluster->set_ds_id( DatastorePool::SYSTEM_DS_ID ); + } + + Nebula::instance().get_clpool()->update(cluster); + cluster->unlock(); + + object = static_cast(pool)->get(oid,true); + + if ( object == 0 ) + { + failure_response(NO_EXISTS, + get_error(object_name(auth_object),oid), + att); + + return; + } + } + + rc = object->replace_template(tmpl, error_str); + + if ( rc != 0 ) + { + // TODO: rollback + + failure_response(INTERNAL, + request_error("Cannot update template",error_str), + att); + object->unlock(); + + return; + } + + pool->update(object); + + object->unlock(); + + success_response(oid, att); + + return; +} + + From 31ed95618d190b691e170b55bce49ac08c4b7eb4 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Mon, 17 Dec 2012 18:31:34 +0100 Subject: [PATCH 022/324] bug #1171: add support for tls in ldap auth Patch provided by Nicolas Agius --- src/authm_mad/remotes/ldap/ldap_auth.conf | 3 +++ src/authm_mad/remotes/ldap/ldap_auth.rb | 1 + 2 files changed, 4 insertions(+) diff --git a/src/authm_mad/remotes/ldap/ldap_auth.conf b/src/authm_mad/remotes/ldap/ldap_auth.conf index af016f554e..3b97f1e92e 100644 --- a/src/authm_mad/remotes/ldap/ldap_auth.conf +++ b/src/authm_mad/remotes/ldap/ldap_auth.conf @@ -28,6 +28,9 @@ server 1: :host: localhost :port: 389 + # Uncomment this line for tsl conections + #:encryption: :simple_tls + # base hierarchy where to search for users and groups :base: 'dc=domain' diff --git a/src/authm_mad/remotes/ldap/ldap_auth.rb b/src/authm_mad/remotes/ldap/ldap_auth.rb index 4090628fed..7f3293c269 100644 --- a/src/authm_mad/remotes/ldap/ldap_auth.rb +++ b/src/authm_mad/remotes/ldap/ldap_auth.rb @@ -41,6 +41,7 @@ class LdapAuth ops[:host]=@options[:host] if @options[:host] ops[:port]=@options[:port].to_i if @options[:port] + ops[:encryption]=@options[:encryption] if @options[:encryption] @ldap=Net::LDAP.new(ops) end From 62def952c6e1e0a2b2719877dfcbe51bf992d7d5 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Tue, 18 Dec 2012 10:43:06 +0100 Subject: [PATCH 023/324] Feature #1592: Check if TGTSETUPLUN is installed --- src/datastore_mad/remotes/iscsi/clone | 3 +++ src/datastore_mad/remotes/iscsi/cp | 3 +++ src/datastore_mad/remotes/iscsi/mkfs | 3 +++ src/mad/sh/scripts_common.sh | 18 ++++++++++++++++++ 4 files changed, 27 insertions(+) diff --git a/src/datastore_mad/remotes/iscsi/clone b/src/datastore_mad/remotes/iscsi/clone index 926c9c8074..e0055a085b 100755 --- a/src/datastore_mad/remotes/iscsi/clone +++ b/src/datastore_mad/remotes/iscsi/clone @@ -64,6 +64,9 @@ BASE_IQN="${XPATH_ELEMENTS[6]:-$BASE_IQN}" SRC="${XPATH_ELEMENTS[7]}" SIZE="${XPATH_ELEMENTS[8]}" +# Check if 'TGTSETUPLUN' is installed +tgt_setup_lun_install "$DST_HOST" "$BASE_PATH" + set_up_datastore "$BASE_PATH" "$RESTRICTED_DIRS" "$SAFE_DIRS" "$UMASK" LV_NAME="lv-one-${ID}" diff --git a/src/datastore_mad/remotes/iscsi/cp b/src/datastore_mad/remotes/iscsi/cp index 86e31424d3..c9a73b5bd3 100755 --- a/src/datastore_mad/remotes/iscsi/cp +++ b/src/datastore_mad/remotes/iscsi/cp @@ -76,6 +76,9 @@ SHA1="${XPATH_ELEMENTS[10]}" NO_DECOMPRESS="${XPATH_ELEMENTS[11]}" LIMIT_TRANSFER_BW="${XPATH_ELEMENTS[12]}" +# Check if 'TGTSETUPLUN' is installed +tgt_setup_lun_install "$DST_HOST" "$BASE_PATH" + set_up_datastore "$BASE_PATH" "$RESTRICTED_DIRS" "$SAFE_DIRS" "$UMASK" LV_NAME="lv-one-${ID}" diff --git a/src/datastore_mad/remotes/iscsi/mkfs b/src/datastore_mad/remotes/iscsi/mkfs index 3dfe40bcf9..e2f5e6fdd3 100755 --- a/src/datastore_mad/remotes/iscsi/mkfs +++ b/src/datastore_mad/remotes/iscsi/mkfs @@ -66,6 +66,9 @@ BASE_IQN="${XPATH_ELEMENTS[6]:-$BASE_IQN}" FSTYPE="${XPATH_ELEMENTS[7]}" SIZE="${XPATH_ELEMENTS[8]:-0}" +# Check if 'TGTSETUPLUN' is installed +tgt_setup_lun_install "$DST_HOST" "$BASE_PATH" + set_up_datastore "$BASE_PATH" "$RESTRICTED_DIRS" "$SAFE_DIRS" "$UMASK" LV_NAME="lv-one-${ID}" diff --git a/src/mad/sh/scripts_common.sh b/src/mad/sh/scripts_common.sh index 22ac39bc44..cb1979019a 100644 --- a/src/mad/sh/scripts_common.sh +++ b/src/mad/sh/scripts_common.sh @@ -403,6 +403,24 @@ function iqn_get_vg_name { echo $TARGET|$AWK -F. '{print $(NF-1)}' } +function tgt_setup_lun_install { + DST_HOST="$1" + BASE_PATH="$2" + + CHECK_FILE="$BASE_PATH/.tgt-setup-lun" + + if [ ! -f "$CHECK_FILE" ]; then + $SSH "$DST_HOST" "$SUDO $TGTSETUPLUN" 2>&1 | \ + $GREP -q "command not found" + if [ "$?" = "0" ]; then + error_message "$TGTSETUPLUN is not installed in $DST_HOST." + exit 127 + else + touch "$CHECK_FILE" + fi + fi +} + function tgt_setup_lun { IQN="$1" DEV="$2" From 1cb2d27ffaccab95e3c4d5e3e67ce888a5c213c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Tue, 18 Dec 2012 13:46:54 +0100 Subject: [PATCH 024/324] Bug #1694: onedb migrator --- src/onedb/3.8.1_to_3.9.80.rb | 86 ++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/src/onedb/3.8.1_to_3.9.80.rb b/src/onedb/3.8.1_to_3.9.80.rb index 6c4f489615..d03487348a 100644 --- a/src/onedb/3.8.1_to_3.9.80.rb +++ b/src/onedb/3.8.1_to_3.9.80.rb @@ -259,6 +259,92 @@ module Migrator @db.run "DROP TABLE old_group_pool;" + ######################################################################## + # Bug #1694: SYSTEM_DS is now set with the method adddatastore + ######################################################################## + + @db.run "ALTER TABLE cluster_pool RENAME TO old_cluster_pool;" + @db.run "CREATE TABLE cluster_pool (oid INTEGER PRIMARY KEY, name VARCHAR(128), body TEXT, uid INTEGER, gid INTEGER, owner_u INTEGER, group_u INTEGER, other_u INTEGER, UNIQUE(name));" + + @db.fetch("SELECT * FROM old_cluster_pool") do |row| + doc = Document.new(row[:body]) + + system_ds = 0 + + doc.root.each_element("TEMPLATE") do |e| + elem = e.delete_element("SYSTEM_DS") + + if !elem.nil? + system_ds = elem.text.to_i + end + end + + if system_ds != 0 + updated_body = nil + + @db.fetch("SELECT body FROM datastore_pool WHERE oid=#{system_ds}") do |ds_row| + ds_doc = Document.new(ds_row[:body]) + + type = "0" # IMAGE_DS + + ds_doc.root.each_element("TYPE") do |e| + type = e.text + end + + if type != "1" + puts " > Cluster #{row[:oid]} has the "<< + "System Datastore set to Datastore #{system_ds}, "<< + "but its type is not SYSTEM_DS. The System Datastore "<< + "for this Cluster will be set to 0" + + system_ds = 0 + else + cluster_id = "-1" + + ds_doc.root.each_element("CLUSTER_ID") do |e| + cluster_id = e.text + end + + if row[:oid] != cluster_id.to_i + puts " > Cluster #{row[:oid]} has the "<< + "System Datastore set to Datastore #{system_ds}, "<< + "but it is not part of the Cluster. It will be added now." + + ds_doc.root.each_element("CLUSTER_ID") do |e| + e.text = row[:oid] + end + + ds_doc.root.each_element("CLUSTER") do |e| + e.text = row[:name] + end + + updated_body = ds_doc.root.to_s + end + end + end + + if !updated_body.nil? + @db[:datastore_pool].where(:oid => system_ds).update( + :body => updated_body) + end + end + + doc.root.add_element("SYSTEM_DS").text = system_ds.to_s + + @db[:cluster_pool].insert( + :oid => row[:oid], + :name => row[:name], + :body => doc.root.to_s, + :uid => row[:uid], + :gid => row[:gid], + :owner_u => row[:owner_u], + :group_u => row[:group_u], + :other_u => row[:other_u]) + end + + @db.run "DROP TABLE old_cluster_pool;" + + ######################################################################## # # Banner for the new /var/lib/one/vms directory From bb8f6ec4c6692917e575fd59710e1f2f4d6def2d Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Tue, 18 Dec 2012 13:42:49 +0100 Subject: [PATCH 025/324] Fix confirmation message when deleting elements in Sunstone (cherry picked from commit c459697b4ce001815fd89dbd64c0debe42000336) --- src/sunstone/public/js/sunstone.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/sunstone/public/js/sunstone.js b/src/sunstone/public/js/sunstone.js index 01e5a9f4db..faa3c1940e 100644 --- a/src/sunstone/public/js/sunstone.js +++ b/src/sunstone/public/js/sunstone.js @@ -758,8 +758,15 @@ function popUpConfirmDialog(target_elem){ var value = $(target_elem).val(); var tab_id = $(target_elem).parents('.tab').attr('id'); var button = Sunstone.getButton(tab_id,value); - var tip = button.tip; + + if (button.tip == undefined) + var tip = tr("You have to confrim this action"); + else + var tip = button.tip + $('button#confirm_proceed',dialog).val(value); + + $('div#confirm_tip',dialog).text(tip); dialog.dialog("open"); } @@ -772,7 +779,12 @@ function popUpConfirmWithSelectDialog(target_elem){ var value = $(target_elem).val(); var tab_id = $(target_elem).parents('.tab').attr('id'); var button = Sunstone.getButton(tab_id,value); - var tip = button.tip; + + if (button.tip == undefined) + var tip = tr("You have to confrim this action"); + else + var tip = button.tip + var select_var = button.select(); $('select#confirm_select',dialog).html(select_var); $('div#confirm_with_select_tip',dialog).text(tip); From a10e19fe05249d952228dcc8a454e9df5ed82cd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Tue, 18 Dec 2012 17:29:47 +0100 Subject: [PATCH 026/324] Bug #1694: FSCK checks the system_ds is part of the cluster, and that there are not more than one system ds per cluster --- src/onedb/fsck.rb | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/onedb/fsck.rb b/src/onedb/fsck.rb index 9a252c01fd..a63ba2a2c9 100644 --- a/src/onedb/fsck.rb +++ b/src/onedb/fsck.rb @@ -249,6 +249,7 @@ module OneDBFsck ######################################################################## # Clusters # + # CLUSTER/SYSTEM_DS # CLUSTER/HOSTS/ID # CLUSTER/DATASTORES/ID # CLUSTER/VNETS/ID @@ -277,6 +278,8 @@ module OneDBFsck cluster[row[:oid]][:hosts] = [] cluster[row[:oid]][:datastores] = [] cluster[row[:oid]][:vnets] = [] + + cluster[row[:oid]][:system_ds] = 0 end hosts_fix = {} @@ -331,7 +334,26 @@ module OneDBFsck datastores_fix[row[:oid]] = doc.to_s else - cluster[cluster_id][:datastores] << row[:oid] + if doc.root.get_text('TYPE').to_s != "1" + cluster[cluster_id][:datastores] << row[:oid] + else + if cluster[cluster_id][:system_ds] == 0 + cluster[cluster_id][:datastores] << row[:oid] + cluster[cluster_id][:system_ds] = row[:oid] + else + log_error("System Datastore #{row[:oid]} is in Cluster #{cluster_id}, but it already contains System Datastore #{cluster[cluster_id][:system_ds]}") + + doc.root.each_element('CLUSTER_ID') do |e| + e.text = "-1" + end + + doc.root.each_element('CLUSTER') do |e| + e.text = "" + end + + datastores_fix[row[:oid]] = doc.to_s + end + end end end end @@ -401,6 +423,16 @@ module OneDBFsck ds_new_elem = doc.root.add_element("DATASTORES") + doc.root.each_element("SYSTEM_DS") do |e| + system_ds = e.text.to_i + + if system_ds != cluster[cluster_id][:system_ds] + log_error("Cluster #{cluster_id} has System Datastore set to #{system_ds}, but it should be #{cluster[cluster_id][:system_ds]}") + + e.text = cluster[cluster_id][:system_ds].to_s + end + end + cluster[cluster_id][:datastores].each do |id| id_elem = ds_elem.elements.delete("ID[.=#{id}]") From 076ca44e751d595e91cdd8553edb1475445947e9 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Tue, 18 Dec 2012 15:52:11 +0100 Subject: [PATCH 027/324] feature #1700: Change oca files to be lowercase --- install.sh | 60 +++++++++---------- src/oca/ruby/{OpenNebula.rb => opennebula.rb} | 48 +++++++-------- .../{OpenNebula/Acl.rb => opennebula/acl.rb} | 0 .../AclPool.rb => opennebula/acl_pool.rb} | 2 +- .../Cluster.rb => opennebula/cluster.rb} | 2 +- .../cluster_pool.rb} | 2 +- .../Datastore.rb => opennebula/datastore.rb} | 2 +- .../datastore_pool.rb} | 2 +- .../Document.rb => opennebula/document.rb} | 2 +- .../document_json.rb} | 0 .../document_pool.rb} | 4 +- .../document_pool_json.rb} | 0 .../Group.rb => opennebula/group.rb} | 2 +- .../GroupPool.rb => opennebula/group_pool.rb} | 2 +- .../Host.rb => opennebula/host.rb} | 2 +- .../HostPool.rb => opennebula/host_pool.rb} | 2 +- .../Image.rb => opennebula/image.rb} | 2 +- .../ImagePool.rb => opennebula/image_pool.rb} | 2 +- .../Pool.rb => opennebula/pool.rb} | 0 .../System.rb => opennebula/system.rb} | 2 +- .../Template.rb => opennebula/template.rb} | 2 +- .../template_pool.rb} | 2 +- .../User.rb => opennebula/user.rb} | 2 +- .../UserPool.rb => opennebula/user_pool.rb} | 2 +- .../virtual_machine.rb} | 2 +- .../virtual_machine_pool.rb} | 2 +- .../virtual_network.rb} | 2 +- .../virtual_network_pool.rb} | 2 +- .../XMLUtils.rb => opennebula/xml_utils.rb} | 0 29 files changed, 77 insertions(+), 77 deletions(-) rename src/oca/ruby/{OpenNebula.rb => opennebula.rb} (86%) rename src/oca/ruby/{OpenNebula/Acl.rb => opennebula/acl.rb} (100%) rename src/oca/ruby/{OpenNebula/AclPool.rb => opennebula/acl_pool.rb} (98%) rename src/oca/ruby/{OpenNebula/Cluster.rb => opennebula/cluster.rb} (99%) rename src/oca/ruby/{OpenNebula/ClusterPool.rb => opennebula/cluster_pool.rb} (98%) rename src/oca/ruby/{OpenNebula/Datastore.rb => opennebula/datastore.rb} (99%) rename src/oca/ruby/{OpenNebula/DatastorePool.rb => opennebula/datastore_pool.rb} (98%) rename src/oca/ruby/{OpenNebula/Document.rb => opennebula/document.rb} (99%) rename src/oca/ruby/{OpenNebula/DocumentJSON.rb => opennebula/document_json.rb} (100%) rename src/oca/ruby/{OpenNebula/DocumentPool.rb => opennebula/document_pool.rb} (98%) rename src/oca/ruby/{OpenNebula/DocumentPoolJSON.rb => opennebula/document_pool_json.rb} (100%) rename src/oca/ruby/{OpenNebula/Group.rb => opennebula/group.rb} (99%) rename src/oca/ruby/{OpenNebula/GroupPool.rb => opennebula/group_pool.rb} (98%) rename src/oca/ruby/{OpenNebula/Host.rb => opennebula/host.rb} (99%) rename src/oca/ruby/{OpenNebula/HostPool.rb => opennebula/host_pool.rb} (99%) rename src/oca/ruby/{OpenNebula/Image.rb => opennebula/image.rb} (99%) rename src/oca/ruby/{OpenNebula/ImagePool.rb => opennebula/image_pool.rb} (99%) rename src/oca/ruby/{OpenNebula/Pool.rb => opennebula/pool.rb} (100%) rename src/oca/ruby/{OpenNebula/System.rb => opennebula/system.rb} (99%) rename src/oca/ruby/{OpenNebula/Template.rb => opennebula/template.rb} (99%) rename src/oca/ruby/{OpenNebula/TemplatePool.rb => opennebula/template_pool.rb} (99%) rename src/oca/ruby/{OpenNebula/User.rb => opennebula/user.rb} (99%) rename src/oca/ruby/{OpenNebula/UserPool.rb => opennebula/user_pool.rb} (98%) rename src/oca/ruby/{OpenNebula/VirtualMachine.rb => opennebula/virtual_machine.rb} (99%) rename src/oca/ruby/{OpenNebula/VirtualMachinePool.rb => opennebula/virtual_machine_pool.rb} (99%) rename src/oca/ruby/{OpenNebula/VirtualNetwork.rb => opennebula/virtual_network.rb} (99%) rename src/oca/ruby/{OpenNebula/VirtualNetworkPool.rb => opennebula/virtual_network_pool.rb} (99%) rename src/oca/ruby/{OpenNebula/XMLUtils.rb => opennebula/xml_utils.rb} (100%) diff --git a/install.sh b/install.sh index e316e55b94..88c9f877ee 100755 --- a/install.sh +++ b/install.sh @@ -376,7 +376,7 @@ LIB_MARKET_CLIENT_DIRS="$LIB_LOCATION/ruby \ $LIB_LOCATION/ruby/cloud/marketplace" LIB_OCA_CLIENT_DIRS="$LIB_LOCATION/ruby \ - $LIB_LOCATION/ruby/OpenNebula" + $LIB_LOCATION/ruby/opennebula" LIB_CLI_CLIENT_DIRS="$LIB_LOCATION/ruby/cli \ $LIB_LOCATION/ruby/cli/one_helper" @@ -406,7 +406,7 @@ INSTALL_FILES=( INCLUDE_FILES:$INCLUDE_LOCATION LIB_FILES:$LIB_LOCATION RUBY_LIB_FILES:$LIB_LOCATION/ruby - RUBY_OPENNEBULA_LIB_FILES:$LIB_LOCATION/ruby/OpenNebula + RUBY_OPENNEBULA_LIB_FILES:$LIB_LOCATION/ruby/opennebula MAD_RUBY_LIB_FILES:$LIB_LOCATION/ruby MAD_RUBY_LIB_FILES:$VAR_LOCATION/remotes MAD_SH_LIB_FILES:$LIB_LOCATION/sh @@ -1081,35 +1081,35 @@ INSTALL_GEMS_SHARE_FILE="share/install_gems/install_gems" #------------------------------------------------------------------------------- # OCA Files #------------------------------------------------------------------------------- -OCA_LIB_FILES="src/oca/ruby/OpenNebula.rb" +OCA_LIB_FILES="src/oca/ruby/opennebula.rb" -RUBY_OPENNEBULA_LIB_FILES="src/oca/ruby/OpenNebula/Host.rb \ - src/oca/ruby/OpenNebula/HostPool.rb \ - src/oca/ruby/OpenNebula/Pool.rb \ - src/oca/ruby/OpenNebula/User.rb \ - src/oca/ruby/OpenNebula/UserPool.rb \ - src/oca/ruby/OpenNebula/VirtualMachine.rb \ - src/oca/ruby/OpenNebula/VirtualMachinePool.rb \ - src/oca/ruby/OpenNebula/VirtualNetwork.rb \ - src/oca/ruby/OpenNebula/VirtualNetworkPool.rb \ - src/oca/ruby/OpenNebula/Image.rb \ - src/oca/ruby/OpenNebula/ImagePool.rb \ - src/oca/ruby/OpenNebula/Template.rb \ - src/oca/ruby/OpenNebula/TemplatePool.rb \ - src/oca/ruby/OpenNebula/Document.rb \ - src/oca/ruby/OpenNebula/DocumentPool.rb \ - src/oca/ruby/OpenNebula/DocumentJSON.rb \ - src/oca/ruby/OpenNebula/DocumentPoolJSON.rb \ - src/oca/ruby/OpenNebula/Group.rb \ - src/oca/ruby/OpenNebula/GroupPool.rb \ - src/oca/ruby/OpenNebula/Acl.rb \ - src/oca/ruby/OpenNebula/AclPool.rb \ - src/oca/ruby/OpenNebula/Datastore.rb \ - src/oca/ruby/OpenNebula/DatastorePool.rb \ - src/oca/ruby/OpenNebula/Cluster.rb \ - src/oca/ruby/OpenNebula/ClusterPool.rb \ - src/oca/ruby/OpenNebula/XMLUtils.rb \ - src/oca/ruby/OpenNebula/System.rb" +RUBY_OPENNEBULA_LIB_FILES="src/oca/ruby/opennebula/host.rb \ + src/oca/ruby/opennebula/host_pool.rb \ + src/oca/ruby/opennebula/pool.rb \ + src/oca/ruby/opennebula/user.rb \ + src/oca/ruby/opennebula/user_pool.rb \ + src/oca/ruby/opennebula/virtual_machine.rb \ + src/oca/ruby/opennebula/virtual_machine_pool.rb \ + src/oca/ruby/opennebula/virtual_network.rb \ + src/oca/ruby/opennebula/virtual_network_pool.rb \ + src/oca/ruby/opennebula/image.rb \ + src/oca/ruby/opennebula/image_pool.rb \ + src/oca/ruby/opennebula/template.rb \ + src/oca/ruby/opennebula/template_pool.rb \ + src/oca/ruby/opennebula/document.rb \ + src/oca/ruby/opennebula/document_pool.rb \ + src/oca/ruby/opennebula/document_json.rb \ + src/oca/ruby/opennebula/document_pool_json.rb \ + src/oca/ruby/opennebula/group.rb \ + src/oca/ruby/opennebula/group_pool.rb \ + src/oca/ruby/opennebula/acl.rb \ + src/oca/ruby/opennebula/acl_pool.rb \ + src/oca/ruby/opennebula/datastore.rb \ + src/oca/ruby/opennebula/datastore_pool.rb \ + src/oca/ruby/opennebula/cluster.rb \ + src/oca/ruby/opennebula/cluster_pool.rb \ + src/oca/ruby/opennebula/xml_utils.rb \ + src/oca/ruby/opennebula/system.rb" #------------------------------------------------------------------------------- # Common Cloud Files diff --git a/src/oca/ruby/OpenNebula.rb b/src/oca/ruby/opennebula.rb similarity index 86% rename from src/oca/ruby/OpenNebula.rb rename to src/oca/ruby/opennebula.rb index 9e60d0be8f..0c720589fe 100644 --- a/src/oca/ruby/OpenNebula.rb +++ b/src/oca/ruby/opennebula.rb @@ -25,30 +25,30 @@ require 'digest/sha1' require 'rexml/document' require 'pp' -require 'OpenNebula/XMLUtils' -require 'OpenNebula/VirtualMachine' -require 'OpenNebula/VirtualMachinePool' -require 'OpenNebula/VirtualNetwork' -require 'OpenNebula/VirtualNetworkPool' -require 'OpenNebula/Image' -require 'OpenNebula/ImagePool' -require 'OpenNebula/User' -require 'OpenNebula/UserPool' -require 'OpenNebula/Host' -require 'OpenNebula/HostPool' -require 'OpenNebula/Template' -require 'OpenNebula/TemplatePool' -require 'OpenNebula/Group' -require 'OpenNebula/GroupPool' -require 'OpenNebula/Acl' -require 'OpenNebula/AclPool' -require 'OpenNebula/Datastore' -require 'OpenNebula/DatastorePool' -require 'OpenNebula/Cluster' -require 'OpenNebula/ClusterPool' -require 'OpenNebula/Document' -require 'OpenNebula/DocumentPool' -require 'OpenNebula/System' +require 'opennebula/xml_utils' +require 'opennebula/virtual_machine' +require 'opennebula/virtual_machine_pool' +require 'opennebula/virtual_network' +require 'opennebula/virtual_network_pool' +require 'opennebula/image' +require 'opennebula/image_pool' +require 'opennebula/user' +require 'opennebula/user_pool' +require 'opennebula/host' +require 'opennebula/host_pool' +require 'opennebula/template' +require 'opennebula/template_pool' +require 'opennebula/group' +require 'opennebula/group_pool' +require 'opennebula/acl' +require 'opennebula/acl_pool' +require 'opennebula/datastore' +require 'opennebula/datastore_pool' +require 'opennebula/cluster' +require 'opennebula/cluster_pool' +require 'opennebula/document' +require 'opennebula/document_pool' +require 'opennebula/system' module OpenNebula diff --git a/src/oca/ruby/OpenNebula/Acl.rb b/src/oca/ruby/opennebula/acl.rb similarity index 100% rename from src/oca/ruby/OpenNebula/Acl.rb rename to src/oca/ruby/opennebula/acl.rb diff --git a/src/oca/ruby/OpenNebula/AclPool.rb b/src/oca/ruby/opennebula/acl_pool.rb similarity index 98% rename from src/oca/ruby/OpenNebula/AclPool.rb rename to src/oca/ruby/opennebula/acl_pool.rb index 4c7a1deef1..4118111145 100644 --- a/src/oca/ruby/OpenNebula/AclPool.rb +++ b/src/oca/ruby/opennebula/acl_pool.rb @@ -15,7 +15,7 @@ #--------------------------------------------------------------------------- # -require 'OpenNebula/Pool' +require 'opennebula/pool' module OpenNebula class AclPool < Pool diff --git a/src/oca/ruby/OpenNebula/Cluster.rb b/src/oca/ruby/opennebula/cluster.rb similarity index 99% rename from src/oca/ruby/OpenNebula/Cluster.rb rename to src/oca/ruby/opennebula/cluster.rb index e6abb4c7a3..1319753c88 100644 --- a/src/oca/ruby/OpenNebula/Cluster.rb +++ b/src/oca/ruby/opennebula/cluster.rb @@ -15,7 +15,7 @@ #--------------------------------------------------------------------------- # -require 'OpenNebula/Pool' +require 'opennebula/pool' module OpenNebula class Cluster < PoolElement diff --git a/src/oca/ruby/OpenNebula/ClusterPool.rb b/src/oca/ruby/opennebula/cluster_pool.rb similarity index 98% rename from src/oca/ruby/OpenNebula/ClusterPool.rb rename to src/oca/ruby/opennebula/cluster_pool.rb index 780b72a347..7ab1ca0aa6 100644 --- a/src/oca/ruby/OpenNebula/ClusterPool.rb +++ b/src/oca/ruby/opennebula/cluster_pool.rb @@ -15,7 +15,7 @@ #--------------------------------------------------------------------------- # -require 'OpenNebula/Pool' +require 'opennebula/pool' module OpenNebula class ClusterPool < Pool diff --git a/src/oca/ruby/OpenNebula/Datastore.rb b/src/oca/ruby/opennebula/datastore.rb similarity index 99% rename from src/oca/ruby/OpenNebula/Datastore.rb rename to src/oca/ruby/opennebula/datastore.rb index fa1410203a..dfe41800b6 100644 --- a/src/oca/ruby/OpenNebula/Datastore.rb +++ b/src/oca/ruby/opennebula/datastore.rb @@ -15,7 +15,7 @@ #--------------------------------------------------------------------------- # -require 'OpenNebula/Pool' +require 'opennebula/pool' module OpenNebula class Datastore < PoolElement diff --git a/src/oca/ruby/OpenNebula/DatastorePool.rb b/src/oca/ruby/opennebula/datastore_pool.rb similarity index 98% rename from src/oca/ruby/OpenNebula/DatastorePool.rb rename to src/oca/ruby/opennebula/datastore_pool.rb index b491d394fe..5a41ba2389 100644 --- a/src/oca/ruby/OpenNebula/DatastorePool.rb +++ b/src/oca/ruby/opennebula/datastore_pool.rb @@ -15,7 +15,7 @@ #--------------------------------------------------------------------------- # -require 'OpenNebula/Pool' +require 'opennebula/pool' module OpenNebula class DatastorePool < Pool diff --git a/src/oca/ruby/OpenNebula/Document.rb b/src/oca/ruby/opennebula/document.rb similarity index 99% rename from src/oca/ruby/OpenNebula/Document.rb rename to src/oca/ruby/opennebula/document.rb index bcb186c8e5..5b3be75da7 100644 --- a/src/oca/ruby/OpenNebula/Document.rb +++ b/src/oca/ruby/opennebula/document.rb @@ -14,7 +14,7 @@ # limitations under the License. # #--------------------------------------------------------------------------- # -require 'OpenNebula/Pool' +require 'opennebula/pool' module OpenNebula diff --git a/src/oca/ruby/OpenNebula/DocumentJSON.rb b/src/oca/ruby/opennebula/document_json.rb similarity index 100% rename from src/oca/ruby/OpenNebula/DocumentJSON.rb rename to src/oca/ruby/opennebula/document_json.rb diff --git a/src/oca/ruby/OpenNebula/DocumentPool.rb b/src/oca/ruby/opennebula/document_pool.rb similarity index 98% rename from src/oca/ruby/OpenNebula/DocumentPool.rb rename to src/oca/ruby/opennebula/document_pool.rb index 3b428aa698..167820e278 100644 --- a/src/oca/ruby/OpenNebula/DocumentPool.rb +++ b/src/oca/ruby/opennebula/document_pool.rb @@ -14,7 +14,7 @@ # limitations under the License. # #--------------------------------------------------------------------------- # -require 'OpenNebula/Pool' +require 'opennebula/pool' module OpenNebula @@ -22,7 +22,7 @@ module OpenNebula # and the factory method. # # @example - # require 'OpenNebula/DocumentPool' + # require 'opennebuña/document_pool' # # module OpenNebula # class CustomObjectPool < DocumentPool diff --git a/src/oca/ruby/OpenNebula/DocumentPoolJSON.rb b/src/oca/ruby/opennebula/document_pool_json.rb similarity index 100% rename from src/oca/ruby/OpenNebula/DocumentPoolJSON.rb rename to src/oca/ruby/opennebula/document_pool_json.rb diff --git a/src/oca/ruby/OpenNebula/Group.rb b/src/oca/ruby/opennebula/group.rb similarity index 99% rename from src/oca/ruby/OpenNebula/Group.rb rename to src/oca/ruby/opennebula/group.rb index fcfefe8e38..ec6bb05e7a 100644 --- a/src/oca/ruby/OpenNebula/Group.rb +++ b/src/oca/ruby/opennebula/group.rb @@ -15,7 +15,7 @@ #--------------------------------------------------------------------------- # -require 'OpenNebula/Pool' +require 'opennebula/pool' module OpenNebula class Group < PoolElement diff --git a/src/oca/ruby/OpenNebula/GroupPool.rb b/src/oca/ruby/opennebula/group_pool.rb similarity index 98% rename from src/oca/ruby/OpenNebula/GroupPool.rb rename to src/oca/ruby/opennebula/group_pool.rb index 20ebdeed08..8a6a83fc85 100644 --- a/src/oca/ruby/OpenNebula/GroupPool.rb +++ b/src/oca/ruby/opennebula/group_pool.rb @@ -15,7 +15,7 @@ #--------------------------------------------------------------------------- # -require 'OpenNebula/Pool' +require 'opennebula/pool' module OpenNebula class GroupPool < Pool diff --git a/src/oca/ruby/OpenNebula/Host.rb b/src/oca/ruby/opennebula/host.rb similarity index 99% rename from src/oca/ruby/OpenNebula/Host.rb rename to src/oca/ruby/opennebula/host.rb index 1519351f80..8eb3cf8d29 100644 --- a/src/oca/ruby/OpenNebula/Host.rb +++ b/src/oca/ruby/opennebula/host.rb @@ -15,7 +15,7 @@ #--------------------------------------------------------------------------- # -require 'OpenNebula/Pool' +require 'opennebula/pool' module OpenNebula class Host < PoolElement diff --git a/src/oca/ruby/OpenNebula/HostPool.rb b/src/oca/ruby/opennebula/host_pool.rb similarity index 99% rename from src/oca/ruby/OpenNebula/HostPool.rb rename to src/oca/ruby/opennebula/host_pool.rb index 8d71712d5a..7ac3e25400 100644 --- a/src/oca/ruby/OpenNebula/HostPool.rb +++ b/src/oca/ruby/opennebula/host_pool.rb @@ -15,7 +15,7 @@ #--------------------------------------------------------------------------- # -require 'OpenNebula/Pool' +require 'opennebula/pool' module OpenNebula class HostPool < Pool diff --git a/src/oca/ruby/OpenNebula/Image.rb b/src/oca/ruby/opennebula/image.rb similarity index 99% rename from src/oca/ruby/OpenNebula/Image.rb rename to src/oca/ruby/opennebula/image.rb index 53a2f8aea7..de21fe8848 100644 --- a/src/oca/ruby/OpenNebula/Image.rb +++ b/src/oca/ruby/opennebula/image.rb @@ -15,7 +15,7 @@ #--------------------------------------------------------------------------- # -require 'OpenNebula/Pool' +require 'opennebula/pool' require 'fileutils' module OpenNebula diff --git a/src/oca/ruby/OpenNebula/ImagePool.rb b/src/oca/ruby/opennebula/image_pool.rb similarity index 99% rename from src/oca/ruby/OpenNebula/ImagePool.rb rename to src/oca/ruby/opennebula/image_pool.rb index 97cab2eb67..08fe1f7d6d 100644 --- a/src/oca/ruby/OpenNebula/ImagePool.rb +++ b/src/oca/ruby/opennebula/image_pool.rb @@ -15,7 +15,7 @@ #--------------------------------------------------------------------------- # -require 'OpenNebula/Pool' +require 'opennebula/pool' module OpenNebula class ImagePool < Pool diff --git a/src/oca/ruby/OpenNebula/Pool.rb b/src/oca/ruby/opennebula/pool.rb similarity index 100% rename from src/oca/ruby/OpenNebula/Pool.rb rename to src/oca/ruby/opennebula/pool.rb diff --git a/src/oca/ruby/OpenNebula/System.rb b/src/oca/ruby/opennebula/system.rb similarity index 99% rename from src/oca/ruby/OpenNebula/System.rb rename to src/oca/ruby/opennebula/system.rb index 9092e0be85..12d5ab81f7 100644 --- a/src/oca/ruby/OpenNebula/System.rb +++ b/src/oca/ruby/opennebula/system.rb @@ -15,7 +15,7 @@ #--------------------------------------------------------------------------- # -require 'OpenNebula/Pool' +require 'opennebula/pool' module OpenNebula class System diff --git a/src/oca/ruby/OpenNebula/Template.rb b/src/oca/ruby/opennebula/template.rb similarity index 99% rename from src/oca/ruby/OpenNebula/Template.rb rename to src/oca/ruby/opennebula/template.rb index 73a6d48aac..69cef3d027 100644 --- a/src/oca/ruby/OpenNebula/Template.rb +++ b/src/oca/ruby/opennebula/template.rb @@ -15,7 +15,7 @@ #--------------------------------------------------------------------------- # -require 'OpenNebula/Pool' +require 'opennebula/pool' module OpenNebula class Template < PoolElement diff --git a/src/oca/ruby/OpenNebula/TemplatePool.rb b/src/oca/ruby/opennebula/template_pool.rb similarity index 99% rename from src/oca/ruby/OpenNebula/TemplatePool.rb rename to src/oca/ruby/opennebula/template_pool.rb index 820d7c8d7b..ed8f724d6f 100644 --- a/src/oca/ruby/OpenNebula/TemplatePool.rb +++ b/src/oca/ruby/opennebula/template_pool.rb @@ -15,7 +15,7 @@ #--------------------------------------------------------------------------- # -require 'OpenNebula/Pool' +require 'opennebula/pool' module OpenNebula class TemplatePool < Pool diff --git a/src/oca/ruby/OpenNebula/User.rb b/src/oca/ruby/opennebula/user.rb similarity index 99% rename from src/oca/ruby/OpenNebula/User.rb rename to src/oca/ruby/opennebula/user.rb index a4c381ccb6..fbcc9b2c80 100644 --- a/src/oca/ruby/OpenNebula/User.rb +++ b/src/oca/ruby/opennebula/user.rb @@ -15,7 +15,7 @@ #--------------------------------------------------------------------------- # -require 'OpenNebula/Pool' +require 'opennebula/pool' module OpenNebula class User < PoolElement diff --git a/src/oca/ruby/OpenNebula/UserPool.rb b/src/oca/ruby/opennebula/user_pool.rb similarity index 98% rename from src/oca/ruby/OpenNebula/UserPool.rb rename to src/oca/ruby/opennebula/user_pool.rb index b4d9b733a6..964f1bb49e 100644 --- a/src/oca/ruby/OpenNebula/UserPool.rb +++ b/src/oca/ruby/opennebula/user_pool.rb @@ -15,7 +15,7 @@ #--------------------------------------------------------------------------- # -require 'OpenNebula/Pool' +require 'opennebula/pool' module OpenNebula class UserPool < Pool diff --git a/src/oca/ruby/OpenNebula/VirtualMachine.rb b/src/oca/ruby/opennebula/virtual_machine.rb similarity index 99% rename from src/oca/ruby/OpenNebula/VirtualMachine.rb rename to src/oca/ruby/opennebula/virtual_machine.rb index 31cd2952e8..e4805271e1 100644 --- a/src/oca/ruby/OpenNebula/VirtualMachine.rb +++ b/src/oca/ruby/opennebula/virtual_machine.rb @@ -15,7 +15,7 @@ #--------------------------------------------------------------------------- # -require 'OpenNebula/Pool' +require 'opennebula/pool' module OpenNebula class VirtualMachine < PoolElement diff --git a/src/oca/ruby/OpenNebula/VirtualMachinePool.rb b/src/oca/ruby/opennebula/virtual_machine_pool.rb similarity index 99% rename from src/oca/ruby/OpenNebula/VirtualMachinePool.rb rename to src/oca/ruby/opennebula/virtual_machine_pool.rb index b0a06af35a..0afe393374 100644 --- a/src/oca/ruby/OpenNebula/VirtualMachinePool.rb +++ b/src/oca/ruby/opennebula/virtual_machine_pool.rb @@ -15,7 +15,7 @@ #--------------------------------------------------------------------------- # -require 'OpenNebula/Pool' +require 'opennebula/pool' module OpenNebula class VirtualMachinePool < Pool diff --git a/src/oca/ruby/OpenNebula/VirtualNetwork.rb b/src/oca/ruby/opennebula/virtual_network.rb similarity index 99% rename from src/oca/ruby/OpenNebula/VirtualNetwork.rb rename to src/oca/ruby/opennebula/virtual_network.rb index b6964b4d0e..1d85bc0ffc 100644 --- a/src/oca/ruby/OpenNebula/VirtualNetwork.rb +++ b/src/oca/ruby/opennebula/virtual_network.rb @@ -15,7 +15,7 @@ #--------------------------------------------------------------------------- # -require 'OpenNebula/Pool' +require 'opennebula/pool' module OpenNebula class VirtualNetwork < PoolElement diff --git a/src/oca/ruby/OpenNebula/VirtualNetworkPool.rb b/src/oca/ruby/opennebula/virtual_network_pool.rb similarity index 99% rename from src/oca/ruby/OpenNebula/VirtualNetworkPool.rb rename to src/oca/ruby/opennebula/virtual_network_pool.rb index 135da47e72..31b4c95d60 100644 --- a/src/oca/ruby/OpenNebula/VirtualNetworkPool.rb +++ b/src/oca/ruby/opennebula/virtual_network_pool.rb @@ -15,7 +15,7 @@ #--------------------------------------------------------------------------- # -require 'OpenNebula/Pool' +require 'opennebula/pool' module OpenNebula class VirtualNetworkPool < Pool diff --git a/src/oca/ruby/OpenNebula/XMLUtils.rb b/src/oca/ruby/opennebula/xml_utils.rb similarity index 100% rename from src/oca/ruby/OpenNebula/XMLUtils.rb rename to src/oca/ruby/opennebula/xml_utils.rb From 18657919d2c751aff97ad9511c6bc3f802c72150 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Tue, 18 Dec 2012 09:14:47 -0600 Subject: [PATCH 028/324] feature #1700: Change oca libs dir in install.sh --- install.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/install.sh b/install.sh index 88c9f877ee..e277d77fdb 100755 --- a/install.sh +++ b/install.sh @@ -196,7 +196,7 @@ ETC_DIRS="$ETC_LOCATION/im_ec2 \ $ETC_LOCATION/cli" LIB_DIRS="$LIB_LOCATION/ruby \ - $LIB_LOCATION/ruby/OpenNebula \ + $LIB_LOCATION/ruby/opennebula \ $LIB_LOCATION/ruby/zona \ $LIB_LOCATION/ruby/cloud/ \ $LIB_LOCATION/ruby/cloud/econe \ @@ -357,22 +357,22 @@ SELF_SERVICE_DIRS="\ $LIB_LOCATION/ruby/cloud/occi/ui/public/vendor/FontAwesome/font" OZONES_CLIENT_DIRS="$LIB_LOCATION/ruby \ - $LIB_LOCATION/ruby/OpenNebula \ + $LIB_LOCATION/ruby/opennebula \ $LIB_LOCATION/ruby/cli \ $LIB_LOCATION/ruby/cli/ozones_helper \ $LIB_LOCATION/ruby/zona" LIB_ECO_CLIENT_DIRS="$LIB_LOCATION/ruby \ - $LIB_LOCATION/ruby/OpenNebula \ + $LIB_LOCATION/ruby/opennebula \ $LIB_LOCATION/ruby/cloud/ \ $LIB_LOCATION/ruby/cloud/econe" LIB_OCCI_CLIENT_DIRS="$LIB_LOCATION/ruby \ - $LIB_LOCATION/ruby/OpenNebula \ + $LIB_LOCATION/ruby/opennebula \ $LIB_LOCATION/ruby/cloud/occi" LIB_MARKET_CLIENT_DIRS="$LIB_LOCATION/ruby \ - $LIB_LOCATION/ruby/OpenNebula \ + $LIB_LOCATION/ruby/opennebula \ $LIB_LOCATION/ruby/cloud/marketplace" LIB_OCA_CLIENT_DIRS="$LIB_LOCATION/ruby \ @@ -488,11 +488,11 @@ INSTALL_CLIENT_FILES=( OZONES_LIB_API_ZONA_FILES:$LIB_LOCATION/ruby/zona CLI_CONF_FILES:$ETC_LOCATION/cli OCA_LIB_FILES:$LIB_LOCATION/ruby - RUBY_OPENNEBULA_LIB_FILES:$LIB_LOCATION/ruby/OpenNebula + RUBY_OPENNEBULA_LIB_FILES:$LIB_LOCATION/ruby/opennebula ) INSTALL_SUNSTONE_RUBY_FILES=( - RUBY_OPENNEBULA_LIB_FILES:$LIB_LOCATION/ruby/OpenNebula + RUBY_OPENNEBULA_LIB_FILES:$LIB_LOCATION/ruby/opennebula OCA_LIB_FILES:$LIB_LOCATION/ruby ) @@ -541,7 +541,7 @@ INSTALL_SUNSTONE_ETC_FILES=( INSTALL_OZONES_RUBY_FILES=( OZONES_RUBY_LIB_FILES:$LIB_LOCATION/ruby - RUBY_OPENNEBULA_LIB_FILES:$LIB_LOCATION/ruby/OpenNebula + RUBY_OPENNEBULA_LIB_FILES:$LIB_LOCATION/ruby/opennebula ) INSTALL_OZONES_FILES=( @@ -673,7 +673,7 @@ RUBY_LIB_FILES="src/mad/ruby/ActionManager.rb \ src/mad/ruby/ssh_stream.rb \ src/vnm_mad/one_vnm.rb \ src/mad/ruby/Ganglia.rb \ - src/oca/ruby/OpenNebula.rb \ + src/oca/ruby/opennebula.rb \ src/authm_mad/remotes/ssh/ssh_auth.rb \ src/authm_mad/remotes/server_x509/server_x509_auth.rb \ src/authm_mad/remotes/server_cipher/server_cipher_auth.rb \ From b4f467553437aa620887db0fac18247cafa47f51 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Tue, 18 Dec 2012 11:30:09 -0600 Subject: [PATCH 029/324] feature #1700: Take out OCA classes to different files and change requires --- install.sh | 5 + src/cli/one_helper.rb | 2 +- src/cloud/common/CloudServer.rb | 2 +- src/cloud/ec2/lib/ImageEC2.rb | 2 +- src/cloud/occi/lib/ImageOCCI.rb | 2 +- src/cloud/occi/lib/UserOCCI.rb | 2 +- src/cloud/occi/lib/VirtualMachineOCCI.rb | 2 +- src/cloud/occi/lib/VirtualNetworkOCCI.rb | 2 +- src/im_mad/remotes/vmware.d/vmware.rb | 2 +- src/oca/ruby/opennebula.rb | 122 +---- src/oca/ruby/opennebula/client.rb | 102 +++++ src/oca/ruby/opennebula/document.rb | 2 +- src/oca/ruby/opennebula/error.rb | 52 +++ src/oca/ruby/opennebula/pool.rb | 250 ---------- src/oca/ruby/opennebula/pool_element.rb | 268 +++++++++++ src/oca/ruby/opennebula/xml_element.rb | 427 ++++++++++++++++++ src/oca/ruby/opennebula/xml_pool.rb | 45 ++ src/oca/ruby/opennebula/xml_utils.rb | 410 +---------------- src/oca/ruby/test/HostPool_spec.rb | 2 +- src/oca/ruby/test/Host_spec.rb | 2 +- src/oca/ruby/test/UserPool_spec.rb | 2 +- src/oca/ruby/test/User_spec.rb | 2 +- src/oca/ruby/test/VirtualMachinePool_spec.rb | 2 +- src/oca/ruby/test/VirtualMachine_spec.rb | 2 +- src/oca/ruby/test/VirtualNetworkPool_spec.rb | 2 +- src/oca/ruby/test/VirtualNetwork_spec.rb | 2 +- src/oca/ruby/test/XMLUtils_spec.rb | 4 +- src/ozones/Server/lib/OZones.rb | 2 +- .../Server/lib/test/helpers/OpenNebula.rb | 30 +- src/sunstone/OpenNebulaVNC.rb | 2 +- src/sunstone/models/OpenNebulaJSON.rb | 2 +- 31 files changed, 939 insertions(+), 816 deletions(-) create mode 100644 src/oca/ruby/opennebula/client.rb create mode 100644 src/oca/ruby/opennebula/error.rb create mode 100644 src/oca/ruby/opennebula/pool_element.rb create mode 100644 src/oca/ruby/opennebula/xml_element.rb create mode 100644 src/oca/ruby/opennebula/xml_pool.rb diff --git a/install.sh b/install.sh index e277d77fdb..e419fe066f 100755 --- a/install.sh +++ b/install.sh @@ -1109,6 +1109,11 @@ RUBY_OPENNEBULA_LIB_FILES="src/oca/ruby/opennebula/host.rb \ src/oca/ruby/opennebula/cluster.rb \ src/oca/ruby/opennebula/cluster_pool.rb \ src/oca/ruby/opennebula/xml_utils.rb \ + src/oca/ruby/opennebula/client.rb \ + src/oca/ruby/opennebula/error.rb \ + src/oca/ruby/opennebula/pool_element.rb \ + src/oca/ruby/opennebula/xml_element.rb \ + src/oca/ruby/opennebula/xml_pool.rb \ src/oca/ruby/opennebula/system.rb" #------------------------------------------------------------------------------- diff --git a/src/cli/one_helper.rb b/src/cli/one_helper.rb index 8330a43446..4d82d79d92 100644 --- a/src/cli/one_helper.rb +++ b/src/cli/one_helper.rb @@ -16,7 +16,7 @@ require 'cli_helper' -require 'OpenNebula' +require 'opennebula' include OpenNebula module OpenNebulaHelper diff --git a/src/cloud/common/CloudServer.rb b/src/cloud/common/CloudServer.rb index 904e072ec0..f6524255f1 100644 --- a/src/cloud/common/CloudServer.rb +++ b/src/cloud/common/CloudServer.rb @@ -14,7 +14,7 @@ # limitations under the License. # #--------------------------------------------------------------------------- # -require 'OpenNebula' +require 'opennebula' ############################################################################## # This class represents a generic Cloud Server using the OpenNebula Cloud diff --git a/src/cloud/ec2/lib/ImageEC2.rb b/src/cloud/ec2/lib/ImageEC2.rb index 585fedd81f..bfce8fd97f 100644 --- a/src/cloud/ec2/lib/ImageEC2.rb +++ b/src/cloud/ec2/lib/ImageEC2.rb @@ -15,7 +15,7 @@ #--------------------------------------------------------------------------- # require 'uuidtools' -require 'OpenNebula' +require 'opennebula' include OpenNebula diff --git a/src/cloud/occi/lib/ImageOCCI.rb b/src/cloud/occi/lib/ImageOCCI.rb index f95f4f65bc..4a09bab2a8 100644 --- a/src/cloud/occi/lib/ImageOCCI.rb +++ b/src/cloud/occi/lib/ImageOCCI.rb @@ -14,7 +14,7 @@ # limitations under the License. # #--------------------------------------------------------------------------- # -require 'OpenNebula' +require 'opennebula' include OpenNebula diff --git a/src/cloud/occi/lib/UserOCCI.rb b/src/cloud/occi/lib/UserOCCI.rb index 0038bdaa3a..aa82255d81 100644 --- a/src/cloud/occi/lib/UserOCCI.rb +++ b/src/cloud/occi/lib/UserOCCI.rb @@ -14,7 +14,7 @@ # limitations under the License. # #--------------------------------------------------------------------------- # -require 'OpenNebula' +require 'opennebula' include OpenNebula diff --git a/src/cloud/occi/lib/VirtualMachineOCCI.rb b/src/cloud/occi/lib/VirtualMachineOCCI.rb index 0af7e05e2c..90f67b9e3f 100644 --- a/src/cloud/occi/lib/VirtualMachineOCCI.rb +++ b/src/cloud/occi/lib/VirtualMachineOCCI.rb @@ -15,7 +15,7 @@ # limitations under the License. # #--------------------------------------------------------------------------- # -require 'OpenNebula' +require 'opennebula' include OpenNebula diff --git a/src/cloud/occi/lib/VirtualNetworkOCCI.rb b/src/cloud/occi/lib/VirtualNetworkOCCI.rb index 6efe071bba..b145a9bfed 100644 --- a/src/cloud/occi/lib/VirtualNetworkOCCI.rb +++ b/src/cloud/occi/lib/VirtualNetworkOCCI.rb @@ -14,7 +14,7 @@ # limitations under the License. # #--------------------------------------------------------------------------- # -require 'OpenNebula' +require 'opennebula' require 'ipaddr' include OpenNebula diff --git a/src/im_mad/remotes/vmware.d/vmware.rb b/src/im_mad/remotes/vmware.d/vmware.rb index cd02f42fbe..5bccd3f900 100755 --- a/src/im_mad/remotes/vmware.d/vmware.rb +++ b/src/im_mad/remotes/vmware.d/vmware.rb @@ -41,7 +41,7 @@ ENV['LANG'] = 'C' require "scripts_common" require 'yaml' require "CommandManager" -require 'OpenNebula' +require 'opennebula' include OpenNebula begin diff --git a/src/oca/ruby/opennebula.rb b/src/oca/ruby/opennebula.rb index 0c720589fe..f3d9d0ff39 100644 --- a/src/oca/ruby/opennebula.rb +++ b/src/oca/ruby/opennebula.rb @@ -20,12 +20,13 @@ begin # require 'rubygems' rescue Exception end -require 'xmlrpc/client' require 'digest/sha1' require 'rexml/document' require 'pp' require 'opennebula/xml_utils' +require 'opennebula/client' +require 'opennebula/error' require 'opennebula/virtual_machine' require 'opennebula/virtual_machine_pool' require 'opennebula/virtual_network' @@ -54,123 +55,4 @@ module OpenNebula # OpenNebula version VERSION = '3.9.0' - - # 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 - ESUCCESS = 0x0000 - EAUTHENTICATION = 0x0100 - EAUTHORIZATION = 0x0200 - ENO_EXISTS = 0x0400 - EACTION = 0x0800 - EXML_RPC_API = 0x1000 - EINTERNAL = 0x2000 - ENOTDEFINED = 0x1111 - - attr_reader :message, :errno - - # +message+ Description of the error - # +errno+ OpenNebula code error - def initialize(message=nil, errno=0x1111) - @message = message - @errno = errno - end - - def to_str() - @message - 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 - - - if OpenNebula::NOKOGIRI - class NokogiriStreamParser < XMLRPC::XMLParser::AbstractStreamParser - def initialize - @parser_class = NokogiriParser - end - - class NokogiriParser < Nokogiri::XML::SAX::Document - include XMLRPC::XMLParser::StreamParserMixin - - alias :cdata_block :character - alias :characters :character - alias :end_element :endElement - alias :start_element :startElement - - def parse(str) - parser = Nokogiri::XML::SAX::Parser.new(self) - parser.parse(str) - end - end - end - end - - - # The client class, represents the connection with the core and handles the - # xml-rpc calls. - class Client - attr_accessor :one_auth - - begin - require 'xmlparser' - XMLPARSER=true - rescue LoadError - XMLPARSER=false - end - - def initialize(secret=nil, endpoint=nil) - if secret - @one_auth = secret - elsif ENV["ONE_AUTH"] and !ENV["ONE_AUTH"].empty? and File.file?(ENV["ONE_AUTH"]) - @one_auth = File.read(ENV["ONE_AUTH"]) - elsif File.file?(ENV["HOME"]+"/.one/one_auth") - @one_auth = File.read(ENV["HOME"]+"/.one/one_auth") - else - raise "ONE_AUTH file not present" - end - - @one_auth.rstrip! - - if endpoint - @one_endpoint = endpoint - elsif ENV["ONE_XMLRPC"] - @one_endpoint = ENV["ONE_XMLRPC"] - else - @one_endpoint = "http://localhost:2633/RPC2" - end - - @server = XMLRPC::Client.new2(@one_endpoint) - - if OpenNebula::NOKOGIRI - @server.set_parser(NokogiriStreamParser.new) - elsif XMLPARSER - @server.set_parser(XMLRPC::XMLParser::XMLStreamParser.new) - end - end - - def call(action, *args) - begin - response = @server.call_async("one."+action, @one_auth, *args) - - if response[0] == false - Error.new(response[1], response[2]) - else - response[1] #response[1..-1] - end - rescue Exception => e - Error.new(e.message) - end - end - - def get_version() - call("system.version") - end - end end diff --git a/src/oca/ruby/opennebula/client.rb b/src/oca/ruby/opennebula/client.rb new file mode 100644 index 0000000000..b7e7ad78f1 --- /dev/null +++ b/src/oca/ruby/opennebula/client.rb @@ -0,0 +1,102 @@ +# -------------------------------------------------------------------------- # +# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # + +require 'xmlrpc/client' + +module OpenNebula + if OpenNebula::NOKOGIRI + class NokogiriStreamParser < XMLRPC::XMLParser::AbstractStreamParser + def initialize + @parser_class = NokogiriParser + end + + class NokogiriParser < Nokogiri::XML::SAX::Document + include XMLRPC::XMLParser::StreamParserMixin + + alias :cdata_block :character + alias :characters :character + alias :end_element :endElement + alias :start_element :startElement + + def parse(str) + parser = Nokogiri::XML::SAX::Parser.new(self) + parser.parse(str) + end + end + end + end + + # The client class, represents the connection with the core and handles the + # xml-rpc calls. + class Client + attr_accessor :one_auth + + begin + require 'xmlparser' + XMLPARSER=true + rescue LoadError + XMLPARSER=false + end + + def initialize(secret=nil, endpoint=nil) + if secret + @one_auth = secret + elsif ENV["ONE_AUTH"] and !ENV["ONE_AUTH"].empty? and File.file?(ENV["ONE_AUTH"]) + @one_auth = File.read(ENV["ONE_AUTH"]) + elsif File.file?(ENV["HOME"]+"/.one/one_auth") + @one_auth = File.read(ENV["HOME"]+"/.one/one_auth") + else + raise "ONE_AUTH file not present" + end + + @one_auth.rstrip! + + if endpoint + @one_endpoint = endpoint + elsif ENV["ONE_XMLRPC"] + @one_endpoint = ENV["ONE_XMLRPC"] + else + @one_endpoint = "http://localhost:2633/RPC2" + end + + @server = XMLRPC::Client.new2(@one_endpoint) + + if OpenNebula::NOKOGIRI + @server.set_parser(NokogiriStreamParser.new) + elsif XMLPARSER + @server.set_parser(XMLRPC::XMLParser::XMLStreamParser.new) + end + end + + def call(action, *args) + begin + response = @server.call_async("one."+action, @one_auth, *args) + + if response[0] == false + Error.new(response[1], response[2]) + else + response[1] #response[1..-1] + end + rescue Exception => e + Error.new(e.message) + end + end + + def get_version() + call("system.version") + end + end +end diff --git a/src/oca/ruby/opennebula/document.rb b/src/oca/ruby/opennebula/document.rb index 5b3be75da7..6c735bcd6e 100644 --- a/src/oca/ruby/opennebula/document.rb +++ b/src/oca/ruby/opennebula/document.rb @@ -21,7 +21,7 @@ module OpenNebula # All subclasses must define the DOCUMENT_TYPE constant. # # @example - # require 'OpenNebula/Document' + # require 'opennebula/document' # # module OpenNebula # class CustomObject < Document diff --git a/src/oca/ruby/opennebula/error.rb b/src/oca/ruby/opennebula/error.rb new file mode 100644 index 0000000000..a0981de571 --- /dev/null +++ b/src/oca/ruby/opennebula/error.rb @@ -0,0 +1,52 @@ +# -------------------------------------------------------------------------- # +# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # + + +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 + ESUCCESS = 0x0000 + EAUTHENTICATION = 0x0100 + EAUTHORIZATION = 0x0200 + ENO_EXISTS = 0x0400 + EACTION = 0x0800 + EXML_RPC_API = 0x1000 + EINTERNAL = 0x2000 + ENOTDEFINED = 0x1111 + + attr_reader :message, :errno + + # +message+ Description of the error + # +errno+ OpenNebula code error + def initialize(message=nil, errno=0x1111) + @message = message + @errno = errno + end + + def to_str() + @message + 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 +end diff --git a/src/oca/ruby/opennebula/pool.rb b/src/oca/ruby/opennebula/pool.rb index e917f7bb32..7308a30cfe 100644 --- a/src/oca/ruby/opennebula/pool.rb +++ b/src/oca/ruby/opennebula/pool.rb @@ -153,254 +153,4 @@ module OpenNebula return str end end - - # The PoolElement Class represents a generic element of a Pool in - # XML format - class PoolElement < XMLElement - - protected - # node:: _XML_is a XML element that represents the Pool element - # client:: _Client_ represents a XML-RPC connection - def initialize(node, client) - @xml = node - @client = client - - if self['ID'] - @pe_id = self['ID'].to_i - else - @pe_id = nil - end - @name = self['NAME'] if self['NAME'] - end - - ####################################################################### - # Common XML-RPC Methods for all the Pool Element Types - ####################################################################### - - # Common client call wrapper. Checks that @pe_id is defined, and - # returns nil instead of the response if it is successful - # - # @param [String] xml_method xml-rpc method - # @param [Array] args any arguments for the xml-rpc method - # - # @return [nil, OpenNebula::Error] nil in case of success, Error - # otherwise - def call(xml_method, *args) - return Error.new('ID not defined') if !@pe_id - - rc = @client.call(xml_method, *args) - rc = nil if !OpenNebula.is_error?(rc) - - return rc - end - - # Calls to the corresponding info method to retreive the element - # detailed information in XML format - # - # @param [String] xml_method the name of the XML-RPC method - # @param [String] root_element Base XML element name - # @param [Array] args additional arguments - # - # @return [nil, OpenNebula::Error] nil in case of success, Error - # otherwise - def info(xml_method, root_element) - return Error.new('ID not defined') if !@pe_id - - rc = @client.call(xml_method, @pe_id) - - if !OpenNebula.is_error?(rc) - initialize_xml(rc, root_element) - rc = nil - - @pe_id = self['ID'].to_i if self['ID'] - @name = self['NAME'] if self['NAME'] - end - - return rc - end - - # Calls to the corresponding allocate method to create a new element - # in the OpenNebula core - # - # @param [String] xml_method the name of the XML-RPC method - # @param [Array] args any extra arguments for the xml-rpc method - # - # @return [nil, OpenNebula::Error] nil in case of success, Error - # otherwise - def allocate(xml_method, *args) - rc = @client.call(xml_method, *args) - - if !OpenNebula.is_error?(rc) - @pe_id = rc - rc = nil - end - - return rc - end - - # Calls to the corresponding update method to modify - # the object's template - # - # @param [String] xml_method the name of the XML-RPC method - # @param [String] new_template the new template contents - # @param [Array] args any extra arguments for the xml-rpc method - # - # @return [nil, OpenNebula::Error] nil in case of success, Error - # otherwise - def update(xml_method, new_template, *args) - new_template ||= template_xml - - return call(xml_method, @pe_id, new_template, *args) - end - - # Calls to the corresponding delete method to remove this element - # from the OpenNebula core - # - # @param [String] xml_method the name of the XML-RPC method - # - # @return [nil, OpenNebula::Error] nil in case of success, Error - # otherwise - def delete(xml_method) - return call(xml_method,@pe_id) - end - - # Calls to the corresponding chown method to modify - # the object's owner and group - # - # @param [String] xml_method the name of the XML-RPC method - # @param [Integer] uid the new owner id. Set to -1 to leave the current one - # @param [Integer] gid the new goup id. Set to -1 to leave the current one - # - # @return [nil, OpenNebula::Error] nil in case of success, Error - # otherwise - def chown(xml_method, uid, gid) - return call(xml_method, @pe_id, uid, gid) - end - - # Calls to the corresponding chmod method to modify - # the object's permission bits - # - # @param xml_method [String] the name of the XML-RPC method - # @param octet [String] Permissions octed , e.g. 640 - # - # @return [nil, OpenNebula::Error] nil in case of success, Error - # otherwise - def chmod_octet(xml_method, octet) - owner_u = octet[0..0].to_i & 4 != 0 ? 1 : 0 - owner_m = octet[0..0].to_i & 2 != 0 ? 1 : 0 - owner_a = octet[0..0].to_i & 1 != 0 ? 1 : 0 - group_u = octet[1..1].to_i & 4 != 0 ? 1 : 0 - group_m = octet[1..1].to_i & 2 != 0 ? 1 : 0 - group_a = octet[1..1].to_i & 1 != 0 ? 1 : 0 - other_u = octet[2..2].to_i & 4 != 0 ? 1 : 0 - other_m = octet[2..2].to_i & 2 != 0 ? 1 : 0 - other_a = octet[2..2].to_i & 1 != 0 ? 1 : 0 - - chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u, - other_m, other_a) - end - - # Calls to the corresponding chmod method to modify - # the object's permission bits - # Each [Integer] parameter must be 1 to allow, 0 deny, -1 do not change - # - # @param xml_method [String] the name of the XML-RPC method - # - # @return [nil, OpenNebula::Error] nil in case of success, Error - # otherwise - def chmod(xml_method, owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u, - other_m, other_a) - return call(xml_method, @pe_id, owner_u, owner_m, - owner_a, group_u, group_m, group_a, other_u, - other_m, other_a) - end - - - # Retrieves this Element's monitoring data from OpenNebula - # - # @param [String] xml_method the name of the XML-RPC method - # @param [String] root_elem Root for each individual PoolElement - # @param [String] timestamp_elem Name of the XML element with the last - # monitorization timestamp - # @param xpath_expressions [Array] Xpath expressions for the - # elements to retrieve. - # - # @return [Hash>, OpenNebula::Error] Hash with - # the requested xpath expressions, and an Array of [timestamp, value]. - def monitoring(xml_method, root_elem, timestamp_elem, xpath_expressions) - return Error.new('ID not defined') if !@pe_id - - rc = @client.call(xml_method, @pe_id) - - if ( OpenNebula.is_error?(rc) ) - return rc - end - - xmldoc = XMLElement.new - xmldoc.initialize_xml(rc, 'MONITORING_DATA') - - - return OpenNebula.process_monitoring( - xmldoc, root_elem, timestamp_elem, @pe_id, xpath_expressions) - end - - public - - # Creates new element specifying its id - # id:: identifyier of the element - # client:: initialized OpenNebula::Client object - def self.new_with_id(id, client=nil) - self.new(self.build_xml(id), client) - end - - # Returns element identifier - # [return] _Integer_ the PoolElement ID - def id - @pe_id - end - - # Gets element name - # [return] _String_ the PoolElement name - def name - @name - end - - # DO NOT USE - ONLY REXML BACKEND - def to_str - str = "" - REXML::Formatters::Pretty.new(1).write(@xml,str) - - return str - end - end - - # Processes the monitoring data in XML returned by OpenNebula - # - # @param [XMLElement] xmldoc monitoring data returned by OpenNebula - # @param [String] root_elem Root for each individual PoolElement - # @param [String] timestamp_elem Name of the XML element with the last - # monitorization timestamp - # @param [Integer] Id of the object to process - # @param [Array] xpath_expressions Elements to retrieve. - # @param args arguemnts for the xml_method call - # - # @return [Hash>, OpenNebula::Error] Hash with - # the requested xpath expressions, and an Array of [timestamp, value]. - def self.process_monitoring(xmldoc, root_elem, timestamp_elem, oid, xpath_expressions) - hash = {} - timestamps = xmldoc.retrieve_elements( - "#{root_elem}[ID=#{oid}]/#{timestamp_elem}") - - xpath_expressions.each { |xpath| - xpath_values = xmldoc.retrieve_elements("#{root_elem}[ID=#{oid}]/#{xpath}") - - if ( xpath_values.nil? ) - hash[xpath] = [] - else - hash[xpath] = timestamps.zip(xpath_values) - end - } - - return hash - end end diff --git a/src/oca/ruby/opennebula/pool_element.rb b/src/oca/ruby/opennebula/pool_element.rb new file mode 100644 index 0000000000..d7dd3670b2 --- /dev/null +++ b/src/oca/ruby/opennebula/pool_element.rb @@ -0,0 +1,268 @@ +# -------------------------------------------------------------------------- # +# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # + + +module OpenNebula + # The PoolElement Class represents a generic element of a Pool in + # XML format + class PoolElement < XMLElement + + protected + # node:: _XML_is a XML element that represents the Pool element + # client:: _Client_ represents a XML-RPC connection + def initialize(node, client) + @xml = node + @client = client + + if self['ID'] + @pe_id = self['ID'].to_i + else + @pe_id = nil + end + @name = self['NAME'] if self['NAME'] + end + + ####################################################################### + # Common XML-RPC Methods for all the Pool Element Types + ####################################################################### + + # Common client call wrapper. Checks that @pe_id is defined, and + # returns nil instead of the response if it is successful + # + # @param [String] xml_method xml-rpc method + # @param [Array] args any arguments for the xml-rpc method + # + # @return [nil, OpenNebula::Error] nil in case of success, Error + # otherwise + def call(xml_method, *args) + return Error.new('ID not defined') if !@pe_id + + rc = @client.call(xml_method, *args) + rc = nil if !OpenNebula.is_error?(rc) + + return rc + end + + # Calls to the corresponding info method to retreive the element + # detailed information in XML format + # + # @param [String] xml_method the name of the XML-RPC method + # @param [String] root_element Base XML element name + # @param [Array] args additional arguments + # + # @return [nil, OpenNebula::Error] nil in case of success, Error + # otherwise + def info(xml_method, root_element) + return Error.new('ID not defined') if !@pe_id + + rc = @client.call(xml_method, @pe_id) + + if !OpenNebula.is_error?(rc) + initialize_xml(rc, root_element) + rc = nil + + @pe_id = self['ID'].to_i if self['ID'] + @name = self['NAME'] if self['NAME'] + end + + return rc + end + + # Calls to the corresponding allocate method to create a new element + # in the OpenNebula core + # + # @param [String] xml_method the name of the XML-RPC method + # @param [Array] args any extra arguments for the xml-rpc method + # + # @return [nil, OpenNebula::Error] nil in case of success, Error + # otherwise + def allocate(xml_method, *args) + rc = @client.call(xml_method, *args) + + if !OpenNebula.is_error?(rc) + @pe_id = rc + rc = nil + end + + return rc + end + + # Calls to the corresponding update method to modify + # the object's template + # + # @param [String] xml_method the name of the XML-RPC method + # @param [String] new_template the new template contents + # @param [Array] args any extra arguments for the xml-rpc method + # + # @return [nil, OpenNebula::Error] nil in case of success, Error + # otherwise + def update(xml_method, new_template, *args) + new_template ||= template_xml + + return call(xml_method, @pe_id, new_template, *args) + end + + # Calls to the corresponding delete method to remove this element + # from the OpenNebula core + # + # @param [String] xml_method the name of the XML-RPC method + # + # @return [nil, OpenNebula::Error] nil in case of success, Error + # otherwise + def delete(xml_method) + return call(xml_method,@pe_id) + end + + # Calls to the corresponding chown method to modify + # the object's owner and group + # + # @param [String] xml_method the name of the XML-RPC method + # @param [Integer] uid the new owner id. Set to -1 to leave the current one + # @param [Integer] gid the new goup id. Set to -1 to leave the current one + # + # @return [nil, OpenNebula::Error] nil in case of success, Error + # otherwise + def chown(xml_method, uid, gid) + return call(xml_method, @pe_id, uid, gid) + end + + # Calls to the corresponding chmod method to modify + # the object's permission bits + # + # @param xml_method [String] the name of the XML-RPC method + # @param octet [String] Permissions octed , e.g. 640 + # + # @return [nil, OpenNebula::Error] nil in case of success, Error + # otherwise + def chmod_octet(xml_method, octet) + owner_u = octet[0..0].to_i & 4 != 0 ? 1 : 0 + owner_m = octet[0..0].to_i & 2 != 0 ? 1 : 0 + owner_a = octet[0..0].to_i & 1 != 0 ? 1 : 0 + group_u = octet[1..1].to_i & 4 != 0 ? 1 : 0 + group_m = octet[1..1].to_i & 2 != 0 ? 1 : 0 + group_a = octet[1..1].to_i & 1 != 0 ? 1 : 0 + other_u = octet[2..2].to_i & 4 != 0 ? 1 : 0 + other_m = octet[2..2].to_i & 2 != 0 ? 1 : 0 + other_a = octet[2..2].to_i & 1 != 0 ? 1 : 0 + + chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u, + other_m, other_a) + end + + # Calls to the corresponding chmod method to modify + # the object's permission bits + # Each [Integer] parameter must be 1 to allow, 0 deny, -1 do not change + # + # @param xml_method [String] the name of the XML-RPC method + # + # @return [nil, OpenNebula::Error] nil in case of success, Error + # otherwise + def chmod(xml_method, owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u, + other_m, other_a) + return call(xml_method, @pe_id, owner_u, owner_m, + owner_a, group_u, group_m, group_a, other_u, + other_m, other_a) + end + + + # Retrieves this Element's monitoring data from OpenNebula + # + # @param [String] xml_method the name of the XML-RPC method + # @param [String] root_elem Root for each individual PoolElement + # @param [String] timestamp_elem Name of the XML element with the last + # monitorization timestamp + # @param xpath_expressions [Array] Xpath expressions for the + # elements to retrieve. + # + # @return [Hash>, OpenNebula::Error] Hash with + # the requested xpath expressions, and an Array of [timestamp, value]. + def monitoring(xml_method, root_elem, timestamp_elem, xpath_expressions) + return Error.new('ID not defined') if !@pe_id + + rc = @client.call(xml_method, @pe_id) + + if ( OpenNebula.is_error?(rc) ) + return rc + end + + xmldoc = XMLElement.new + xmldoc.initialize_xml(rc, 'MONITORING_DATA') + + + return OpenNebula.process_monitoring( + xmldoc, root_elem, timestamp_elem, @pe_id, xpath_expressions) + end + + public + + # Creates new element specifying its id + # id:: identifyier of the element + # client:: initialized OpenNebula::Client object + def self.new_with_id(id, client=nil) + self.new(self.build_xml(id), client) + end + + # Returns element identifier + # [return] _Integer_ the PoolElement ID + def id + @pe_id + end + + # Gets element name + # [return] _String_ the PoolElement name + def name + @name + end + + # DO NOT USE - ONLY REXML BACKEND + def to_str + str = "" + REXML::Formatters::Pretty.new(1).write(@xml,str) + + return str + end + end + + # Processes the monitoring data in XML returned by OpenNebula + # + # @param [XMLElement] xmldoc monitoring data returned by OpenNebula + # @param [String] root_elem Root for each individual PoolElement + # @param [String] timestamp_elem Name of the XML element with the last + # monitorization timestamp + # @param [Integer] Id of the object to process + # @param [Array] xpath_expressions Elements to retrieve. + # @param args arguemnts for the xml_method call + # + # @return [Hash>, OpenNebula::Error] Hash with + # the requested xpath expressions, and an Array of [timestamp, value]. + def self.process_monitoring(xmldoc, root_elem, timestamp_elem, oid, xpath_expressions) + hash = {} + timestamps = xmldoc.retrieve_elements( + "#{root_elem}[ID=#{oid}]/#{timestamp_elem}") + + xpath_expressions.each { |xpath| + xpath_values = xmldoc.retrieve_elements("#{root_elem}[ID=#{oid}]/#{xpath}") + + if ( xpath_values.nil? ) + hash[xpath] = [] + else + hash[xpath] = timestamps.zip(xpath_values) + end + } + + return hash + end +end diff --git a/src/oca/ruby/opennebula/xml_element.rb b/src/oca/ruby/opennebula/xml_element.rb new file mode 100644 index 0000000000..0d4f966e84 --- /dev/null +++ b/src/oca/ruby/opennebula/xml_element.rb @@ -0,0 +1,427 @@ +# -------------------------------------------------------------------------- # +# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # + + +module OpenNebula + # 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 + def initialize(xml=nil) + @xml = xml + end + + # Initialize a XML document for the element + # xml:: _String_ the XML document of the object + # root_element:: _String_ Base xml element + def initialize_xml(xml, root_element) + @xml = XMLElement.build_xml(xml, root_element) + + if OpenNebula.is_error?(@xml) + @xml = nil + else + if NOKOGIRI + if @xml.size == 0 + @xml = nil + end + else + if @xml.name != root_element + @xml = nil + end + end + end + end + + # Builds a XML document + # xml:: _String_ the XML document of the object + # root_element:: _String_ Base xml element + # [return] _XML_ object for the underlying XML engine + def self.build_xml(xml, root_element) + begin + if NOKOGIRI + doc = Nokogiri::XML(xml).xpath("/#{root_element}") + else + doc = REXML::Document.new(xml).root + end + rescue Exception => e + return OpenNebula::Error.new(e.message) + end + + return doc + end + + # Extract a text element from the XML description of the PoolElement. + # + # @param [String] key Xpath expression + # + # @return [String, nil] If a text element is found, the element's + # text value. Otherwise, an empty string or nil, depending + # on the backend + # + # @example + # vm['VID'] # gets VM id + # vm['HISTORY/HOSTNAME'] # get the hostname from the history + def [](key) + if NOKOGIRI + element=@xml.xpath(key.to_s) + + return nil if element.size == 0 + else + element=@xml.elements[key.to_s] + + return "" if element && !element.has_text? + end + + element.text if element + end + + # Delete an element from the xml + # xpath::_String_ xpath expression that selects the elemnts to be deleted + def delete_element(xpath) + if NOKOGIRI + @xml.xpath(xpath.to_s).remove + else + @xml.delete_element(xpath.to_s) + end + end + + # Add a new element to the xml + # xpath::_String_ xpath xpression where the elemente will be added + # elems::_Hash_ Hash containing the pairs key-value to be included + # Examples: + # add_element('VM', 'NEW_ITEM' => 'NEW_VALUE') + # NEW_VALUE... + # + # add_element('VM/TEMPLATE', 'V1' => {'X1' => 'A1', 'Y2' => 'A2'}) + # + def add_element(xpath, elems) + elems.each { |key, value| + if value.instance_of?(Hash) + if NOKOGIRI + elem = Nokogiri::XML::Node.new key, @xml.document + value.each { |k2, v2| + child = Nokogiri::XML::Node.new k2, elem + child.content = v2 + elem.add_child(child) + } + @xml.xpath(xpath.to_s).first.add_child(elem) + else + elem = REXML::Element.new(key) + value.each { |k2, v2| + elem.add_element(k2).text = v2 + } + @xml.elements[xpath].add_element(elem) + end + else + if NOKOGIRI + elem = Nokogiri::XML::Node.new key, @xml.document + elem.content = value + @xml.xpath(xpath.to_s).first.add_child(elem) + else + @xml.elements[xpath].add_element(key).text = value + end + end + } + end + + # Gets an array of text from elemenets extracted + # using the XPATH expression passed as filter + def retrieve_elements(filter) + elements_array = Array.new + + if NOKOGIRI + @xml.xpath(filter.to_s).each { |pelem| + elements_array << pelem.text if pelem.text + } + else + @xml.elements.each(filter.to_s) { |pelem| + elements_array << pelem.text if pelem.text + } + end + + if elements_array.size == 0 + return nil + else + return elements_array + end + + end + + # Gets an attribute from an elemenT + # key:: _String_ xpath for the element + # name:: _String_ name of the attribute + def attr(key,name) + value = nil + + if NOKOGIRI + element=@xml.xpath(key.to_s.upcase) + if element.size == 0 + return nil + end + + attribute = element.attr(name) + + value = attribute.text if attribute != nil + else + element=@xml.elements[key.to_s.upcase] + + value = element.attributes[name] if element != nil + end + + return value + end + + # Iterates over every Element in the XPath and calls the block with a + # a XMLElement + # block:: _Block_ + def each(xpath_str,&block) + if NOKOGIRI + @xml.xpath(xpath_str).each { |pelem| + block.call XMLElement.new(pelem) + } + else + @xml.elements.each(xpath_str) { |pelem| + block.call XMLElement.new(pelem) + } + end + end + + def each_xpath(xpath_str,&block) + if NOKOGIRI + @xml.xpath(xpath_str).each { |pelem| + block.call pelem.text + } + else + @xml.elements.each(xpath_str) { |pelem| + block.call pelem.text + } + end + end + + def name + @xml.name + end + + def text + if NOKOGIRI + @xml.content + else + @xml.text + end + end + + # Returns wheter there are elements for a given XPath + # xpath_str:: _String_ XPath expression to locate the element + def has_elements?(xpath_str) + if NOKOGIRI + element = @xml.xpath(xpath_str.to_s.upcase) + return element != nil && element.children.size > 0 + else + element = @xml.elements[xpath_str.to_s] + return element != nil && element.has_elements? + end + end + + # Returns the