From be747966e9fc5094338ae05c58b160f57b095419 Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Sun, 19 Aug 2012 01:31:32 +0200 Subject: [PATCH] Change the Luxi tags kind from String to a custom type This will allow safer code when we implement the tags query. Signed-off-by: Iustin Pop <iustin@google.com> Reviewed-by: Agata Murawska <agatamurawska@google.com> --- htools/Ganeti/HTools/QC.hs | 5 ++++- htools/Ganeti/Luxi.hs | 12 +++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/htools/Ganeti/HTools/QC.hs b/htools/Ganeti/HTools/QC.hs index 8705ad164..2410bdbbe 100644 --- a/htools/Ganeti/HTools/QC.hs +++ b/htools/Ganeti/HTools/QC.hs @@ -1847,6 +1847,9 @@ testSuite "JSON" -- * Luxi tests +instance Arbitrary Luxi.TagObject where + arbitrary = elements [minBound..maxBound] + instance Arbitrary Luxi.LuxiReq where arbitrary = elements [minBound..maxBound] @@ -1866,7 +1869,7 @@ instance Arbitrary Luxi.LuxiOp where (listOf getFQDN) <*> arbitrary Luxi.ReqQueryConfigValues -> Luxi.QueryConfigValues <$> getFields Luxi.ReqQueryClusterInfo -> pure Luxi.QueryClusterInfo - Luxi.ReqQueryTags -> Luxi.QueryTags <$> getName <*> getFQDN + Luxi.ReqQueryTags -> Luxi.QueryTags <$> arbitrary <*> getFQDN Luxi.ReqSubmitJob -> Luxi.SubmitJob <$> (resize maxOpCodes arbitrary) Luxi.ReqSubmitManyJobs -> Luxi.SubmitManyJobs <$> (resize maxOpCodes arbitrary) diff --git a/htools/Ganeti/Luxi.hs b/htools/Ganeti/Luxi.hs index 939302c23..0ac40e792 100644 --- a/htools/Ganeti/Luxi.hs +++ b/htools/Ganeti/Luxi.hs @@ -32,6 +32,7 @@ module Ganeti.Luxi , Client , JobId , RecvResult(..) + , TagObject(..) , strOfOp , checkRS , getClient @@ -99,6 +100,15 @@ data RecvResult = RecvConnClosed -- ^ Connection closed -- | The Ganeti job type. type JobId = Int +-- | Data type representing what items do the tag operations apply to. +$(declareSADT "TagObject" + [ ("TagInstance", 'tagInstance) + , ("TagNode", 'tagNode) + , ("TagGroup", 'tagNodegroup) + , ("TagCluster", 'tagCluster) + ]) +$(makeJSONInstance ''TagObject) + -- | Currently supported Luxi operations and JSON serialization. $(genLuxiOp "LuxiOp" [(luxiReqQuery, @@ -134,7 +144,7 @@ $(genLuxiOp "LuxiOp" ) , (luxiReqQueryClusterInfo, []) , (luxiReqQueryTags, - [ ("kind", [t| String |]) + [ ("kind", [t| TagObject |]) , ("name", [t| String |]) ]) , (luxiReqSubmitJob, -- GitLab