Statistics
| Branch: | Tag: | Revision:

root / htools / Ganeti / Objects.hs @ adb77e3a

History | View | Annotate | Download (17.1 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 2e12944a Iustin Pop
  , DiskLogicalId(..)
40 b1e81520 Iustin Pop
  , Disk(..)
41 b1e81520 Iustin Pop
  , DiskTemplate(..)
42 b1e81520 Iustin Pop
  , PartialBEParams(..)
43 b1e81520 Iustin Pop
  , FilledBEParams(..)
44 b1e81520 Iustin Pop
  , fillBEParams
45 c4f65a0e Agata Murawska
  , Hypervisor(..)
46 c4f65a0e Agata Murawska
  , AdminState(..)
47 c4f65a0e Agata Murawska
  , adminStateFromRaw
48 b1e81520 Iustin Pop
  , Instance(..)
49 b1e81520 Iustin Pop
  , toDictInstance
50 b1e81520 Iustin Pop
  , PartialNDParams(..)
51 b1e81520 Iustin Pop
  , FilledNDParams(..)
52 b1e81520 Iustin Pop
  , fillNDParams
53 b1e81520 Iustin Pop
  , Node(..)
54 b1e81520 Iustin Pop
  , AllocPolicy(..)
55 7514fe92 Iustin Pop
  , FilledISpecParams(..)
56 7514fe92 Iustin Pop
  , PartialISpecParams(..)
57 7514fe92 Iustin Pop
  , fillISpecParams
58 7514fe92 Iustin Pop
  , FilledIPolicy(..)
59 7514fe92 Iustin Pop
  , PartialIPolicy(..)
60 7514fe92 Iustin Pop
  , fillIPolicy
61 b1e81520 Iustin Pop
  , NodeGroup(..)
62 a957e150 Iustin Pop
  , IpFamily(..)
63 a957e150 Iustin Pop
  , ipFamilyToVersion
64 adb77e3a Iustin Pop
  , fillDict
65 b1e81520 Iustin Pop
  , Cluster(..)
66 b1e81520 Iustin Pop
  , ConfigData(..)
67 b1e81520 Iustin Pop
  ) where
68 b1e81520 Iustin Pop
69 adb77e3a Iustin Pop
import Data.List (foldl')
70 b1e81520 Iustin Pop
import Data.Maybe
71 adb77e3a Iustin Pop
import qualified Data.Map as Map
72 2e12944a Iustin Pop
import Text.JSON (makeObj, showJSON, readJSON, JSON, JSValue(..))
73 2e12944a Iustin Pop
import qualified Text.JSON as J
74 b1e81520 Iustin Pop
75 b1e81520 Iustin Pop
import qualified Ganeti.Constants as C
76 b1e81520 Iustin Pop
import Ganeti.HTools.JSON
77 b1e81520 Iustin Pop
78 b1e81520 Iustin Pop
import Ganeti.THH
79 b1e81520 Iustin Pop
80 adb77e3a Iustin Pop
-- * Generic definitions
81 adb77e3a Iustin Pop
82 adb77e3a Iustin Pop
-- | Fills one map with keys from the other map, if not already
83 adb77e3a Iustin Pop
-- existing. Mirrors objects.py:FillDict.
84 adb77e3a Iustin Pop
fillDict :: (Ord k) => Map.Map k v -> Map.Map k v -> [k] -> Map.Map k v
85 adb77e3a Iustin Pop
fillDict defaults custom skip_keys =
86 adb77e3a Iustin Pop
  let updated = Map.union custom defaults
87 adb77e3a Iustin Pop
  in foldl' (flip Map.delete) updated skip_keys
88 adb77e3a Iustin Pop
89 b1e81520 Iustin Pop
-- * NIC definitions
90 b1e81520 Iustin Pop
91 b1e81520 Iustin Pop
$(declareSADT "NICMode"
92 b1e81520 Iustin Pop
  [ ("NMBridged", 'C.nicModeBridged)
93 b1e81520 Iustin Pop
  , ("NMRouted",  'C.nicModeRouted)
94 b1e81520 Iustin Pop
  ])
95 b1e81520 Iustin Pop
$(makeJSONInstance ''NICMode)
96 b1e81520 Iustin Pop
97 b1e81520 Iustin Pop
$(buildParam "NIC" "nicp"
98 b1e81520 Iustin Pop
  [ simpleField "mode" [t| NICMode |]
99 b1e81520 Iustin Pop
  , simpleField "link" [t| String  |]
100 b1e81520 Iustin Pop
  ])
101 b1e81520 Iustin Pop
102 b1e81520 Iustin Pop
$(buildObject "PartialNIC" "nic"
103 b1e81520 Iustin Pop
  [ simpleField "mac" [t| String |]
104 b1e81520 Iustin Pop
  , optionalField $ simpleField "ip" [t| String |]
105 b1e81520 Iustin Pop
  , simpleField "nicparams" [t| PartialNICParams |]
106 b1e81520 Iustin Pop
  ])
107 b1e81520 Iustin Pop
108 b1e81520 Iustin Pop
-- * Disk definitions
109 b1e81520 Iustin Pop
110 b1e81520 Iustin Pop
$(declareSADT "DiskMode"
111 b1e81520 Iustin Pop
  [ ("DiskRdOnly", 'C.diskRdonly)
112 b1e81520 Iustin Pop
  , ("DiskRdWr",   'C.diskRdwr)
113 b1e81520 Iustin Pop
  ])
114 b1e81520 Iustin Pop
$(makeJSONInstance ''DiskMode)
115 b1e81520 Iustin Pop
116 b1e81520 Iustin Pop
$(declareSADT "DiskType"
117 b1e81520 Iustin Pop
  [ ("LD_LV",       'C.ldLv)
118 b1e81520 Iustin Pop
  , ("LD_DRBD8",    'C.ldDrbd8)
119 b1e81520 Iustin Pop
  , ("LD_FILE",     'C.ldFile)
120 b1e81520 Iustin Pop
  , ("LD_BLOCKDEV", 'C.ldBlockdev)
121 2e12944a Iustin Pop
  , ("LD_RADOS",    'C.ldRbd)
122 b1e81520 Iustin Pop
  ])
123 b1e81520 Iustin Pop
$(makeJSONInstance ''DiskType)
124 b1e81520 Iustin Pop
125 2e12944a Iustin Pop
-- | The file driver type.
126 2e12944a Iustin Pop
$(declareSADT "FileDriver"
127 2e12944a Iustin Pop
  [ ("FileLoop",   'C.fdLoop)
128 2e12944a Iustin Pop
  , ("FileBlktap", 'C.fdBlktap)
129 2e12944a Iustin Pop
  ])
130 2e12944a Iustin Pop
$(makeJSONInstance ''FileDriver)
131 2e12944a Iustin Pop
132 2e12944a Iustin Pop
-- | The persistent block driver type. Currently only one type is allowed.
133 2e12944a Iustin Pop
$(declareSADT "BlockDriver"
134 2e12944a Iustin Pop
  [ ("BlockDrvManual", 'C.blockdevDriverManual)
135 2e12944a Iustin Pop
  ])
136 2e12944a Iustin Pop
$(makeJSONInstance ''BlockDriver)
137 2e12944a Iustin Pop
138 2e12944a Iustin Pop
-- | Constant for the dev_type key entry in the disk config.
139 2e12944a Iustin Pop
devType :: String
140 2e12944a Iustin Pop
devType = "dev_type"
141 2e12944a Iustin Pop
142 2e12944a Iustin Pop
-- | The disk configuration type. This includes the disk type itself,
143 2e12944a Iustin Pop
-- for a more complete consistency. Note that since in the Python
144 2e12944a Iustin Pop
-- code-base there's no authoritative place where we document the
145 2e12944a Iustin Pop
-- logical id, this is probably a good reference point.
146 2e12944a Iustin Pop
data DiskLogicalId
147 2e12944a Iustin Pop
  = LIDPlain String String  -- ^ Volume group, logical volume
148 2e12944a Iustin Pop
  | LIDDrbd8 String String Int Int Int String
149 2e12944a Iustin Pop
  -- ^ NodeA, NodeB, Port, MinorA, MinorB, Secret
150 2e12944a Iustin Pop
  | LIDFile FileDriver String -- ^ Driver, path
151 2e12944a Iustin Pop
  | LIDBlockDev BlockDriver String -- ^ Driver, path (must be under /dev)
152 2e12944a Iustin Pop
  | LIDRados String String -- ^ Unused, path
153 2e12944a Iustin Pop
    deriving (Read, Show, Eq)
154 2e12944a Iustin Pop
155 2e12944a Iustin Pop
-- | Mapping from a logical id to a disk type.
156 2e12944a Iustin Pop
lidDiskType :: DiskLogicalId -> DiskType
157 2e12944a Iustin Pop
lidDiskType (LIDPlain {}) = LD_LV
158 2e12944a Iustin Pop
lidDiskType (LIDDrbd8 {}) = LD_DRBD8
159 2e12944a Iustin Pop
lidDiskType (LIDFile  {}) = LD_FILE
160 2e12944a Iustin Pop
lidDiskType (LIDBlockDev {}) = LD_BLOCKDEV
161 2e12944a Iustin Pop
lidDiskType (LIDRados {}) = LD_RADOS
162 2e12944a Iustin Pop
163 2e12944a Iustin Pop
-- | Builds the extra disk_type field for a given logical id.
164 2e12944a Iustin Pop
lidEncodeType :: DiskLogicalId -> [(String, JSValue)]
165 2e12944a Iustin Pop
lidEncodeType v = [(devType, showJSON . lidDiskType $ v)]
166 2e12944a Iustin Pop
167 2e12944a Iustin Pop
-- | Custom encoder for DiskLogicalId (logical id only).
168 2e12944a Iustin Pop
encodeDLId :: DiskLogicalId -> JSValue
169 2e12944a Iustin Pop
encodeDLId (LIDPlain vg lv) = JSArray [showJSON vg, showJSON lv]
170 2e12944a Iustin Pop
encodeDLId (LIDDrbd8 nodeA nodeB port minorA minorB key) =
171 2e12944a Iustin Pop
  JSArray [ showJSON nodeA, showJSON nodeB, showJSON port
172 2e12944a Iustin Pop
          , showJSON minorA, showJSON minorB, showJSON key ]
173 2e12944a Iustin Pop
encodeDLId (LIDRados pool name) = JSArray [showJSON pool, showJSON name]
174 2e12944a Iustin Pop
encodeDLId (LIDFile driver name) = JSArray [showJSON driver, showJSON name]
175 2e12944a Iustin Pop
encodeDLId (LIDBlockDev driver name) = JSArray [showJSON driver, showJSON name]
176 2e12944a Iustin Pop
177 2e12944a Iustin Pop
-- | Custom encoder for DiskLogicalId, composing both the logical id
178 2e12944a Iustin Pop
-- and the extra disk_type field.
179 2e12944a Iustin Pop
encodeFullDLId :: DiskLogicalId -> (JSValue, [(String, JSValue)])
180 2e12944a Iustin Pop
encodeFullDLId v = (encodeDLId v, lidEncodeType v)
181 2e12944a Iustin Pop
182 2e12944a Iustin Pop
-- | Custom decoder for DiskLogicalId. This is manual for now, since
183 2e12944a Iustin Pop
-- we don't have yet automation for separate-key style fields.
184 2e12944a Iustin Pop
decodeDLId :: [(String, JSValue)] -> JSValue -> J.Result DiskLogicalId
185 2e12944a Iustin Pop
decodeDLId obj lid = do
186 2e12944a Iustin Pop
  dtype <- fromObj obj devType
187 2e12944a Iustin Pop
  case dtype of
188 2e12944a Iustin Pop
    LD_DRBD8 ->
189 2e12944a Iustin Pop
      case lid of
190 2e12944a Iustin Pop
        JSArray [nA, nB, p, mA, mB, k] -> do
191 2e12944a Iustin Pop
          nA' <- readJSON nA
192 2e12944a Iustin Pop
          nB' <- readJSON nB
193 2e12944a Iustin Pop
          p'  <- readJSON p
194 2e12944a Iustin Pop
          mA' <- readJSON mA
195 2e12944a Iustin Pop
          mB' <- readJSON mB
196 2e12944a Iustin Pop
          k'  <- readJSON k
197 2e12944a Iustin Pop
          return $ LIDDrbd8 nA' nB' p' mA' mB' k'
198 2e12944a Iustin Pop
        _ -> fail $ "Can't read logical_id for DRBD8 type"
199 2e12944a Iustin Pop
    LD_LV ->
200 2e12944a Iustin Pop
      case lid of
201 2e12944a Iustin Pop
        JSArray [vg, lv] -> do
202 2e12944a Iustin Pop
          vg' <- readJSON vg
203 2e12944a Iustin Pop
          lv' <- readJSON lv
204 2e12944a Iustin Pop
          return $ LIDPlain vg' lv'
205 2e12944a Iustin Pop
        _ -> fail $ "Can't read logical_id for plain type"
206 2e12944a Iustin Pop
    LD_FILE ->
207 2e12944a Iustin Pop
      case lid of
208 2e12944a Iustin Pop
        JSArray [driver, path] -> do
209 2e12944a Iustin Pop
          driver' <- readJSON driver
210 2e12944a Iustin Pop
          path'   <- readJSON path
211 2e12944a Iustin Pop
          return $ LIDFile driver' path'
212 2e12944a Iustin Pop
        _ -> fail $ "Can't read logical_id for file type"
213 2e12944a Iustin Pop
    LD_BLOCKDEV ->
214 2e12944a Iustin Pop
      case lid of
215 2e12944a Iustin Pop
        JSArray [driver, path] -> do
216 2e12944a Iustin Pop
          driver' <- readJSON driver
217 2e12944a Iustin Pop
          path'   <- readJSON path
218 2e12944a Iustin Pop
          return $ LIDBlockDev driver' path'
219 2e12944a Iustin Pop
        _ -> fail $ "Can't read logical_id for blockdev type"
220 2e12944a Iustin Pop
    LD_RADOS ->
221 2e12944a Iustin Pop
      case lid of
222 2e12944a Iustin Pop
        JSArray [driver, path] -> do
223 2e12944a Iustin Pop
          driver' <- readJSON driver
224 2e12944a Iustin Pop
          path'   <- readJSON path
225 2e12944a Iustin Pop
          return $ LIDRados driver' path'
226 2e12944a Iustin Pop
        _ -> fail $ "Can't read logical_id for rdb type"
227 2e12944a Iustin Pop
228 b1e81520 Iustin Pop
-- | Disk data structure.
229 b1e81520 Iustin Pop
--
230 b1e81520 Iustin Pop
-- This is declared manually as it's a recursive structure, and our TH
231 b1e81520 Iustin Pop
-- code currently can't build it.
232 b1e81520 Iustin Pop
data Disk = Disk
233 2e12944a Iustin Pop
  { diskLogicalId  :: DiskLogicalId
234 b1e81520 Iustin Pop
--  , diskPhysicalId :: String
235 b1e81520 Iustin Pop
  , diskChildren   :: [Disk]
236 b1e81520 Iustin Pop
  , diskIvName     :: String
237 b1e81520 Iustin Pop
  , diskSize       :: Int
238 b1e81520 Iustin Pop
  , diskMode       :: DiskMode
239 b1e81520 Iustin Pop
  } deriving (Read, Show, Eq)
240 b1e81520 Iustin Pop
241 b1e81520 Iustin Pop
$(buildObjectSerialisation "Disk"
242 2e12944a Iustin Pop
  [ customField 'decodeDLId 'encodeFullDLId $
243 2e12944a Iustin Pop
      simpleField "logical_id"    [t| DiskLogicalId   |]
244 b1e81520 Iustin Pop
--  , simpleField "physical_id" [t| String   |]
245 b1e81520 Iustin Pop
  , defaultField  [| [] |] $ simpleField "children" [t| [Disk] |]
246 b1e81520 Iustin Pop
  , defaultField [| "" |] $ simpleField "iv_name" [t| String |]
247 b1e81520 Iustin Pop
  , simpleField "size" [t| Int |]
248 b1e81520 Iustin Pop
  , defaultField [| DiskRdWr |] $ simpleField "mode" [t| DiskMode |]
249 b1e81520 Iustin Pop
  ])
250 b1e81520 Iustin Pop
251 c4f65a0e Agata Murawska
-- * Hypervisor definitions
252 c4f65a0e Agata Murawska
253 c4f65a0e Agata Murawska
-- | This may be due to change when we add hypervisor parameters.
254 c4f65a0e Agata Murawska
$(declareSADT "Hypervisor"
255 c4f65a0e Agata Murawska
  [ ( "Kvm",    'C.htKvm )
256 c4f65a0e Agata Murawska
  , ( "XenPvm", 'C.htXenPvm )
257 c4f65a0e Agata Murawska
  , ( "Chroot", 'C.htChroot )
258 c4f65a0e Agata Murawska
  , ( "XenHvm", 'C.htXenHvm )
259 c4f65a0e Agata Murawska
  , ( "Lxc",    'C.htLxc )
260 c4f65a0e Agata Murawska
  , ( "Fake",   'C.htFake )
261 c4f65a0e Agata Murawska
  ])
262 c4f65a0e Agata Murawska
$(makeJSONInstance ''Hypervisor)
263 c4f65a0e Agata Murawska
264 b1e81520 Iustin Pop
-- * Instance definitions
265 b1e81520 Iustin Pop
266 b1e81520 Iustin Pop
-- | Instance disk template type. **Copied from HTools/Types.hs**
267 b1e81520 Iustin Pop
$(declareSADT "DiskTemplate"
268 b1e81520 Iustin Pop
  [ ("DTDiskless",   'C.dtDiskless)
269 b1e81520 Iustin Pop
  , ("DTFile",       'C.dtFile)
270 b1e81520 Iustin Pop
  , ("DTSharedFile", 'C.dtSharedFile)
271 b1e81520 Iustin Pop
  , ("DTPlain",      'C.dtPlain)
272 b1e81520 Iustin Pop
  , ("DTBlock",      'C.dtBlock)
273 b1e81520 Iustin Pop
  , ("DTDrbd8",      'C.dtDrbd8)
274 a957e150 Iustin Pop
  , ("DTRados",      'C.dtRbd)
275 b1e81520 Iustin Pop
  ])
276 b1e81520 Iustin Pop
$(makeJSONInstance ''DiskTemplate)
277 b1e81520 Iustin Pop
278 b1e81520 Iustin Pop
$(declareSADT "AdminState"
279 b1e81520 Iustin Pop
  [ ("AdminOffline", 'C.adminstOffline)
280 b1e81520 Iustin Pop
  , ("AdminDown",    'C.adminstDown)
281 b1e81520 Iustin Pop
  , ("AdminUp",      'C.adminstUp)
282 b1e81520 Iustin Pop
  ])
283 b1e81520 Iustin Pop
$(makeJSONInstance ''AdminState)
284 b1e81520 Iustin Pop
285 b1e81520 Iustin Pop
$(buildParam "BE" "bep" $
286 b1e81520 Iustin Pop
  [ simpleField "minmem"       [t| Int  |]
287 b1e81520 Iustin Pop
  , simpleField "maxmem"       [t| Int  |]
288 b1e81520 Iustin Pop
  , simpleField "vcpus"        [t| Int  |]
289 b1e81520 Iustin Pop
  , simpleField "auto_balance" [t| Bool |]
290 b1e81520 Iustin Pop
  ])
291 b1e81520 Iustin Pop
292 b1e81520 Iustin Pop
$(buildObject "Instance" "inst" $
293 b1e81520 Iustin Pop
  [ simpleField "name"           [t| String             |]
294 b1e81520 Iustin Pop
  , simpleField "primary_node"   [t| String             |]
295 b1e81520 Iustin Pop
  , simpleField "os"             [t| String             |]
296 b1e81520 Iustin Pop
  , simpleField "hypervisor"     [t| String             |]
297 b1e81520 Iustin Pop
--  , simpleField "hvparams"     [t| [(String, String)] |]
298 b1e81520 Iustin Pop
  , simpleField "beparams"       [t| PartialBEParams |]
299 b1e81520 Iustin Pop
--  , simpleField "osparams"     [t| [(String, String)] |]
300 b1e81520 Iustin Pop
  , simpleField "admin_state"    [t| AdminState         |]
301 b1e81520 Iustin Pop
  , simpleField "nics"           [t| [PartialNIC]              |]
302 b1e81520 Iustin Pop
  , simpleField "disks"          [t| [Disk]             |]
303 b1e81520 Iustin Pop
  , simpleField "disk_template"  [t| DiskTemplate       |]
304 b1e81520 Iustin Pop
  , optionalField $ simpleField "network_port" [t| Int |]
305 b1e81520 Iustin Pop
  ]
306 b1e81520 Iustin Pop
  ++ timeStampFields
307 b1e81520 Iustin Pop
  ++ uuidFields
308 f2374060 Iustin Pop
  ++ serialFields
309 f2374060 Iustin Pop
  ++ tagsFields)
310 b1e81520 Iustin Pop
311 7514fe92 Iustin Pop
-- * IPolicy definitions
312 7514fe92 Iustin Pop
313 7514fe92 Iustin Pop
$(buildParam "ISpec" "ispec" $
314 7514fe92 Iustin Pop
  [ simpleField C.ispecMemSize     [t| Int |]
315 7514fe92 Iustin Pop
  , simpleField C.ispecDiskSize    [t| Int |]
316 7514fe92 Iustin Pop
  , simpleField C.ispecDiskCount   [t| Int |]
317 7514fe92 Iustin Pop
  , simpleField C.ispecCpuCount    [t| Int |]
318 7514fe92 Iustin Pop
  , simpleField C.ispecSpindleUse  [t| Int |]
319 7514fe92 Iustin Pop
  ])
320 7514fe92 Iustin Pop
321 7514fe92 Iustin Pop
-- | Custom partial ipolicy. This is not built via buildParam since it
322 7514fe92 Iustin Pop
-- has a special 2-level inheritance mode.
323 7514fe92 Iustin Pop
$(buildObject "PartialIPolicy" "ipolicy" $
324 7514fe92 Iustin Pop
  [ renameField "MinSpecP" $ simpleField "min" [t| PartialISpecParams |]
325 7514fe92 Iustin Pop
  , renameField "MaxSpecP" $ simpleField "max" [t| PartialISpecParams |]
326 7514fe92 Iustin Pop
  , renameField "StdSpecP" $ simpleField "std" [t| PartialISpecParams |]
327 7514fe92 Iustin Pop
  , optionalField . renameField "SpindleRatioP"
328 7514fe92 Iustin Pop
                    $ simpleField "spindle-ratio"  [t| Double |]
329 7514fe92 Iustin Pop
  , optionalField . renameField "VcpuRatioP"
330 7514fe92 Iustin Pop
                    $ simpleField "vcpu-ratio"     [t| Double |]
331 7514fe92 Iustin Pop
  , optionalField . renameField "DiskTemplatesP"
332 7514fe92 Iustin Pop
                    $ simpleField "disk-templates" [t| [DiskTemplate] |]
333 7514fe92 Iustin Pop
  ])
334 7514fe92 Iustin Pop
335 7514fe92 Iustin Pop
-- | Custom filled ipolicy. This is not built via buildParam since it
336 7514fe92 Iustin Pop
-- has a special 2-level inheritance mode.
337 7514fe92 Iustin Pop
$(buildObject "FilledIPolicy" "ipolicy" $
338 7514fe92 Iustin Pop
  [ renameField "MinSpec" $ simpleField "min" [t| FilledISpecParams |]
339 7514fe92 Iustin Pop
  , renameField "MaxSpec" $ simpleField "max" [t| FilledISpecParams |]
340 7514fe92 Iustin Pop
  , renameField "StdSpec" $ simpleField "std" [t| FilledISpecParams |]
341 7514fe92 Iustin Pop
  , simpleField "spindle-ratio"  [t| Double |]
342 7514fe92 Iustin Pop
  , simpleField "vcpu-ratio"     [t| Double |]
343 7514fe92 Iustin Pop
  , simpleField "disk-templates" [t| [DiskTemplate] |]
344 7514fe92 Iustin Pop
  ])
345 7514fe92 Iustin Pop
346 7514fe92 Iustin Pop
-- | Custom filler for the ipolicy types.
347 7514fe92 Iustin Pop
fillIPolicy :: FilledIPolicy -> PartialIPolicy -> FilledIPolicy
348 7514fe92 Iustin Pop
fillIPolicy (FilledIPolicy { ipolicyMinSpec       = fmin
349 7514fe92 Iustin Pop
                           , ipolicyMaxSpec       = fmax
350 7514fe92 Iustin Pop
                           , ipolicyStdSpec       = fstd
351 7514fe92 Iustin Pop
                           , ipolicySpindleRatio  = fspindleRatio
352 7514fe92 Iustin Pop
                           , ipolicyVcpuRatio     = fvcpuRatio
353 7514fe92 Iustin Pop
                           , ipolicyDiskTemplates = fdiskTemplates})
354 7514fe92 Iustin Pop
            (PartialIPolicy { ipolicyMinSpecP       = pmin
355 7514fe92 Iustin Pop
                            , ipolicyMaxSpecP       = pmax
356 7514fe92 Iustin Pop
                            , ipolicyStdSpecP       = pstd
357 7514fe92 Iustin Pop
                            , ipolicySpindleRatioP  = pspindleRatio
358 7514fe92 Iustin Pop
                            , ipolicyVcpuRatioP     = pvcpuRatio
359 7514fe92 Iustin Pop
                            , ipolicyDiskTemplatesP = pdiskTemplates}) =
360 7514fe92 Iustin Pop
  FilledIPolicy { ipolicyMinSpec       = fillISpecParams fmin pmin
361 7514fe92 Iustin Pop
                , ipolicyMaxSpec       = fillISpecParams fmax pmax
362 7514fe92 Iustin Pop
                , ipolicyStdSpec       = fillISpecParams fstd pstd
363 7514fe92 Iustin Pop
                , ipolicySpindleRatio  = fromMaybe fspindleRatio pspindleRatio
364 7514fe92 Iustin Pop
                , ipolicyVcpuRatio     = fromMaybe fvcpuRatio pvcpuRatio
365 7514fe92 Iustin Pop
                , ipolicyDiskTemplates = fromMaybe fdiskTemplates
366 7514fe92 Iustin Pop
                                         pdiskTemplates
367 7514fe92 Iustin Pop
                }
368 b1e81520 Iustin Pop
-- * Node definitions
369 b1e81520 Iustin Pop
370 b1e81520 Iustin Pop
$(buildParam "ND" "ndp" $
371 7514fe92 Iustin Pop
  [ simpleField "oob_program"   [t| String |]
372 7514fe92 Iustin Pop
  , simpleField "spindle_count" [t| Int    |]
373 b1e81520 Iustin Pop
  ])
374 b1e81520 Iustin Pop
375 b1e81520 Iustin Pop
$(buildObject "Node" "node" $
376 b1e81520 Iustin Pop
  [ simpleField "name"             [t| String |]
377 b1e81520 Iustin Pop
  , simpleField "primary_ip"       [t| String |]
378 b1e81520 Iustin Pop
  , simpleField "secondary_ip"     [t| String |]
379 b1e81520 Iustin Pop
  , simpleField "master_candidate" [t| Bool   |]
380 b1e81520 Iustin Pop
  , simpleField "offline"          [t| Bool   |]
381 b1e81520 Iustin Pop
  , simpleField "drained"          [t| Bool   |]
382 b1e81520 Iustin Pop
  , simpleField "group"            [t| String |]
383 b1e81520 Iustin Pop
  , simpleField "master_capable"   [t| Bool   |]
384 b1e81520 Iustin Pop
  , simpleField "vm_capable"       [t| Bool   |]
385 a957e150 Iustin Pop
  , simpleField "ndparams"         [t| PartialNDParams |]
386 b1e81520 Iustin Pop
  , simpleField "powered"          [t| Bool   |]
387 b1e81520 Iustin Pop
  ]
388 b1e81520 Iustin Pop
  ++ timeStampFields
389 b1e81520 Iustin Pop
  ++ uuidFields
390 f2374060 Iustin Pop
  ++ serialFields
391 f2374060 Iustin Pop
  ++ tagsFields)
392 b1e81520 Iustin Pop
393 b1e81520 Iustin Pop
-- * NodeGroup definitions
394 b1e81520 Iustin Pop
395 b1e81520 Iustin Pop
-- | The Group allocation policy type.
396 b1e81520 Iustin Pop
--
397 b1e81520 Iustin Pop
-- Note that the order of constructors is important as the automatic
398 b1e81520 Iustin Pop
-- Ord instance will order them in the order they are defined, so when
399 b1e81520 Iustin Pop
-- changing this data type be careful about the interaction with the
400 b1e81520 Iustin Pop
-- desired sorting order.
401 b1e81520 Iustin Pop
--
402 b1e81520 Iustin Pop
-- FIXME: COPIED from Types.hs; we need to eliminate this duplication later
403 b1e81520 Iustin Pop
$(declareSADT "AllocPolicy"
404 b1e81520 Iustin Pop
  [ ("AllocPreferred",   'C.allocPolicyPreferred)
405 b1e81520 Iustin Pop
  , ("AllocLastResort",  'C.allocPolicyLastResort)
406 b1e81520 Iustin Pop
  , ("AllocUnallocable", 'C.allocPolicyUnallocable)
407 b1e81520 Iustin Pop
  ])
408 b1e81520 Iustin Pop
$(makeJSONInstance ''AllocPolicy)
409 b1e81520 Iustin Pop
410 b1e81520 Iustin Pop
$(buildObject "NodeGroup" "group" $
411 b1e81520 Iustin Pop
  [ simpleField "name"         [t| String |]
412 b1e81520 Iustin Pop
  , defaultField  [| [] |] $ simpleField "members" [t| [String] |]
413 a957e150 Iustin Pop
  , simpleField "ndparams"     [t| PartialNDParams |]
414 7514fe92 Iustin Pop
  , simpleField "alloc_policy" [t| AllocPolicy     |]
415 7514fe92 Iustin Pop
  , simpleField "ipolicy"      [t| PartialIPolicy  |]
416 b1e81520 Iustin Pop
  ]
417 b1e81520 Iustin Pop
  ++ timeStampFields
418 b1e81520 Iustin Pop
  ++ uuidFields
419 f2374060 Iustin Pop
  ++ serialFields
420 f2374060 Iustin Pop
  ++ tagsFields)
421 b1e81520 Iustin Pop
422 a957e150 Iustin Pop
-- | IP family type
423 a957e150 Iustin Pop
$(declareIADT "IpFamily"
424 a957e150 Iustin Pop
  [ ("IpFamilyV4", 'C.ip4Family)
425 a957e150 Iustin Pop
  , ("IpFamilyV6", 'C.ip6Family)
426 a957e150 Iustin Pop
  ])
427 a957e150 Iustin Pop
$(makeJSONInstance ''IpFamily)
428 a957e150 Iustin Pop
429 a957e150 Iustin Pop
-- | Conversion from IP family to IP version. This is needed because
430 a957e150 Iustin Pop
-- Python uses both, depending on context.
431 a957e150 Iustin Pop
ipFamilyToVersion :: IpFamily -> Int
432 a957e150 Iustin Pop
ipFamilyToVersion IpFamilyV4 = C.ip4Version
433 a957e150 Iustin Pop
ipFamilyToVersion IpFamilyV6 = C.ip6Version
434 a957e150 Iustin Pop
435 b1e81520 Iustin Pop
-- * Cluster definitions
436 b1e81520 Iustin Pop
$(buildObject "Cluster" "cluster" $
437 b1e81520 Iustin Pop
  [ simpleField "rsahostkeypub"             [t| String   |]
438 b1e81520 Iustin Pop
  , simpleField "highest_used_port"         [t| Int      |]
439 b1e81520 Iustin Pop
  , simpleField "tcpudp_port_pool"          [t| [Int]    |]
440 b1e81520 Iustin Pop
  , simpleField "mac_prefix"                [t| String   |]
441 b1e81520 Iustin Pop
  , simpleField "volume_group_name"         [t| String   |]
442 b1e81520 Iustin Pop
  , simpleField "reserved_lvs"              [t| [String] |]
443 a957e150 Iustin Pop
  , optionalField $ simpleField "drbd_usermode_helper" [t| String |]
444 b1e81520 Iustin Pop
-- , simpleField "default_bridge"          [t| String   |]
445 b1e81520 Iustin Pop
-- , simpleField "default_hypervisor"      [t| String   |]
446 b1e81520 Iustin Pop
  , simpleField "master_node"               [t| String   |]
447 b1e81520 Iustin Pop
  , simpleField "master_ip"                 [t| String   |]
448 b1e81520 Iustin Pop
  , simpleField "master_netdev"             [t| String   |]
449 a957e150 Iustin Pop
  , simpleField "master_netmask"            [t| Int   |]
450 a957e150 Iustin Pop
  , simpleField "use_external_mip_script"   [t| Bool |]
451 b1e81520 Iustin Pop
  , simpleField "cluster_name"              [t| String   |]
452 b1e81520 Iustin Pop
  , simpleField "file_storage_dir"          [t| String   |]
453 a957e150 Iustin Pop
  , simpleField "shared_file_storage_dir"   [t| String   |]
454 b1e81520 Iustin Pop
  , simpleField "enabled_hypervisors"       [t| [String] |]
455 b1e81520 Iustin Pop
-- , simpleField "hvparams"                [t| [(String, [(String, String)])] |]
456 b1e81520 Iustin Pop
-- , simpleField "os_hvp"                  [t| [(String, String)] |]
457 d5a93a80 Iustin Pop
  , simpleField "beparams" [t| Container FilledBEParams |]
458 a957e150 Iustin Pop
  , simpleField "osparams"                  [t| Container (Container String) |]
459 d5a93a80 Iustin Pop
  , simpleField "nicparams" [t| Container FilledNICParams    |]
460 a957e150 Iustin Pop
  , simpleField "ndparams"                  [t| FilledNDParams |]
461 b1e81520 Iustin Pop
  , simpleField "candidate_pool_size"       [t| Int                |]
462 b1e81520 Iustin Pop
  , simpleField "modify_etc_hosts"          [t| Bool               |]
463 b1e81520 Iustin Pop
  , simpleField "modify_ssh_setup"          [t| Bool               |]
464 b1e81520 Iustin Pop
  , simpleField "maintain_node_health"      [t| Bool               |]
465 a957e150 Iustin Pop
  , simpleField "uid_pool"                  [t| [(Int, Int)]       |]
466 b1e81520 Iustin Pop
  , simpleField "default_iallocator"        [t| String             |]
467 b1e81520 Iustin Pop
  , simpleField "hidden_os"                 [t| [String]           |]
468 b1e81520 Iustin Pop
  , simpleField "blacklisted_os"            [t| [String]           |]
469 a957e150 Iustin Pop
  , simpleField "primary_ip_family"         [t| IpFamily           |]
470 b1e81520 Iustin Pop
  , simpleField "prealloc_wipe_disks"       [t| Bool               |]
471 7514fe92 Iustin Pop
  , simpleField "ipolicy"                   [t| FilledIPolicy      |]
472 b1e81520 Iustin Pop
 ]
473 02cccecd Iustin Pop
 ++ serialFields
474 02cccecd Iustin Pop
 ++ timeStampFields
475 02cccecd Iustin Pop
 ++ uuidFields
476 02cccecd Iustin Pop
 ++ tagsFields)
477 b1e81520 Iustin Pop
478 b1e81520 Iustin Pop
-- * ConfigData definitions
479 b1e81520 Iustin Pop
480 b1e81520 Iustin Pop
$(buildObject "ConfigData" "config" $
481 b1e81520 Iustin Pop
--  timeStampFields ++
482 d5a93a80 Iustin Pop
  [ simpleField "version"    [t| Int                 |]
483 d5a93a80 Iustin Pop
  , simpleField "cluster"    [t| Cluster             |]
484 d5a93a80 Iustin Pop
  , simpleField "nodes"      [t| Container Node      |]
485 d5a93a80 Iustin Pop
  , simpleField "nodegroups" [t| Container NodeGroup |]
486 d5a93a80 Iustin Pop
  , simpleField "instances"  [t| Container Instance  |]
487 b1e81520 Iustin Pop
  ]
488 b1e81520 Iustin Pop
  ++ serialFields)