From 637f1dbbd22c504d7de702438bbf996d1d1cc08f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Wed, 20 Nov 2013 17:02:12 +0100 Subject: [PATCH] Feature #2435 #2092: New generic HYBRID section in VMs, better automatic_requirements --- include/VirtualMachine.h | 16 +++++++++ src/host/Host.cc | 13 +------ src/vm/VirtualMachine.cc | 78 ++++++++++++++++++++++++++++++++++------ 3 files changed, 85 insertions(+), 22 deletions(-) diff --git a/include/VirtualMachine.h b/include/VirtualMachine.h index c137fd75a6..0960b8c2ab 100644 --- a/include/VirtualMachine.h +++ b/include/VirtualMachine.h @@ -1388,6 +1388,22 @@ public: */ void delete_snapshots(); + // ------------------------------------------------------------------------ + // Hybrid templates related functions + // ------------------------------------------------------------------------ + + /** + * Checks if the VM is hybrid + * @return true if the VM is hybrid + */ + bool is_hybrid() const; + + /** + * Gets the list of hybrid hypervisors for which this VM has definitions + * @return the list of hybrid hypervisors + */ + vector get_hybrid_hypervisors() const; + private: // ------------------------------------------------------------------------- diff --git a/src/host/Host.cc b/src/host/Host.cc index f84f3bc2d0..8f0231d335 100644 --- a/src/host/Host.cc +++ b/src/host/Host.cc @@ -540,20 +540,9 @@ error_common: bool Host::isHybrid() const { - string hypervisor; bool is_hybrid = false; - get_template_attribute("HYPERVISOR", hypervisor); - one_util::toupper(hypervisor); - - for(int i=0; i < NUM_HYBRID_HYPERVISORS; i++) - { - if(hypervisor==HYBRID_HYPERVISORS[i]) - { - is_hybrid = true; - break; - } - } + get_template_attribute("HYBRID", is_hybrid); return is_hybrid; } diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index da2b0593fc..808016f061 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -1129,7 +1129,8 @@ int VirtualMachine::automatic_requirements(string& error_str) ostringstream oss; string requirements; string cluster_id = ""; - string hypervisor; + + vector hybrid_hypervisors = get_hybrid_hypervisors(); int incomp_id; int rc; @@ -1208,23 +1209,28 @@ int VirtualMachine::automatic_requirements(string& error_str) if ( !cluster_id.empty() ) { - oss << "CLUSTER_ID = " << cluster_id; + oss << "CLUSTER_ID = " << cluster_id << " & !(HYBRID = YES)"; + } + else + { + oss << "!(HYBRID = YES)"; } - if (static_cast(obj_template)->get_hybrid_hypervisor(hypervisor)) + if (!hybrid_hypervisors.empty()) { - if ( !cluster_id.empty() ) + oss << " | (HYBRID = YES & ("; + + oss << "HYPERVISOR = " << hybrid_hypervisors[0]; + + for (size_t i = 1; i < hybrid_hypervisors.size(); i++) { - oss << " || "; + oss << " | HYPERVISOR = " << hybrid_hypervisors[i]; } - oss << "HYPERVISOR = " << hypervisor; + oss << "))"; } - if ( !cluster_id.empty() || !hypervisor.empty() ) - { - obj_template->add("AUTOMATIC_REQUIREMENTS", oss.str()); - } + obj_template->add("AUTOMATIC_REQUIREMENTS", oss.str()); return 0; @@ -3656,3 +3662,55 @@ void VirtualMachine::clear_template_monitor_error() { user_obj_template->erase("ERROR_MONITOR"); } + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +bool VirtualMachine::is_hybrid() const +{ + vector v = get_hybrid_hypervisors(); + + return (v.size() > 0); +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +vector VirtualMachine::get_hybrid_hypervisors() const +{ + vector attrs; + vector::const_iterator it; + + VectorAttribute * vatt; + vector hybrid_hypervisors; + + user_obj_template->get("HYBRID", attrs); + + for (it = attrs.begin(); it != attrs.end(); it++) + { + vatt = dynamic_cast(*it); + + if ( vatt == 0 ) + { + continue; + } + + string type = vatt->vector_value("TYPE"); + + if (!type.empty()) + { + hybrid_hypervisors.push_back(type); + } + } + + // Compatibility with old templates + + user_obj_template->get("EC2", attrs); + + if (!attrs.empty()) + { + hybrid_hypervisors.push_back("ec2"); + } + + return hybrid_hypervisors; +}