Statistics
| Branch: | Tag: | Revision:

root / htools / Ganeti / Objects.hs @ 36691f08

History | View | Annotate | Download (8.7 kB)

1 b1e81520 Iustin Pop
{-# LANGUAGE TemplateHaskell #-}
2 b1e81520 Iustin Pop
3 b1e81520 Iustin Pop
{-| Implementation of the Ganeti config objects.
4 b1e81520 Iustin Pop
5 b1e81520 Iustin Pop
Some object fields are not implemented yet, and as such they are
6 b1e81520 Iustin Pop
commented out below.
7 b1e81520 Iustin Pop
8 b1e81520 Iustin Pop
-}
9 b1e81520 Iustin Pop
10 b1e81520 Iustin Pop
{-
11 b1e81520 Iustin Pop
12 b1e81520 Iustin Pop
Copyright (C) 2011, 2012 Google Inc.
13 b1e81520 Iustin Pop
14 b1e81520 Iustin Pop
This program is free software; you can redistribute it and/or modify
15 b1e81520 Iustin Pop
it under the terms of the GNU General Public License as published by
16 b1e81520 Iustin Pop
the Free Software Foundation; either version 2 of the License, or
17 b1e81520 Iustin Pop
(at your option) any later version.
18 b1e81520 Iustin Pop
19 b1e81520 Iustin Pop
This program is distributed in the hope that it will be useful, but
20 b1e81520 Iustin Pop
WITHOUT ANY WARRANTY; without even the implied warranty of
21 b1e81520 Iustin Pop
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
22 b1e81520 Iustin Pop
General Public License for more details.
23 b1e81520 Iustin Pop
24 b1e81520 Iustin Pop
You should have received a copy of the GNU General Public License
25 b1e81520 Iustin Pop
along with this program; if not, write to the Free Software
26 b1e81520 Iustin Pop
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
27 b1e81520 Iustin Pop
02110-1301, USA.
28 b1e81520 Iustin Pop
29 b1e81520 Iustin Pop
-}
30 b1e81520 Iustin Pop
31 b1e81520 Iustin Pop
module Ganeti.Objects
32 b1e81520 Iustin Pop
  ( NICMode(..)
33 b1e81520 Iustin Pop
  , PartialNICParams(..)
34 b1e81520 Iustin Pop
  , FilledNICParams(..)
35 b1e81520 Iustin Pop
  , fillNICParams
36 b1e81520 Iustin Pop
  , PartialNIC(..)
37 b1e81520 Iustin Pop
  , DiskMode(..)
38 b1e81520 Iustin Pop
  , DiskType(..)
39 b1e81520 Iustin Pop
  , Disk(..)
40 b1e81520 Iustin Pop
  , DiskTemplate(..)
41 b1e81520 Iustin Pop
  , PartialBEParams(..)
42 b1e81520 Iustin Pop
  , FilledBEParams(..)
43 b1e81520 Iustin Pop
  , fillBEParams
44 b1e81520 Iustin Pop
  , Instance(..)
45 b1e81520 Iustin Pop
  , toDictInstance
46 b1e81520 Iustin Pop
  , PartialNDParams(..)
47 b1e81520 Iustin Pop
  , FilledNDParams(..)
48 b1e81520 Iustin Pop
  , fillNDParams
49 b1e81520 Iustin Pop
  , Node(..)
50 b1e81520 Iustin Pop
  , AllocPolicy(..)
51 b1e81520 Iustin Pop
  , NodeGroup(..)
52 b1e81520 Iustin Pop
  , Cluster(..)
53 b1e81520 Iustin Pop
  , ConfigData(..)
54 b1e81520 Iustin Pop
  ) where
55 b1e81520 Iustin Pop
56 b1e81520 Iustin Pop
import Data.Maybe
57 b1e81520 Iustin Pop
import Text.JSON (makeObj, showJSON, readJSON)
58 b1e81520 Iustin Pop
59 b1e81520 Iustin Pop
import qualified Ganeti.Constants as C
60 b1e81520 Iustin Pop
import Ganeti.HTools.JSON
61 b1e81520 Iustin Pop
62 b1e81520 Iustin Pop
import Ganeti.THH
63 b1e81520 Iustin Pop
64 b1e81520 Iustin Pop
-- * NIC definitions
65 b1e81520 Iustin Pop
66 b1e81520 Iustin Pop
$(declareSADT "NICMode"
67 b1e81520 Iustin Pop
  [ ("NMBridged", 'C.nicModeBridged)
68 b1e81520 Iustin Pop
  , ("NMRouted",  'C.nicModeRouted)
69 b1e81520 Iustin Pop
  ])
70 b1e81520 Iustin Pop
$(makeJSONInstance ''NICMode)
71 b1e81520 Iustin Pop
72 b1e81520 Iustin Pop
$(buildParam "NIC" "nicp"
73 b1e81520 Iustin Pop
  [ simpleField "mode" [t| NICMode |]
74 b1e81520 Iustin Pop
  , simpleField "link" [t| String  |]
75 b1e81520 Iustin Pop
  ])
76 b1e81520 Iustin Pop
77 b1e81520 Iustin Pop
$(buildObject "PartialNIC" "nic"
78 b1e81520 Iustin Pop
  [ simpleField "mac" [t| String |]
79 b1e81520 Iustin Pop
  , optionalField $ simpleField "ip" [t| String |]
80 b1e81520 Iustin Pop
  , simpleField "nicparams" [t| PartialNICParams |]
81 b1e81520 Iustin Pop
  ])
82 b1e81520 Iustin Pop
83 b1e81520 Iustin Pop
-- * Disk definitions
84 b1e81520 Iustin Pop
85 b1e81520 Iustin Pop
$(declareSADT "DiskMode"
86 b1e81520 Iustin Pop
  [ ("DiskRdOnly", 'C.diskRdonly)
87 b1e81520 Iustin Pop
  , ("DiskRdWr",   'C.diskRdwr)
88 b1e81520 Iustin Pop
  ])
89 b1e81520 Iustin Pop
$(makeJSONInstance ''DiskMode)
90 b1e81520 Iustin Pop
91 b1e81520 Iustin Pop
$(declareSADT "DiskType"
92 b1e81520 Iustin Pop
  [ ("LD_LV",       'C.ldLv)
93 b1e81520 Iustin Pop
  , ("LD_DRBD8",    'C.ldDrbd8)
94 b1e81520 Iustin Pop
  , ("LD_FILE",     'C.ldFile)
95 b1e81520 Iustin Pop
  , ("LD_BLOCKDEV", 'C.ldBlockdev)
96 b1e81520 Iustin Pop
  ])
97 b1e81520 Iustin Pop
$(makeJSONInstance ''DiskType)
98 b1e81520 Iustin Pop
99 b1e81520 Iustin Pop
-- | Disk data structure.
100 b1e81520 Iustin Pop
--
101 b1e81520 Iustin Pop
-- This is declared manually as it's a recursive structure, and our TH
102 b1e81520 Iustin Pop
-- code currently can't build it.
103 b1e81520 Iustin Pop
data Disk = Disk
104 b1e81520 Iustin Pop
  { diskDevType    :: DiskType
105 b1e81520 Iustin Pop
--  , diskLogicalId  :: String
106 b1e81520 Iustin Pop
--  , diskPhysicalId :: String
107 b1e81520 Iustin Pop
  , diskChildren   :: [Disk]
108 b1e81520 Iustin Pop
  , diskIvName     :: String
109 b1e81520 Iustin Pop
  , diskSize       :: Int
110 b1e81520 Iustin Pop
  , diskMode       :: DiskMode
111 b1e81520 Iustin Pop
  } deriving (Read, Show, Eq)
112 b1e81520 Iustin Pop
113 b1e81520 Iustin Pop
$(buildObjectSerialisation "Disk"
114 b1e81520 Iustin Pop
  [ simpleField "dev_type"      [t| DiskMode |]
115 b1e81520 Iustin Pop
--  , simpleField "logical_id"  [t| String   |]
116 b1e81520 Iustin Pop
--  , simpleField "physical_id" [t| String   |]
117 b1e81520 Iustin Pop
  , defaultField  [| [] |] $ simpleField "children" [t| [Disk] |]
118 b1e81520 Iustin Pop
  , defaultField [| "" |] $ simpleField "iv_name" [t| String |]
119 b1e81520 Iustin Pop
  , simpleField "size" [t| Int |]
120 b1e81520 Iustin Pop
  , defaultField [| DiskRdWr |] $ simpleField "mode" [t| DiskMode |]
121 b1e81520 Iustin Pop
  ])
122 b1e81520 Iustin Pop
123 b1e81520 Iustin Pop
-- * Instance definitions
124 b1e81520 Iustin Pop
125 b1e81520 Iustin Pop
-- | Instance disk template type. **Copied from HTools/Types.hs**
126 b1e81520 Iustin Pop
$(declareSADT "DiskTemplate"
127 b1e81520 Iustin Pop
  [ ("DTDiskless",   'C.dtDiskless)
128 b1e81520 Iustin Pop
  , ("DTFile",       'C.dtFile)
129 b1e81520 Iustin Pop
  , ("DTSharedFile", 'C.dtSharedFile)
130 b1e81520 Iustin Pop
  , ("DTPlain",      'C.dtPlain)
131 b1e81520 Iustin Pop
  , ("DTBlock",      'C.dtBlock)
132 b1e81520 Iustin Pop
  , ("DTDrbd8",      'C.dtDrbd8)
133 b1e81520 Iustin Pop
  ])
134 b1e81520 Iustin Pop
$(makeJSONInstance ''DiskTemplate)
135 b1e81520 Iustin Pop
136 b1e81520 Iustin Pop
$(declareSADT "AdminState"
137 b1e81520 Iustin Pop
  [ ("AdminOffline", 'C.adminstOffline)
138 b1e81520 Iustin Pop
  , ("AdminDown",    'C.adminstDown)
139 b1e81520 Iustin Pop
  , ("AdminUp",      'C.adminstUp)
140 b1e81520 Iustin Pop
  ])
141 b1e81520 Iustin Pop
$(makeJSONInstance ''AdminState)
142 b1e81520 Iustin Pop
143 b1e81520 Iustin Pop
$(buildParam "BE" "bep" $
144 b1e81520 Iustin Pop
  [ simpleField "minmem"       [t| Int  |]
145 b1e81520 Iustin Pop
  , simpleField "maxmem"       [t| Int  |]
146 b1e81520 Iustin Pop
  , simpleField "vcpus"        [t| Int  |]
147 b1e81520 Iustin Pop
  , simpleField "auto_balance" [t| Bool |]
148 b1e81520 Iustin Pop
  ])
149 b1e81520 Iustin Pop
150 b1e81520 Iustin Pop
$(buildObject "Instance" "inst" $
151 b1e81520 Iustin Pop
  [ simpleField "name"           [t| String             |]
152 b1e81520 Iustin Pop
  , simpleField "primary_node"   [t| String             |]
153 b1e81520 Iustin Pop
  , simpleField "os"             [t| String             |]
154 b1e81520 Iustin Pop
  , simpleField "hypervisor"     [t| String             |]
155 b1e81520 Iustin Pop
--  , simpleField "hvparams"     [t| [(String, String)] |]
156 b1e81520 Iustin Pop
  , simpleField "beparams"       [t| PartialBEParams |]
157 b1e81520 Iustin Pop
--  , simpleField "osparams"     [t| [(String, String)] |]
158 b1e81520 Iustin Pop
  , simpleField "admin_state"    [t| AdminState         |]
159 b1e81520 Iustin Pop
  , simpleField "nics"           [t| [PartialNIC]              |]
160 b1e81520 Iustin Pop
  , simpleField "disks"          [t| [Disk]             |]
161 b1e81520 Iustin Pop
  , simpleField "disk_template"  [t| DiskTemplate       |]
162 b1e81520 Iustin Pop
  , optionalField $ simpleField "network_port" [t| Int |]
163 b1e81520 Iustin Pop
  ]
164 b1e81520 Iustin Pop
  ++ timeStampFields
165 b1e81520 Iustin Pop
  ++ uuidFields
166 b1e81520 Iustin Pop
  ++ serialFields)
167 b1e81520 Iustin Pop
168 b1e81520 Iustin Pop
-- * Node definitions
169 b1e81520 Iustin Pop
170 b1e81520 Iustin Pop
$(buildParam "ND" "ndp" $
171 b1e81520 Iustin Pop
  [ simpleField "oob_program" [t| String |]
172 b1e81520 Iustin Pop
  ])
173 b1e81520 Iustin Pop
174 b1e81520 Iustin Pop
$(buildObject "Node" "node" $
175 b1e81520 Iustin Pop
  [ simpleField "name"             [t| String |]
176 b1e81520 Iustin Pop
  , simpleField "primary_ip"       [t| String |]
177 b1e81520 Iustin Pop
  , simpleField "secondary_ip"     [t| String |]
178 b1e81520 Iustin Pop
  , simpleField "master_candidate" [t| Bool   |]
179 b1e81520 Iustin Pop
  , simpleField "offline"          [t| Bool   |]
180 b1e81520 Iustin Pop
  , simpleField "drained"          [t| Bool   |]
181 b1e81520 Iustin Pop
  , simpleField "group"            [t| String |]
182 b1e81520 Iustin Pop
  , simpleField "master_capable"   [t| Bool   |]
183 b1e81520 Iustin Pop
  , simpleField "vm_capable"       [t| Bool   |]
184 b1e81520 Iustin Pop
--  , simpleField "ndparams"       [t| PartialNDParams |]
185 b1e81520 Iustin Pop
  , simpleField "powered"          [t| Bool   |]
186 b1e81520 Iustin Pop
  ]
187 b1e81520 Iustin Pop
  ++ timeStampFields
188 b1e81520 Iustin Pop
  ++ uuidFields
189 b1e81520 Iustin Pop
  ++ serialFields)
190 b1e81520 Iustin Pop
191 b1e81520 Iustin Pop
-- * NodeGroup definitions
192 b1e81520 Iustin Pop
193 b1e81520 Iustin Pop
-- | The Group allocation policy type.
194 b1e81520 Iustin Pop
--
195 b1e81520 Iustin Pop
-- Note that the order of constructors is important as the automatic
196 b1e81520 Iustin Pop
-- Ord instance will order them in the order they are defined, so when
197 b1e81520 Iustin Pop
-- changing this data type be careful about the interaction with the
198 b1e81520 Iustin Pop
-- desired sorting order.
199 b1e81520 Iustin Pop
--
200 b1e81520 Iustin Pop
-- FIXME: COPIED from Types.hs; we need to eliminate this duplication later
201 b1e81520 Iustin Pop
$(declareSADT "AllocPolicy"
202 b1e81520 Iustin Pop
  [ ("AllocPreferred",   'C.allocPolicyPreferred)
203 b1e81520 Iustin Pop
  , ("AllocLastResort",  'C.allocPolicyLastResort)
204 b1e81520 Iustin Pop
  , ("AllocUnallocable", 'C.allocPolicyUnallocable)
205 b1e81520 Iustin Pop
  ])
206 b1e81520 Iustin Pop
$(makeJSONInstance ''AllocPolicy)
207 b1e81520 Iustin Pop
208 b1e81520 Iustin Pop
$(buildObject "NodeGroup" "group" $
209 b1e81520 Iustin Pop
  [ simpleField "name"         [t| String |]
210 b1e81520 Iustin Pop
  , defaultField  [| [] |] $ simpleField "members" [t| [String] |]
211 b1e81520 Iustin Pop
--  , simpleField "ndparams"   [t| PartialNDParams |]
212 b1e81520 Iustin Pop
  , simpleField "alloc_policy" [t| AllocPolicy |]
213 b1e81520 Iustin Pop
  ]
214 b1e81520 Iustin Pop
  ++ timeStampFields
215 b1e81520 Iustin Pop
  ++ uuidFields
216 b1e81520 Iustin Pop
  ++ serialFields)
217 b1e81520 Iustin Pop
218 b1e81520 Iustin Pop
-- * Cluster definitions
219 b1e81520 Iustin Pop
$(buildObject "Cluster" "cluster" $
220 b1e81520 Iustin Pop
  [ simpleField "rsahostkeypub"             [t| String   |]
221 b1e81520 Iustin Pop
  , simpleField "highest_used_port"         [t| Int      |]
222 b1e81520 Iustin Pop
  , simpleField "tcpudp_port_pool"          [t| [Int]    |]
223 b1e81520 Iustin Pop
  , simpleField "mac_prefix"                [t| String   |]
224 b1e81520 Iustin Pop
  , simpleField "volume_group_name"         [t| String   |]
225 b1e81520 Iustin Pop
  , simpleField "reserved_lvs"              [t| [String] |]
226 b1e81520 Iustin Pop
--  , simpleField "drbd_usermode_helper"      [t| String   |]
227 b1e81520 Iustin Pop
-- , simpleField "default_bridge"          [t| String   |]
228 b1e81520 Iustin Pop
-- , simpleField "default_hypervisor"      [t| String   |]
229 b1e81520 Iustin Pop
  , simpleField "master_node"               [t| String   |]
230 b1e81520 Iustin Pop
  , simpleField "master_ip"                 [t| String   |]
231 b1e81520 Iustin Pop
  , simpleField "master_netdev"             [t| String   |]
232 b1e81520 Iustin Pop
-- , simpleField "master_netmask"          [t| String   |]
233 b1e81520 Iustin Pop
  , simpleField "cluster_name"              [t| String   |]
234 b1e81520 Iustin Pop
  , simpleField "file_storage_dir"          [t| String   |]
235 b1e81520 Iustin Pop
-- , simpleField "shared_file_storage_dir" [t| String   |]
236 b1e81520 Iustin Pop
  , simpleField "enabled_hypervisors"       [t| [String] |]
237 b1e81520 Iustin Pop
-- , simpleField "hvparams"                [t| [(String, [(String, String)])] |]
238 b1e81520 Iustin Pop
-- , simpleField "os_hvp"                  [t| [(String, String)] |]
239 b1e81520 Iustin Pop
  , containerField $ simpleField "beparams" [t| FilledBEParams |]
240 b1e81520 Iustin Pop
-- , simpleField "osparams"                [t| [(String, String)] |]
241 b1e81520 Iustin Pop
  , containerField $ simpleField "nicparams" [t| FilledNICParams    |]
242 b1e81520 Iustin Pop
--  , simpleField "ndparams"                  [t| FilledNDParams |]
243 b1e81520 Iustin Pop
  , simpleField "candidate_pool_size"       [t| Int                |]
244 b1e81520 Iustin Pop
  , simpleField "modify_etc_hosts"          [t| Bool               |]
245 b1e81520 Iustin Pop
  , simpleField "modify_ssh_setup"          [t| Bool               |]
246 b1e81520 Iustin Pop
  , simpleField "maintain_node_health"      [t| Bool               |]
247 b1e81520 Iustin Pop
  , simpleField "uid_pool"                  [t| [Int]              |]
248 b1e81520 Iustin Pop
  , simpleField "default_iallocator"        [t| String             |]
249 b1e81520 Iustin Pop
  , simpleField "hidden_os"                 [t| [String]           |]
250 b1e81520 Iustin Pop
  , simpleField "blacklisted_os"            [t| [String]           |]
251 b1e81520 Iustin Pop
  , simpleField "primary_ip_family"         [t| Int                |]
252 b1e81520 Iustin Pop
  , simpleField "prealloc_wipe_disks"       [t| Bool               |]
253 b1e81520 Iustin Pop
 ]
254 b1e81520 Iustin Pop
 ++ serialFields)
255 b1e81520 Iustin Pop
256 b1e81520 Iustin Pop
-- * ConfigData definitions
257 b1e81520 Iustin Pop
258 b1e81520 Iustin Pop
$(buildObject "ConfigData" "config" $
259 b1e81520 Iustin Pop
--  timeStampFields ++
260 b1e81520 Iustin Pop
  [ simpleField "version"       [t| Int                |]
261 b1e81520 Iustin Pop
  , simpleField "cluster"       [t| Cluster            |]
262 b1e81520 Iustin Pop
  , containerField $ simpleField "nodes"      [t| Node     |]
263 b1e81520 Iustin Pop
  , containerField $ simpleField "nodegroups" [t| NodeGroup |]
264 b1e81520 Iustin Pop
  , containerField $ simpleField "instances"  [t| Instance |]
265 b1e81520 Iustin Pop
  ]
266 b1e81520 Iustin Pop
  ++ serialFields)