From 38ad6cebebbbf2149be67ecfaa7eaec01ff9d27e Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Thu, 10 Oct 2013 13:07:33 +0200 Subject: [PATCH] feature #2092: Make use of hybrid hypervisor instead of attribute --- include/Host.h | 15 ++++++++++++++- include/VirtualMachineTemplate.h | 11 +++++++---- src/vm/VirtualMachine.cc | 8 ++------ src/vm/VirtualMachineTemplate.cc | 5 +++-- 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/include/Host.h b/include/Host.h index 29e7d40e6c..2ca409d055 100644 --- a/include/Host.h +++ b/include/Host.h @@ -92,6 +92,15 @@ public: */ bool isHybrid() const; + /** + * Return an element of the hypervisor array. The calling function + * must check that the index is valid. + */ + static const char * get_hybrid_hypervisor_by_id(int i) + { + return HYBRID_HYPERVISORS[i]; + } + /** * Disables the current host, it will not be monitored nor used by the * scheduler @@ -498,7 +507,11 @@ private: static const char * monit_table; /** - * Array containing the hybrid hypervisors, and counter + * Array containing the hybrid hypervisors, and counter. There is a + * correspondence between Host::HYBRID_HYPERVISOR and + * VirtualMachine::HYBRID_ATTRIBUTES. Attributes in HYBRID_ATTRIBUTES[i] are + * meant to be used in hosts reporting a a hypervisor of type + * HYBRID_HYPERVISOR[i] */ static const char * HYBRID_HYPERVISORS[]; diff --git a/include/VirtualMachineTemplate.h b/include/VirtualMachineTemplate.h index 1d14ccc7e1..a30132e78e 100644 --- a/include/VirtualMachineTemplate.h +++ b/include/VirtualMachineTemplate.h @@ -68,9 +68,9 @@ public: void remove_all_except_restricted(); /** - * Returns a copy of the VirtualMachineTemplate + * Returns the hypervisor name if the template is hybrid * @param hypervisor the resulting hypervisor string - * @return true if any hybrid hypervisor found, false otherwise + * @return true if any hybrid hypervisor attribute found, false otherwise */ bool get_hybrid_hypervisor(string& hypervisor) const; @@ -80,9 +80,12 @@ private: static vector restricted_attributes; - /** - * Array containing the hybrid attributes, and counter + * Array containing the hybrid attributes, and counter. There is a + * correspondence between Host::HYBRID_HYPERVISOR and + * VirtualMachine::HYBRID_ATTRIBUTES. Attributes in HYBRID_ATTRIBUTES[i] are + * meant to be used in hosts reporting a a hypervisor of type + * HYBRID_HYPERVISOR[i] */ static const char * HYBRID_ATTRIBUTES[]; diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 833bf953d3..f84011c1e8 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -251,7 +251,7 @@ int VirtualMachine::insert(SqlDB * db, string& error_str) string value; int ivalue; float fvalue; - + ostringstream oss; // ------------------------------------------------------------------------ @@ -1144,16 +1144,12 @@ int VirtualMachine::automatic_requirements(string& error_str) } } - static_cast(obj_template)->get_hybrid_hypervisor( - hypervisor); - oss.str(""); - if ( !cluster_id.empty() ) { oss << "CLUSTER_ID = " << cluster_id; } - if ( !hypervisor.empty() ) + if (static_cast(obj_template)->get_hybrid_hypervisor(hypervisor)) { if ( !cluster_id.empty() ) { diff --git a/src/vm/VirtualMachineTemplate.cc b/src/vm/VirtualMachineTemplate.cc index b18d177800..6504727a17 100644 --- a/src/vm/VirtualMachineTemplate.cc +++ b/src/vm/VirtualMachineTemplate.cc @@ -15,6 +15,7 @@ /* -------------------------------------------------------------------------- */ #include "VirtualMachineTemplate.h" +#include "Host.h" /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ @@ -151,10 +152,10 @@ bool VirtualMachineTemplate::get_hybrid_hypervisor(string& hypervisor) const bool found_it = false; for(int i=0; i < NUM_HYBRID_ATTRIBUTES; i++) - { + { if(get(HYBRID_ATTRIBUTES[i],attrs)) { - hypervisor = HYBRID_ATTRIBUTES[i]; + hypervisor = Host::get_hybrid_hypervisor_by_id(i); found_it = true; break; }