Statistics
| Branch: | Tag: | Revision:

root / htools / Ganeti / OpCodes.hs @ ad0e078e

History | View | Annotate | Download (2.5 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

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

    
39
import Ganeti.HTools.JSON
40

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

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

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

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