1 {-# LANGUAGE TemplateHaskell #-}
3 {-| Implementation of the opcodes.
9 Copyright (C) 2009, 2010, 2011, 2012 Google Inc.
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
30 , ReplaceDisksMode(..)
35 import Text.JSON (readJSON, showJSON, makeObj, JSON)
37 import qualified Ganeti.Constants as C
40 import Ganeti.HTools.JSON
42 -- | Replace disks type.
43 $(declareSADT "ReplaceDisksMode"
44 [ ("ReplaceOnPrimary", 'C.replaceDiskPri)
45 , ("ReplaceOnSecondary", 'C.replaceDiskSec)
46 , ("ReplaceNewSecondary", 'C.replaceDiskChg)
47 , ("ReplaceAuto", 'C.replaceDiskAuto)
49 $(makeJSONInstance ''ReplaceDisksMode)
51 -- | OpCode representation.
53 -- We only implement a subset of Ganeti opcodes, but only what we
54 -- actually use in the htools codebase.
57 [ simpleField "duration" [t| Double |]
58 , simpleField "on_master" [t| Bool |]
59 , simpleField "on_nodes" [t| [String] |]
61 , ("OpInstanceReplaceDisks",
62 [ simpleField "instance_name" [t| String |]
63 , optionalField $ simpleField "remote_node" [t| String |]
64 , simpleField "mode" [t| ReplaceDisksMode |]
65 , simpleField "disks" [t| [Int] |]
66 , optionalField $ simpleField "iallocator" [t| String |]
68 , ("OpInstanceFailover",
69 [ simpleField "instance_name" [t| String |]
70 , simpleField "ignore_consistency" [t| Bool |]
71 , optionalField $ simpleField "target_node" [t| String |]
73 , ("OpInstanceMigrate",
74 [ simpleField "instance_name" [t| String |]
75 , simpleField "live" [t| Bool |]
76 , simpleField "cleanup" [t| Bool |]
77 , defaultField [| False |] $ simpleField "allow_failover" [t| Bool |]
78 , optionalField $ simpleField "target_node" [t| String |]
82 -- | Returns the OP_ID for a given opcode value.
83 $(genOpID ''OpCode "opID")
85 -- | A list of all defined/supported opcode IDs.
86 $(genAllOpIDs ''OpCode "allOpIDs")
88 instance JSON OpCode where