From a451dae2eb3dcf95c40f233a10eef98cfbc5f5ab Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Fri, 23 Nov 2012 17:44:30 +0100
Subject: [PATCH] Complete the Tag opcodes and fix OpTestDelay missing param

The regexp in OpTagsSearch is loaded as is, without testing for
validity; the rest of the patch is trivial.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Helga Velroyen <helgav@google.com>
---
 htest/Test/Ganeti/OpCodes.hs |  6 +++++-
 htools/Ganeti/OpCodes.hs     |  7 +++++++
 htools/Ganeti/OpParams.hs    | 15 +++++++++++++++
 3 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/htest/Test/Ganeti/OpCodes.hs b/htest/Test/Ganeti/OpCodes.hs
index c690b07d5..61ffd4abe 100644
--- a/htest/Test/Ganeti/OpCodes.hs
+++ b/htest/Test/Ganeti/OpCodes.hs
@@ -105,7 +105,7 @@ instance Arbitrary OpCodes.OpCode where
     case op_id of
       "OP_TEST_DELAY" ->
         OpCodes.OpTestDelay <$> arbitrary <*> arbitrary
-                 <*> genNodeNames
+                 <*> genNodeNames <*> arbitrary
       "OP_INSTANCE_REPLACE_DISKS" ->
         OpCodes.OpInstanceReplaceDisks <$> getFQDN <*>
           getMaybe genNodeNameNE <*> arbitrary <*> genDiskIndices <*>
@@ -116,6 +116,10 @@ instance Arbitrary OpCodes.OpCode where
       "OP_INSTANCE_MIGRATE" ->
         OpCodes.OpInstanceMigrate <$> getFQDN <*> arbitrary <*>
           arbitrary <*> arbitrary <*> getMaybe genNodeNameNE
+      "OP_TAGS_GET" ->
+        OpCodes.OpTagsGet <$> arbitrary <*> arbitrary
+      "OP_TAGS_SEARCH" ->
+        OpCodes.OpTagsSearch <$> genNameNE
       "OP_TAGS_SET" ->
         OpCodes.OpTagsSet <$> arbitrary <*> genTags
       "OP_TAGS_DEL" ->
diff --git a/htools/Ganeti/OpCodes.hs b/htools/Ganeti/OpCodes.hs
index 8d08632cc..151b5e938 100644
--- a/htools/Ganeti/OpCodes.hs
+++ b/htools/Ganeti/OpCodes.hs
@@ -54,6 +54,7 @@ $(genOpCode "OpCode"
      [ simpleField "duration"  [t| Double   |]
      , simpleField "on_master" [t| Bool     |]
      , simpleField "on_nodes"  [t| [String] |]
+     , pDelayRepeat
      ])
   , ("OpInstanceReplaceDisks",
      [ pInstanceName
@@ -74,6 +75,12 @@ $(genOpCode "OpCode"
      , defaultField [| False |] $ simpleField "allow_failover" [t| Bool |]
      , pMigrationTargetNode
      ])
+  , ("OpTagsGet",
+     [ pTagsObject
+     , pUseLocking
+     ])
+  , ("OpTagsSearch",
+     [ pTagSearchPattern ])
   , ("OpTagsSet",
      [ pTagsObject
      , pTagsList
diff --git a/htools/Ganeti/OpParams.hs b/htools/Ganeti/OpParams.hs
index 955599c26..4039c8925 100644
--- a/htools/Ganeti/OpParams.hs
+++ b/htools/Ganeti/OpParams.hs
@@ -187,6 +187,8 @@ module Ganeti.OpParams
   , pIgnoreRemoveFailures
   , pX509KeyName
   , pX509DestCA
+  , pTagSearchPattern
+  , pDelayRepeat
   ) where
 
 import Control.Monad (liftM)
@@ -1112,3 +1114,16 @@ pX509KeyName = optionalField $ simpleField "x509_key_name" [t| UncheckedList |]
 -- | Destination X509 CA (remote export only).
 pX509DestCA :: Field
 pX509DestCA = optionalNEStringField "destination_x509_ca"
+
+-- | Search pattern (regular expression). FIXME: this should be
+-- compiled at load time?
+pTagSearchPattern :: Field
+pTagSearchPattern =
+  renameField "TagSearchPattern" $ simpleField "pattern" [t| NonEmptyString |]
+
+-- | Repeat parameter for OpTestDelay.
+pDelayRepeat :: Field
+pDelayRepeat =
+  renameField "DelayRepeat" .
+  defaultField [| forceNonNeg (0::Int) |] $
+  simpleField "repeat" [t| NonNegative Int |]
-- 
GitLab