This patch adds the tags field to the objects which were missing it
(all except Cluster), implements handling the LuxiCall QueryTags, and
then enables the use of the query socket in cli.ListTags, used by all
commands, and in the RAPI client.

Signed-off-by: Iustin Pop <[email protected]>
---
 htools/Ganeti/Objects.hs |    9 ++++++---
 htools/Ganeti/Queryd.hs  |   11 ++++++++++-
 lib/cli.py               |    2 +-
 lib/rapi/rlib2.py        |    2 +-
 4 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/htools/Ganeti/Objects.hs b/htools/Ganeti/Objects.hs
index 8da960f..c23707e 100644
--- a/htools/Ganeti/Objects.hs
+++ b/htools/Ganeti/Objects.hs
@@ -277,7 +277,8 @@ $(buildObject "Instance" "inst" $
   ]
   ++ timeStampFields
   ++ uuidFields
-  ++ serialFields)
+  ++ serialFields
+  ++ tagsFields)
 
 -- * IPolicy definitions
 
@@ -358,7 +359,8 @@ $(buildObject "Node" "node" $
   ]
   ++ timeStampFields
   ++ uuidFields
-  ++ serialFields)
+  ++ serialFields
+  ++ tagsFields)
 
 -- * NodeGroup definitions
 
@@ -386,7 +388,8 @@ $(buildObject "NodeGroup" "group" $
   ]
   ++ timeStampFields
   ++ uuidFields
-  ++ serialFields)
+  ++ serialFields
+  ++ tagsFields)
 
 -- | IP family type
 $(declareIADT "IpFamily"
diff --git a/htools/Ganeti/Queryd.hs b/htools/Ganeti/Queryd.hs
index 4f265bd..1ac44fc 100644
--- a/htools/Ganeti/Queryd.hs
+++ b/htools/Ganeti/Queryd.hs
@@ -29,6 +29,7 @@ module Ganeti.Queryd
 
 where
 
+import Control.Applicative
 import Control.Concurrent
 import Control.Exception
 import Data.Bits (bitSize)
@@ -41,7 +42,7 @@ import System.Info (arch)
 
 import qualified Ganeti.Constants as C
 import Ganeti.Objects
---import Ganeti.Config
+import qualified Ganeti.Config as Config
 import Ganeti.BasicTypes
 import Ganeti.Logging
 import Ganeti.Luxi
@@ -118,6 +119,14 @@ handleCall cdata QueryClusterInfo =
 
   in return . Ok . J.makeObj $ obj
 
+handleCall cfg (QueryTags kind name) =
+  let tags = case kind of
+               TagCluster -> Ok . clusterTags $ configCluster cfg
+               TagGroup -> groupTags <$> Config.getGroup cfg name
+               TagNode -> nodeTags <$> Config.getNode cfg name
+               TagInstance -> instTags <$> Config.getInstance cfg name
+  in return (J.showJSON <$> tags)
+
 handleCall _ op =
   return . Bad $ "Luxi call '" ++ strOfOp op ++ "' not implemented"
 
diff --git a/lib/cli.py b/lib/cli.py
index a9c5c9b..22006dc 100644
--- a/lib/cli.py
+++ b/lib/cli.py
@@ -464,7 +464,7 @@ def ListTags(opts, args):
 
   """
   kind, name = _ExtractTagsObject(opts, args)
-  cl = GetClient()
+  cl = GetClient(query=True)
   result = cl.QueryTags(kind, name)
   result = list(result)
   result.sort()
diff --git a/lib/rapi/rlib2.py b/lib/rapi/rlib2.py
index addb938..4259a6e 100644
--- a/lib/rapi/rlib2.py
+++ b/lib/rapi/rlib2.py
@@ -1339,7 +1339,7 @@ class _R_Tags(baserlib.OpcodeResource):
       if not self.name:
         raise http.HttpBadRequest("Missing name on tag request")
 
-      cl = self.GetClient()
+      cl = self.GetClient(query=True)
       tags = list(cl.QueryTags(kind, self.name))
 
     elif kind == constants.TAG_CLUSTER:
-- 
1.7.7.3

Reply via email to