Statistics
| Branch: | Tag: | Revision:

root / htools / Ganeti / OpCodes.hs @ ebf38064

History | View | Annotate | Download (2.6 kB)

1
{-# LANGUAGE TemplateHaskell #-}
2

    
3
{-| Implementation of the opcodes.
4

    
5
-}
6

    
7
{-
8

    
9
Copyright (C) 2009, 2010, 2011 Google Inc.
10

    
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.
15

    
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.
20

    
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
24
02110-1301, USA.
25

    
26
-}
27

    
28
module Ganeti.OpCodes
29
  ( OpCode(..)
30
  , ReplaceDisksMode(..)
31
  , opID
32
  ) where
33

    
34
import Text.JSON (readJSON, showJSON, makeObj, JSON)
35
import qualified Text.JSON as J
36

    
37
import qualified Ganeti.Constants as C
38
import Ganeti.THH
39

    
40
import Ganeti.HTools.Utils
41

    
42
-- | Replace disks type.
43
$(declareSADT "ReplaceDisksMode"
44
  [ ("ReplaceOnPrimary",    'C.replaceDiskPri)
45
  , ("ReplaceOnSecondary",  'C.replaceDiskSec)
46
  , ("ReplaceNewSecondary", 'C.replaceDiskChg)
47
  , ("ReplaceAuto",         'C.replaceDiskAuto)
48
  ])
49
$(makeJSONInstance ''ReplaceDisksMode)
50

    
51
-- | OpCode representation.
52
--
53
-- We only implement a subset of Ganeti opcodes, but only what we
54
-- actually use in the htools codebase.
55
$(genOpCode "OpCode"
56
  [ ("OpTestDelay",
57
     [ ("duration",  [t| Double   |], noDefault)
58
     , ("on_master", [t| Bool     |], noDefault)
59
     , ("on_nodes",  [t| [String] |], noDefault)
60
     ])
61
  , ("OpInstanceReplaceDisks",
62
     [ ("instance_name", [t| String           |], noDefault)
63
     , ("remote_node",   [t| Maybe String     |], noDefault)
64
     , ("mode",          [t| ReplaceDisksMode |], noDefault)
65
     , ("disks",         [t| [Int]            |], noDefault)
66
     , ("iallocator",    [t| Maybe String     |], noDefault)
67
     ])
68
  , ("OpInstanceFailover",
69
     [ ("instance_name",      [t| String       |], noDefault)
70
     , ("ignore_consistency", [t| Bool         |], noDefault)
71
     , ("target_node",        [t| Maybe String |], noDefault)
72
     ])
73
  , ("OpInstanceMigrate",
74
     [ ("instance_name",  [t| String       |], noDefault)
75
     , ("live",           [t| Bool         |], noDefault)
76
     , ("cleanup",        [t| Bool         |], noDefault)
77
     , ("allow_failover", [t| Bool         |], [| Just False |])
78
     , ("target_node",    [t| Maybe String |], noDefault)
79
     ])
80
  ])
81

    
82
$(genOpID ''OpCode "opID")
83

    
84
instance JSON OpCode where
85
  readJSON = loadOpCode
86
  showJSON = saveOpCode