On Mon, Aug 10, 2015 at 07:22:19PM +0200, 'Klaus Aehlig' via ganeti-devel wrote:
In some cases we do not want to migrate an instance off a node.
Add a function to change all OpMigrate to a corresponding OpFailover.
This will simplify the handling of such code.

Signed-off-by: Klaus Aehlig <[email protected]>
---
src/Ganeti/Jobs.hs | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)

diff --git a/src/Ganeti/Jobs.hs b/src/Ganeti/Jobs.hs
index 924ed56..642046b 100644
--- a/src/Ganeti/Jobs.hs
+++ b/src/Ganeti/Jobs.hs
@@ -40,10 +40,12 @@ module Ganeti.Jobs
  , execJobsWaitOk
  , execJobsWaitOkJid
  , waitForJobs
+  , forceFailover
  ) where

import Control.Exception (bracket)
import Control.Monad (void, forM)
+import Data.Functor.Identity (runIdentity)
import Data.List
import Data.Tuple
import Data.IORef
@@ -196,3 +198,19 @@ execJobsWaitOkJid opcodes client = do
execJobsWaitOk :: [[MetaOpCode]] -> L.Client -> IO (Result ())
execJobsWaitOk opcodes =
  fmap void . execJobsWaitOkJid opcodes
+
+-- | Channge Migrations to Failovers
+forceFailover :: OpCode -> OpCode
+forceFailover op@(OpInstanceMigrate {}) = runIdentity $ do
+  timeout <- mkNonNegative C.defaultShutdownTimeout

Just a minor idea, as the monad is needed only at this single place, I'd suggest just

  let timeout = runIdentity $ mkNonNegative C.defaultShutdownTimeout
   in ..

No need to resend.

+  return OpInstanceFailover { opInstanceName = opInstanceName op
+                            , opInstanceUuid = opInstanceUuid op
+                            , opShutdownTimeout = timeout
+                            , opIgnoreConsistency = True
+                            , opTargetNode = opTargetNode op
+                            , opTargetNodeUuid = opTargetNodeUuid op
+                            , opIgnoreIpolicy = opIgnoreIpolicy op
+                            , opMigrationCleanup = opMigrationCleanup op
+                            , opIallocator = opIallocator op
+                            }
+forceFailover op = op
--
2.5.0.rc2.392.g76e840b


LGTM

Reply via email to