Enable tags query over the query socket
authorIustin Pop <iustin@google.com>
Sun, 19 Aug 2012 00:13:43 +0000 (02:13 +0200)
committerIustin Pop <iustin@google.com>
Tue, 28 Aug 2012 15:02:50 +0000 (17:02 +0200)
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 <iustin@google.com>
Reviewed-by: Agata Murawska <agatamurawska@google.com>

htools/Ganeti/HTools/QC.hs
htools/Ganeti/Objects.hs
htools/Ganeti/Queryd.hs
lib/cli.py
lib/rapi/rlib2.py

index 2410bdb..611d74d 100644 (file)
@@ -57,6 +57,7 @@ import Test.QuickCheck.Monadic (assert, monadicIO, run, stop)
 import Text.Printf (printf)
 import Data.List (intercalate, nub, isPrefixOf)
 import Data.Maybe
+import qualified Data.Set as Set
 import Control.Monad
 import Control.Applicative
 import qualified System.Console.GetOpt as GetOpt
@@ -548,6 +549,7 @@ instance Arbitrary Objects.Node where
               <*> arbitrary <*> arbitrary <*> arbitrary <*> getFQDN
               <*> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary
               <*> arbitrary <*> arbitrary <*> getFQDN <*> arbitrary
+              <*> (Set.fromList <$> genTags)
 
 instance Arbitrary Rpc.RpcCallAllInstancesInfo where
   arbitrary = Rpc.RpcCallAllInstancesInfo <$> arbitrary
index 380524c..75e1d6b 100644 (file)
@@ -293,7 +293,8 @@ $(buildObject "Instance" "inst" $
   ]
   ++ timeStampFields
   ++ uuidFields
-  ++ serialFields)
+  ++ serialFields
+  ++ tagsFields)
 
 -- * IPolicy definitions
 
@@ -374,7 +375,8 @@ $(buildObject "Node" "node" $
   ]
   ++ timeStampFields
   ++ uuidFields
-  ++ serialFields)
+  ++ serialFields
+  ++ tagsFields)
 
 -- * NodeGroup definitions
 
@@ -402,7 +404,8 @@ $(buildObject "NodeGroup" "group" $
   ]
   ++ timeStampFields
   ++ uuidFields
-  ++ serialFields)
+  ++ serialFields
+  ++ tagsFields)
 
 -- | IP family type
 $(declareIADT "IpFamily"
index 4f265bd..1ac44fc 100644 (file)
@@ -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"
 
index 44d854d..845c8a7 100644 (file)
@@ -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()
index addb938..4259a6e 100644 (file)
@@ -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: