Statistics
| Branch: | Tag: | Revision:

root / htools / Ganeti / OpCodes.hs @ 1a865afe

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, 2012 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
  , TagObject(..)
31
  , tagObjectFrom
32
  , encodeTagObject
33
  , decodeTagObject
34
  , ReplaceDisksMode(..)
35
  , DiskIndex
36
  , mkDiskIndex
37
  , unDiskIndex
38
  , opID
39
  , allOpIDs
40
  ) where
41

    
42
import Text.JSON (readJSON, showJSON, JSON())
43

    
44
import Ganeti.THH
45

    
46
import Ganeti.OpParams
47

    
48
-- | OpCode representation.
49
--
50
-- We only implement a subset of Ganeti opcodes: those which are actually used
51
-- in the htools codebase.
52
$(genOpCode "OpCode"
53
  [ ("OpTestDelay",
54
     [ simpleField "duration"  [t| Double   |]
55
     , simpleField "on_master" [t| Bool     |]
56
     , simpleField "on_nodes"  [t| [String] |]
57
     ])
58
  , ("OpInstanceReplaceDisks",
59
     [ pInstanceName
60
     , optionalField $ simpleField "remote_node" [t| String |]
61
     , simpleField "mode"  [t| ReplaceDisksMode |]
62
     , simpleField "disks" [t| [DiskIndex] |]
63
     , optionalField $ simpleField "iallocator" [t| String |]
64
     ])
65
  , ("OpInstanceFailover",
66
     [ pInstanceName
67
     , simpleField "ignore_consistency" [t| Bool   |]
68
     , optionalField $ simpleField "target_node" [t| String |]
69
     ])
70
  , ("OpInstanceMigrate",
71
     [ pInstanceName
72
     , simpleField "live"           [t| Bool   |]
73
     , simpleField "cleanup"        [t| Bool   |]
74
     , defaultField [| False |] $ simpleField "allow_failover" [t| Bool |]
75
     , optionalField $ simpleField "target_node" [t| String |]
76
     ])
77
  , ("OpTagsSet",
78
     [ pTagsObject
79
     , pTagsList
80
     ])
81
  , ("OpTagsDel",
82
     [ pTagsObject
83
     , pTagsList
84
     ])
85
  ])
86

    
87
-- | Returns the OP_ID for a given opcode value.
88
$(genOpID ''OpCode "opID")
89

    
90
-- | A list of all defined/supported opcode IDs.
91
$(genAllOpIDs ''OpCode "allOpIDs")
92

    
93
instance JSON OpCode where
94
  readJSON = loadOpCode
95
  showJSON = saveOpCode