Statistics
| Branch: | Tag: | Revision:

root / htools / Ganeti / OpCodes.hs @ f3f76ccc

History | View | Annotate | Download (2.6 kB)

1 e9aaa3c6 Iustin Pop
{-# LANGUAGE TemplateHaskell #-}
2 e9aaa3c6 Iustin Pop
3 702a4ee0 Iustin Pop
{-| Implementation of the opcodes.
4 702a4ee0 Iustin Pop
5 702a4ee0 Iustin Pop
-}
6 702a4ee0 Iustin Pop
7 702a4ee0 Iustin Pop
{-
8 702a4ee0 Iustin Pop
9 e8230242 Iustin Pop
Copyright (C) 2009, 2010, 2011 Google Inc.
10 702a4ee0 Iustin Pop
11 702a4ee0 Iustin Pop
This program is free software; you can redistribute it and/or modify
12 702a4ee0 Iustin Pop
it under the terms of the GNU General Public License as published by
13 702a4ee0 Iustin Pop
the Free Software Foundation; either version 2 of the License, or
14 702a4ee0 Iustin Pop
(at your option) any later version.
15 702a4ee0 Iustin Pop
16 702a4ee0 Iustin Pop
This program is distributed in the hope that it will be useful, but
17 702a4ee0 Iustin Pop
WITHOUT ANY WARRANTY; without even the implied warranty of
18 702a4ee0 Iustin Pop
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 702a4ee0 Iustin Pop
General Public License for more details.
20 702a4ee0 Iustin Pop
21 702a4ee0 Iustin Pop
You should have received a copy of the GNU General Public License
22 702a4ee0 Iustin Pop
along with this program; if not, write to the Free Software
23 702a4ee0 Iustin Pop
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 702a4ee0 Iustin Pop
02110-1301, USA.
25 702a4ee0 Iustin Pop
26 702a4ee0 Iustin Pop
-}
27 702a4ee0 Iustin Pop
28 702a4ee0 Iustin Pop
module Ganeti.OpCodes
29 ebf38064 Iustin Pop
  ( OpCode(..)
30 ebf38064 Iustin Pop
  , ReplaceDisksMode(..)
31 ebf38064 Iustin Pop
  , opID
32 ebf38064 Iustin Pop
  ) where
33 702a4ee0 Iustin Pop
34 0903280b Iustin Pop
import Text.JSON (readJSON, showJSON, makeObj, JSON)
35 702a4ee0 Iustin Pop
import qualified Text.JSON as J
36 702a4ee0 Iustin Pop
37 e9aaa3c6 Iustin Pop
import qualified Ganeti.Constants as C
38 12c19659 Iustin Pop
import Ganeti.THH
39 e9aaa3c6 Iustin Pop
40 702a4ee0 Iustin Pop
import Ganeti.HTools.Utils
41 702a4ee0 Iustin Pop
42 525bfb36 Iustin Pop
-- | Replace disks type.
43 12c19659 Iustin Pop
$(declareSADT "ReplaceDisksMode"
44 ebf38064 Iustin Pop
  [ ("ReplaceOnPrimary",    'C.replaceDiskPri)
45 ebf38064 Iustin Pop
  , ("ReplaceOnSecondary",  'C.replaceDiskSec)
46 ebf38064 Iustin Pop
  , ("ReplaceNewSecondary", 'C.replaceDiskChg)
47 ebf38064 Iustin Pop
  , ("ReplaceAuto",         'C.replaceDiskAuto)
48 ebf38064 Iustin Pop
  ])
49 12c19659 Iustin Pop
$(makeJSONInstance ''ReplaceDisksMode)
50 702a4ee0 Iustin Pop
51 525bfb36 Iustin Pop
-- | OpCode representation.
52 525bfb36 Iustin Pop
--
53 525bfb36 Iustin Pop
-- We only implement a subset of Ganeti opcodes, but only what we
54 525bfb36 Iustin Pop
-- actually use in the htools codebase.
55 12c19659 Iustin Pop
$(genOpCode "OpCode"
56 ebf38064 Iustin Pop
  [ ("OpTestDelay",
57 a1505857 Iustin Pop
     [ simpleField "duration"  [t| Double   |]
58 a1505857 Iustin Pop
     , simpleField "on_master" [t| Bool     |]
59 a1505857 Iustin Pop
     , simpleField "on_nodes"  [t| [String] |]
60 ebf38064 Iustin Pop
     ])
61 ebf38064 Iustin Pop
  , ("OpInstanceReplaceDisks",
62 a1505857 Iustin Pop
     [ simpleField "instance_name" [t| String |]
63 a1505857 Iustin Pop
     , optionalField $ simpleField "remote_node" [t| String |]
64 a1505857 Iustin Pop
     , simpleField "mode"  [t| ReplaceDisksMode |]
65 a1505857 Iustin Pop
     , simpleField "disks" [t| [Int] |]
66 a1505857 Iustin Pop
     , optionalField $ simpleField "iallocator" [t| String |]
67 ebf38064 Iustin Pop
     ])
68 ebf38064 Iustin Pop
  , ("OpInstanceFailover",
69 a1505857 Iustin Pop
     [ simpleField "instance_name"      [t| String |]
70 a1505857 Iustin Pop
     , simpleField "ignore_consistency" [t| Bool   |]
71 a1505857 Iustin Pop
     , optionalField $ simpleField "target_node" [t| String |]
72 ebf38064 Iustin Pop
     ])
73 ebf38064 Iustin Pop
  , ("OpInstanceMigrate",
74 a1505857 Iustin Pop
     [ simpleField "instance_name"  [t| String |]
75 a1505857 Iustin Pop
     , simpleField "live"           [t| Bool   |]
76 a1505857 Iustin Pop
     , simpleField "cleanup"        [t| Bool   |]
77 a1505857 Iustin Pop
     , defaultField [| False |] $ simpleField "allow_failover" [t| Bool |]
78 a1505857 Iustin Pop
     , optionalField $ simpleField "target_node" [t| String |]
79 ebf38064 Iustin Pop
     ])
80 ebf38064 Iustin Pop
  ])
81 12c19659 Iustin Pop
82 12c19659 Iustin Pop
$(genOpID ''OpCode "opID")
83 702a4ee0 Iustin Pop
84 702a4ee0 Iustin Pop
instance JSON OpCode where
85 ebf38064 Iustin Pop
  readJSON = loadOpCode
86 ebf38064 Iustin Pop
  showJSON = saveOpCode