From ea017cbc60cbdcfe2797f47902c12c67b58bd741 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Tue, 1 Dec 2009 10:53:58 +0100
Subject: [PATCH] Read cluster tags in the RAPI backend

This also shows them in hbal in verbose mode.
---
 Ganeti/HTools/Rapi.hs | 6 ++++--
 hbal.hs               | 5 ++++-
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/Ganeti/HTools/Rapi.hs b/Ganeti/HTools/Rapi.hs
index 261b29095..3f6069907 100644
--- a/Ganeti/HTools/Rapi.hs
+++ b/Ganeti/HTools/Rapi.hs
@@ -33,7 +33,7 @@ import Network.Curl.Types ()
 import Network.Curl.Code
 import Data.List
 import Control.Monad
-import Text.JSON (JSObject, JSValue, fromJSObject)
+import Text.JSON (JSObject, JSValue, fromJSObject, decodeStrict)
 import Text.Printf (printf)
 
 import Ganeti.HTools.Utils
@@ -119,9 +119,11 @@ loadData master = do -- IO monad
   let url = formatHost master
   node_body <- getUrl $ printf "%s/2/nodes?bulk=1" url
   inst_body <- getUrl $ printf "%s/2/instances?bulk=1" url
+  tags_body <- getUrl $ printf "%s/2/tags" url
   return $ do -- Result monad
     node_data <- node_body >>= getNodes
     let (node_names, node_idx) = assignIndices node_data
     inst_data <- inst_body >>= getInstances node_names
     let (_, inst_idx) = assignIndices inst_data
-    return (node_idx, inst_idx, [])
+    tags_data <- tags_body >>= (fromJResult . decodeStrict)
+    return (node_idx, inst_idx, tags_data)
diff --git a/hbal.hs b/hbal.hs
index 51ca704c4..1c3f9fe49 100644
--- a/hbal.hs
+++ b/hbal.hs
@@ -187,7 +187,7 @@ main = do
       verbose = optVerbose opts
       shownodes = optShowNodes opts
 
-  (fixed_nl, il, _, csf) <- loadExternalData opts
+  (fixed_nl, il, ctags, csf) <- loadExternalData opts
 
   let offline_names = optOffline opts
       all_nodes = Container.elems fixed_nl
@@ -210,6 +210,9 @@ main = do
       nl = Container.map (flip Node.setMdsk m_dsk . flip Node.setMcpu m_cpu)
            nm
 
+  when (not oneline && verbose > 1) $
+       putStrLn $ "Loaded cluster tags: " ++ intercalate "," ctags
+
   when (Container.size il == 0) $ do
          (if oneline then putStrLn $ formatOneline 0 0 0
           else printf "Cluster is empty, exiting.\n")
-- 
GitLab