From 7d4213868ece0a64952254246ab805637aaa94dd Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Sun, 25 Nov 2012 23:28:31 +0100
Subject: [PATCH] Remove remaining in-line parameters
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

… except one, and replace them with separately-defined ones in
OpParams.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Helga Velroyen <helgav@google.com>
---
 htest/Test/Ganeti/OpCodes.hs |  4 ++--
 htools/Ganeti/OpCodes.hs     | 16 +++++++-------
 htools/Ganeti/OpParams.hs    | 41 ++++++++++++++++++++++++++++++++++++
 3 files changed, 51 insertions(+), 10 deletions(-)

diff --git a/htest/Test/Ganeti/OpCodes.hs b/htest/Test/Ganeti/OpCodes.hs
index 32e29c4ac..ab56f69d4 100644
--- a/htest/Test/Ganeti/OpCodes.hs
+++ b/htest/Test/Ganeti/OpCodes.hs
@@ -105,8 +105,8 @@ instance Arbitrary OpCodes.OpCode where
     op_id <- elements OpCodes.allOpIDs
     case op_id of
       "OP_TEST_DELAY" ->
-        OpCodes.OpTestDelay <$> arbitrary <*> arbitrary
-                 <*> genNodeNames <*> arbitrary
+        OpCodes.OpTestDelay <$> arbitrary <*> arbitrary <*>
+          genNodeNamesNE <*> arbitrary
       "OP_INSTANCE_REPLACE_DISKS" ->
         OpCodes.OpInstanceReplaceDisks <$> genFQDN <*>
           genMaybe genNodeNameNE <*> arbitrary <*> genDiskIndices <*>
diff --git a/htools/Ganeti/OpCodes.hs b/htools/Ganeti/OpCodes.hs
index 20acff73c..5b52a3802 100644
--- a/htools/Ganeti/OpCodes.hs
+++ b/htools/Ganeti/OpCodes.hs
@@ -51,28 +51,28 @@ import Ganeti.OpParams
 -- in the htools codebase.
 $(genOpCode "OpCode"
   [ ("OpTestDelay",
-     [ simpleField "duration"  [t| Double   |]
-     , simpleField "on_master" [t| Bool     |]
-     , simpleField "on_nodes"  [t| [String] |]
+     [ pDelayDuration
+     , pDelayOnMaster
+     , pDelayOnNodes
      , pDelayRepeat
      ])
   , ("OpInstanceReplaceDisks",
      [ pInstanceName
      , pRemoteNode
-     , simpleField "mode"  [t| ReplaceDisksMode |]
-     , simpleField "disks" [t| [DiskIndex] |]
+     , pReplaceDisksMode
+     , pReplaceDisksList
      , pIallocator
      ])
   , ("OpInstanceFailover",
      [ pInstanceName
-     , simpleField "ignore_consistency" [t| Bool   |]
+     , pIgnoreConsistency
      , pMigrationTargetNode
      ])
   , ("OpInstanceMigrate",
      [ pInstanceName
      , simpleField "live"           [t| Bool   |]
-     , simpleField "cleanup"        [t| Bool   |]
-     , defaultField [| False |] $ simpleField "allow_failover" [t| Bool |]
+     , pMigrationCleanup
+     , pAllowFailover
      , pMigrationTargetNode
      ])
   , ("OpTagsGet",
diff --git a/htools/Ganeti/OpParams.hs b/htools/Ganeti/OpParams.hs
index 0970c1dee..c4ec425ad 100644
--- a/htools/Ganeti/OpParams.hs
+++ b/htools/Ganeti/OpParams.hs
@@ -63,6 +63,7 @@ module Ganeti.OpParams
   , pGroupName
   , pMigrationMode
   , pMigrationLive
+  , pMigrationCleanup
   , pForceVariant
   , pWaitForSync
   , pWaitForSyncFalse
@@ -189,6 +190,12 @@ module Ganeti.OpParams
   , pX509DestCA
   , pTagSearchPattern
   , pRestrictedCommand
+  , pReplaceDisksMode
+  , pReplaceDisksList
+  , pAllowFailover
+  , pDelayDuration
+  , pDelayOnMaster
+  , pDelayOnNodes
   , pDelayRepeat
   , pIAllocatorDirection
   , pIAllocatorMode
@@ -560,6 +567,10 @@ pMigrationLive :: Field
 pMigrationLive =
   renameField "OldLiveMode" . optionalField $ booleanField "live"
 
+-- | Migration cleanup parameter.
+pMigrationCleanup :: Field
+pMigrationCleanup = renameField "MigrationCleanup" $ defaultFalse "cleanup"
+
 -- | Whether to force an unknown OS variant.
 pForceVariant :: Field
 pForceVariant = defaultFalse "force_variant"
@@ -1161,8 +1172,38 @@ pRestrictedCommand =
   renameField "RestrictedCommand" $
   simpleField "command" [t| NonEmptyString |]
 
+-- | Replace disks mode.
+pReplaceDisksMode :: Field
+pReplaceDisksMode =
+  renameField "ReplaceDisksMode" $ simpleField "mode" [t| ReplaceDisksMode |]
+
+-- | List of disk indices.
+pReplaceDisksList :: Field
+pReplaceDisksList =
+  renameField "ReplaceDisksList" $ simpleField "disks" [t| [DiskIndex] |]
+
+-- | Whether do allow failover in migrations.
+pAllowFailover :: Field
+pAllowFailover = defaultFalse "allow_failover"
+
 -- * Test opcode parameters
 
+-- | Duration parameter for 'OpTestDelay'.
+pDelayDuration :: Field
+pDelayDuration =
+  renameField "DelayDuration "$ simpleField "duration" [t| Double |]
+
+-- | on_master field for 'OpTestDelay'.
+pDelayOnMaster :: Field
+pDelayOnMaster = renameField "DelayOnMaster" $ defaultTrue "on_master"
+
+-- | on_nodes field for 'OpTestDelay'.
+pDelayOnNodes :: Field
+pDelayOnNodes =
+  renameField "DelayOnNodes" .
+  defaultField [| [] |] $
+  simpleField "on_nodes" [t| [NonEmptyString] |]
+
 -- | Repeat parameter for OpTestDelay.
 pDelayRepeat :: Field
 pDelayRepeat =
-- 
GitLab