Statistics
| Branch: | Tag: | Revision:

root / htools / Ganeti / OpCodes.hs @ e85444d0

History | View | Annotate | Download (2.5 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
36 e9aaa3c6 Iustin Pop
import qualified Ganeti.Constants as C
37 12c19659 Iustin Pop
import Ganeti.THH
38 e9aaa3c6 Iustin Pop
39 b69be409 Iustin Pop
import Ganeti.HTools.JSON
40 702a4ee0 Iustin Pop
41 525bfb36 Iustin Pop
-- | Replace disks type.
42 12c19659 Iustin Pop
$(declareSADT "ReplaceDisksMode"
43 ebf38064 Iustin Pop
  [ ("ReplaceOnPrimary",    'C.replaceDiskPri)
44 ebf38064 Iustin Pop
  , ("ReplaceOnSecondary",  'C.replaceDiskSec)
45 ebf38064 Iustin Pop
  , ("ReplaceNewSecondary", 'C.replaceDiskChg)
46 ebf38064 Iustin Pop
  , ("ReplaceAuto",         'C.replaceDiskAuto)
47 ebf38064 Iustin Pop
  ])
48 12c19659 Iustin Pop
$(makeJSONInstance ''ReplaceDisksMode)
49 702a4ee0 Iustin Pop
50 525bfb36 Iustin Pop
-- | OpCode representation.
51 525bfb36 Iustin Pop
--
52 525bfb36 Iustin Pop
-- We only implement a subset of Ganeti opcodes, but only what we
53 525bfb36 Iustin Pop
-- actually use in the htools codebase.
54 12c19659 Iustin Pop
$(genOpCode "OpCode"
55 ebf38064 Iustin Pop
  [ ("OpTestDelay",
56 a1505857 Iustin Pop
     [ simpleField "duration"  [t| Double   |]
57 a1505857 Iustin Pop
     , simpleField "on_master" [t| Bool     |]
58 a1505857 Iustin Pop
     , simpleField "on_nodes"  [t| [String] |]
59 ebf38064 Iustin Pop
     ])
60 ebf38064 Iustin Pop
  , ("OpInstanceReplaceDisks",
61 a1505857 Iustin Pop
     [ simpleField "instance_name" [t| String |]
62 a1505857 Iustin Pop
     , optionalField $ simpleField "remote_node" [t| String |]
63 a1505857 Iustin Pop
     , simpleField "mode"  [t| ReplaceDisksMode |]
64 a1505857 Iustin Pop
     , simpleField "disks" [t| [Int] |]
65 a1505857 Iustin Pop
     , optionalField $ simpleField "iallocator" [t| String |]
66 ebf38064 Iustin Pop
     ])
67 ebf38064 Iustin Pop
  , ("OpInstanceFailover",
68 a1505857 Iustin Pop
     [ simpleField "instance_name"      [t| String |]
69 a1505857 Iustin Pop
     , simpleField "ignore_consistency" [t| Bool   |]
70 a1505857 Iustin Pop
     , optionalField $ simpleField "target_node" [t| String |]
71 ebf38064 Iustin Pop
     ])
72 ebf38064 Iustin Pop
  , ("OpInstanceMigrate",
73 a1505857 Iustin Pop
     [ simpleField "instance_name"  [t| String |]
74 a1505857 Iustin Pop
     , simpleField "live"           [t| Bool   |]
75 a1505857 Iustin Pop
     , simpleField "cleanup"        [t| Bool   |]
76 a1505857 Iustin Pop
     , defaultField [| False |] $ simpleField "allow_failover" [t| Bool |]
77 a1505857 Iustin Pop
     , optionalField $ simpleField "target_node" [t| String |]
78 ebf38064 Iustin Pop
     ])
79 ebf38064 Iustin Pop
  ])
80 12c19659 Iustin Pop
81 12c19659 Iustin Pop
$(genOpID ''OpCode "opID")
82 702a4ee0 Iustin Pop
83 702a4ee0 Iustin Pop
instance JSON OpCode where
84 ebf38064 Iustin Pop
  readJSON = loadOpCode
85 ebf38064 Iustin Pop
  showJSON = saveOpCode