From f23740602ddc9e3f62b92849eef3ba804fc19c7b Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Sun, 19 Aug 2012 02:13:43 +0200 Subject: [PATCH] Enable tags query over the query socket 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 | 2 ++ htools/Ganeti/Objects.hs | 9 ++++++--- htools/Ganeti/Queryd.hs | 11 ++++++++++- lib/cli.py | 2 +- lib/rapi/rlib2.py | 2 +- 5 files changed, 20 insertions(+), 6 deletions(-) diff --git a/htools/Ganeti/HTools/QC.hs b/htools/Ganeti/HTools/QC.hs index 2410bdbbe..611d74dcd 100644 --- a/htools/Ganeti/HTools/QC.hs +++ b/htools/Ganeti/HTools/QC.hs @@ -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 diff --git a/htools/Ganeti/Objects.hs b/htools/Ganeti/Objects.hs index 380524c03..75e1d6bb7 100644 --- a/htools/Ganeti/Objects.hs +++ b/htools/Ganeti/Objects.hs @@ -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" diff --git a/htools/Ganeti/Queryd.hs b/htools/Ganeti/Queryd.hs index 4f265bdfb..1ac44fc16 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 44d854dd4..845c8a7bc 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 addb938c1..4259a6e34 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: -- GitLab