RAPI: implement backwards compat with Ganeti 2.3
[ganeti-local] / Ganeti / OpCodes.hs
index ca2d8f4..7b3e434 100644 (file)
@@ -4,7 +4,7 @@
 
 {-
 
-Copyright (C) 2009 Google Inc.
+Copyright (C) 2009, 2010 Google Inc.
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -29,9 +29,8 @@ module Ganeti.OpCodes
     , opID
     ) where
 
-import Data.List
 import Control.Monad
-import Text.JSON (JSObject, JSValue, readJSON, showJSON, makeObj, JSON)
+import Text.JSON (readJSON, showJSON, makeObj, JSON)
 import qualified Text.JSON as J
 import Text.JSON.Types
 
@@ -41,7 +40,7 @@ data ReplaceDisksMode = ReplaceOnPrimary
                   | ReplaceOnSecondary
                   | ReplaceNewSecondary
                   | ReplaceAuto
-                  deriving Show
+                  deriving (Show, Read, Eq)
 
 instance JSON ReplaceDisksMode where
     showJSON m = case m of
@@ -61,7 +60,7 @@ data OpCode = OpTestDelay Double Bool [String]
               [Int] (Maybe String)
             | OpFailoverInstance String Bool
             | OpMigrateInstance String Bool Bool
-            deriving Show
+            deriving (Show, Read, Eq)
 
 
 opID :: OpCode -> String
@@ -82,10 +81,10 @@ loadOpCode v = do
                  return $ OpTestDelay duration on_master on_nodes
     "OP_INSTANCE_REPLACE_DISKS" -> do
                  inst <- fromObj "instance_name" o
-                 node <- fromObj "remote_node" o
+                 node <- maybeFromObj "remote_node" o
                  mode <- fromObj "mode" o
                  disks <- fromObj "disks" o
-                 ialloc <- fromObj "iallocator" o
+                 ialloc <- maybeFromObj "iallocator" o
                  return $ OpReplaceDisks inst node mode disks ialloc
     "OP_INSTANCE_FAILOVER" -> do
                  inst <- fromObj "instance_name" o