From 0ec87781ca26da7795966e376e95e4fd17244501 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Thu, 4 Oct 2012 03:09:57 +0100
Subject: [PATCH] Fixup hypervisor queries in node query
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

We need to only query the default (first enabled) hypervisor, not all
hypervisors. For this, we need to add a manual check to ensure that we
don't have a corrupt config (there's no "NonEmptyList" type…).

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>
---
 htools/Ganeti/Config.hs      | 11 +++++++++++
 htools/Ganeti/Query/Query.hs |  3 ++-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/htools/Ganeti/Config.hs b/htools/Ganeti/Config.hs
index f88ba8a68..55cb492cf 100644
--- a/htools/Ganeti/Config.hs
+++ b/htools/Ganeti/Config.hs
@@ -31,6 +31,7 @@ module Ganeti.Config
     , getNodeRole
     , getNodeNdParams
     , getDefaultNicLink
+    , getDefaultHypervisor
     , getInstancesIpByLink
     , getNode
     , getInstance
@@ -126,6 +127,16 @@ getDefaultNicLink =
   nicpLink . (M.! C.ppDefault) . fromContainer .
   clusterNicparams . configCluster
 
+-- | Returns the default cluster hypervisor.
+getDefaultHypervisor :: ConfigData -> Hypervisor
+getDefaultHypervisor cfg =
+  case clusterEnabledHypervisors $ configCluster cfg of
+    -- FIXME: this case shouldn't happen (configuration broken), but
+    -- for now we handle it here because we're not authoritative for
+    -- the config
+    []  -> XenPvm
+    x:_ -> x
+
 -- | Returns instances of a given link.
 getInstancesIpByLink :: LinkIpMap -> String -> [String]
 getInstancesIpByLink linkipmap link =
diff --git a/htools/Ganeti/Query/Query.hs b/htools/Ganeti/Query/Query.hs
index a42cde6a7..7a172ff93 100644
--- a/htools/Ganeti/Query/Query.hs
+++ b/htools/Ganeti/Query/Query.hs
@@ -56,6 +56,7 @@ import Data.Maybe (fromMaybe)
 import qualified Data.Map as Map
 
 import Ganeti.BasicTypes
+import Ganeti.Config
 import Ganeti.JSON
 import Ganeti.Rpc
 import Ganeti.Query.Language
@@ -103,7 +104,7 @@ maybeCollectLiveData False _ nodes =
 
 maybeCollectLiveData True cfg nodes = do
   let vgs = [clusterVolumeGroupName $ configCluster cfg]
-      hvs = clusterEnabledHypervisors $ configCluster cfg
+      hvs = [getDefaultHypervisor cfg]
   executeRpcCall nodes (RpcCallNodeInfo vgs hvs)
 
 -- | Check whether list of queried fields contains live fields.
-- 
GitLab