Statistics
| Branch: | Tag: | Revision:

root / htools / Ganeti / OpCodes.hs @ 7eda951b

History | View | Annotate | Download (2.8 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 702a4ee0 Iustin Pop
    ( OpCode(..)
30 702a4ee0 Iustin Pop
    , ReplaceDisksMode(..)
31 702a4ee0 Iustin Pop
    , opID
32 702a4ee0 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 e9aaa3c6 Iustin Pop
     [ ("ReplaceOnPrimary",    'C.replaceDiskPri)
45 e9aaa3c6 Iustin Pop
     , ("ReplaceOnSecondary",  'C.replaceDiskSec)
46 e9aaa3c6 Iustin Pop
     , ("ReplaceNewSecondary", 'C.replaceDiskChg)
47 e9aaa3c6 Iustin Pop
     , ("ReplaceAuto",         'C.replaceDiskAuto)
48 e9aaa3c6 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 12c19659 Iustin Pop
         [ ("OpTestDelay",
57 12c19659 Iustin Pop
            [ ("duration",  [t| Double   |], noDefault)
58 12c19659 Iustin Pop
            , ("on_master", [t| Bool     |], noDefault)
59 12c19659 Iustin Pop
            , ("on_nodes",  [t| [String] |], noDefault)
60 12c19659 Iustin Pop
            ])
61 12c19659 Iustin Pop
         , ("OpInstanceReplaceDisks",
62 12c19659 Iustin Pop
            [ ("instance_name", [t| String           |], noDefault)
63 12c19659 Iustin Pop
            , ("remote_node",   [t| Maybe String     |], noDefault)
64 12c19659 Iustin Pop
            , ("mode",          [t| ReplaceDisksMode |], noDefault)
65 12c19659 Iustin Pop
            , ("disks",         [t| [Int]            |], noDefault)
66 12c19659 Iustin Pop
            , ("iallocator",    [t| Maybe String     |], noDefault)
67 12c19659 Iustin Pop
            ])
68 12c19659 Iustin Pop
         , ("OpInstanceFailover",
69 12c19659 Iustin Pop
            [ ("instance_name",      [t| String       |], noDefault)
70 12c19659 Iustin Pop
            , ("ignore_consistency", [t| Bool         |], noDefault)
71 12c19659 Iustin Pop
            , ("target_node",        [t| Maybe String |], noDefault)
72 12c19659 Iustin Pop
            ])
73 12c19659 Iustin Pop
         , ("OpInstanceMigrate",
74 12c19659 Iustin Pop
            [ ("instance_name",  [t| String       |], noDefault)
75 12c19659 Iustin Pop
            , ("live",           [t| Bool         |], noDefault)
76 12c19659 Iustin Pop
            , ("cleanup",        [t| Bool         |], noDefault)
77 12c19659 Iustin Pop
            , ("allow_failover", [t| Bool         |], [| Just False |])
78 12c19659 Iustin Pop
            , ("target_node",    [t| Maybe String |], noDefault)
79 12c19659 Iustin Pop
            ])
80 12c19659 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 702a4ee0 Iustin Pop
    readJSON = loadOpCode
86 702a4ee0 Iustin Pop
    showJSON = saveOpCode