Statistics
| Branch: | Tag: | Revision:

root / src / Ganeti / Objects.hs @ f0e4b2a4

History | View | Annotate | Download (24.6 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 3a991f2d Iustin Pop
Copyright (C) 2011, 2012, 2013 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 9d4cc8ed Iustin Pop
  ( VType(..)
33 9d4cc8ed Iustin Pop
  , vTypeFromRaw
34 9d4cc8ed Iustin Pop
  , HvParams
35 b09cce64 Iustin Pop
  , OsParams
36 b09cce64 Iustin Pop
  , PartialNicParams(..)
37 b09cce64 Iustin Pop
  , FilledNicParams(..)
38 b09cce64 Iustin Pop
  , fillNicParams
39 2af78b97 Iustin Pop
  , allNicParamFields
40 b09cce64 Iustin Pop
  , PartialNic(..)
41 8d2b6a12 Iustin Pop
  , FileDriver(..)
42 8d2b6a12 Iustin Pop
  , BlockDriver(..)
43 b1e81520 Iustin Pop
  , DiskMode(..)
44 b1e81520 Iustin Pop
  , DiskType(..)
45 2e12944a Iustin Pop
  , DiskLogicalId(..)
46 b1e81520 Iustin Pop
  , Disk(..)
47 b1e81520 Iustin Pop
  , DiskTemplate(..)
48 b09cce64 Iustin Pop
  , PartialBeParams(..)
49 b09cce64 Iustin Pop
  , FilledBeParams(..)
50 b09cce64 Iustin Pop
  , fillBeParams
51 2af78b97 Iustin Pop
  , allBeParamFields
52 c4f65a0e Agata Murawska
  , AdminState(..)
53 c4f65a0e Agata Murawska
  , adminStateFromRaw
54 b1e81520 Iustin Pop
  , Instance(..)
55 b1e81520 Iustin Pop
  , toDictInstance
56 b1e81520 Iustin Pop
  , PartialNDParams(..)
57 b1e81520 Iustin Pop
  , FilledNDParams(..)
58 b1e81520 Iustin Pop
  , fillNDParams
59 2af78b97 Iustin Pop
  , allNDParamFields
60 b1e81520 Iustin Pop
  , Node(..)
61 da45c352 Iustin Pop
  , NodeRole(..)
62 da45c352 Iustin Pop
  , nodeRoleToRaw
63 da45c352 Iustin Pop
  , roleDescription
64 b1e81520 Iustin Pop
  , AllocPolicy(..)
65 7514fe92 Iustin Pop
  , FilledISpecParams(..)
66 7514fe92 Iustin Pop
  , PartialISpecParams(..)
67 7514fe92 Iustin Pop
  , fillISpecParams
68 2af78b97 Iustin Pop
  , allISpecParamFields
69 da5f09ef Bernardo Dal Seno
  , FilledMinMaxISpecs(..)
70 da5f09ef Bernardo Dal Seno
  , PartialMinMaxISpecs(..)
71 da5f09ef Bernardo Dal Seno
  , fillMinMaxISpecs
72 7514fe92 Iustin Pop
  , FilledIPolicy(..)
73 7514fe92 Iustin Pop
  , PartialIPolicy(..)
74 7514fe92 Iustin Pop
  , fillIPolicy
75 b09cce64 Iustin Pop
  , DiskParams
76 b1e81520 Iustin Pop
  , NodeGroup(..)
77 a957e150 Iustin Pop
  , IpFamily(..)
78 a957e150 Iustin Pop
  , ipFamilyToVersion
79 adb77e3a Iustin Pop
  , fillDict
80 b09cce64 Iustin Pop
  , ClusterHvParams
81 b09cce64 Iustin Pop
  , OsHvParams
82 b09cce64 Iustin Pop
  , ClusterBeParams
83 b09cce64 Iustin Pop
  , ClusterOsParams
84 b09cce64 Iustin Pop
  , ClusterNicParams
85 b1e81520 Iustin Pop
  , Cluster(..)
86 b1e81520 Iustin Pop
  , ConfigData(..)
87 04dd53a3 Iustin Pop
  , TimeStampObject(..)
88 04dd53a3 Iustin Pop
  , UuidObject(..)
89 04dd53a3 Iustin Pop
  , SerialNoObject(..)
90 04dd53a3 Iustin Pop
  , TagsObject(..)
91 2af78b97 Iustin Pop
  , DictObject(..) -- re-exported from THH
92 9924d61e Iustin Pop
  , TagSet -- re-exported from THH
93 76a0266e Helga Velroyen
  , Network(..)
94 3a991f2d Iustin Pop
  , Ip4Address(..)
95 3a991f2d Iustin Pop
  , Ip4Network(..)
96 3a991f2d Iustin Pop
  , readIp4Address
97 3a991f2d Iustin Pop
  , nextIp4Address
98 b1e81520 Iustin Pop
  ) where
99 b1e81520 Iustin Pop
100 3a991f2d Iustin Pop
import Control.Applicative
101 adb77e3a Iustin Pop
import Data.List (foldl')
102 b1e81520 Iustin Pop
import Data.Maybe
103 adb77e3a Iustin Pop
import qualified Data.Map as Map
104 04dd53a3 Iustin Pop
import qualified Data.Set as Set
105 3a991f2d Iustin Pop
import Data.Word
106 3a991f2d Iustin Pop
import Text.JSON (showJSON, readJSON, JSON, JSValue(..), fromJSString)
107 2e12944a Iustin Pop
import qualified Text.JSON as J
108 b1e81520 Iustin Pop
109 b1e81520 Iustin Pop
import qualified Ganeti.Constants as C
110 f3baf5ef Iustin Pop
import Ganeti.JSON
111 5e9deac0 Iustin Pop
import Ganeti.Types
112 b1e81520 Iustin Pop
import Ganeti.THH
113 3a991f2d Iustin Pop
import Ganeti.Utils (sepSplit, tryRead)
114 b1e81520 Iustin Pop
115 adb77e3a Iustin Pop
-- * Generic definitions
116 adb77e3a Iustin Pop
117 adb77e3a Iustin Pop
-- | Fills one map with keys from the other map, if not already
118 adb77e3a Iustin Pop
-- existing. Mirrors objects.py:FillDict.
119 adb77e3a Iustin Pop
fillDict :: (Ord k) => Map.Map k v -> Map.Map k v -> [k] -> Map.Map k v
120 adb77e3a Iustin Pop
fillDict defaults custom skip_keys =
121 adb77e3a Iustin Pop
  let updated = Map.union custom defaults
122 adb77e3a Iustin Pop
  in foldl' (flip Map.delete) updated skip_keys
123 adb77e3a Iustin Pop
124 9d4cc8ed Iustin Pop
-- | The VTYPES, a mini-type system in Python.
125 9d4cc8ed Iustin Pop
$(declareSADT "VType"
126 9d4cc8ed Iustin Pop
  [ ("VTypeString",      'C.vtypeString)
127 9d4cc8ed Iustin Pop
  , ("VTypeMaybeString", 'C.vtypeMaybeString)
128 9d4cc8ed Iustin Pop
  , ("VTypeBool",        'C.vtypeBool)
129 9d4cc8ed Iustin Pop
  , ("VTypeSize",        'C.vtypeSize)
130 9d4cc8ed Iustin Pop
  , ("VTypeInt",         'C.vtypeInt)
131 9d4cc8ed Iustin Pop
  ])
132 9d4cc8ed Iustin Pop
$(makeJSONInstance ''VType)
133 9d4cc8ed Iustin Pop
134 b09cce64 Iustin Pop
-- | The hypervisor parameter type. This is currently a simple map,
135 b09cce64 Iustin Pop
-- without type checking on key/value pairs.
136 b09cce64 Iustin Pop
type HvParams = Container JSValue
137 b09cce64 Iustin Pop
138 b09cce64 Iustin Pop
-- | The OS parameters type. This is, and will remain, a string
139 b09cce64 Iustin Pop
-- container, since the keys are dynamically declared by the OSes, and
140 b09cce64 Iustin Pop
-- the values are always strings.
141 b09cce64 Iustin Pop
type OsParams = Container String
142 b09cce64 Iustin Pop
143 04dd53a3 Iustin Pop
-- | Class of objects that have timestamps.
144 04dd53a3 Iustin Pop
class TimeStampObject a where
145 04dd53a3 Iustin Pop
  cTimeOf :: a -> Double
146 04dd53a3 Iustin Pop
  mTimeOf :: a -> Double
147 04dd53a3 Iustin Pop
148 04dd53a3 Iustin Pop
-- | Class of objects that have an UUID.
149 04dd53a3 Iustin Pop
class UuidObject a where
150 04dd53a3 Iustin Pop
  uuidOf :: a -> String
151 04dd53a3 Iustin Pop
152 04dd53a3 Iustin Pop
-- | Class of object that have a serial number.
153 04dd53a3 Iustin Pop
class SerialNoObject a where
154 04dd53a3 Iustin Pop
  serialOf :: a -> Int
155 04dd53a3 Iustin Pop
156 04dd53a3 Iustin Pop
-- | Class of objects that have tags.
157 04dd53a3 Iustin Pop
class TagsObject a where
158 04dd53a3 Iustin Pop
  tagsOf :: a -> Set.Set String
159 04dd53a3 Iustin Pop
160 da45c352 Iustin Pop
-- * Node role object
161 da45c352 Iustin Pop
162 da45c352 Iustin Pop
$(declareSADT "NodeRole"
163 da45c352 Iustin Pop
  [ ("NROffline",   'C.nrOffline)
164 da45c352 Iustin Pop
  , ("NRDrained",   'C.nrDrained)
165 da45c352 Iustin Pop
  , ("NRRegular",   'C.nrRegular)
166 da45c352 Iustin Pop
  , ("NRCandidate", 'C.nrMcandidate)
167 da45c352 Iustin Pop
  , ("NRMaster",    'C.nrMaster)
168 da45c352 Iustin Pop
  ])
169 da45c352 Iustin Pop
$(makeJSONInstance ''NodeRole)
170 da45c352 Iustin Pop
171 da45c352 Iustin Pop
-- | The description of the node role.
172 da45c352 Iustin Pop
roleDescription :: NodeRole -> String
173 da45c352 Iustin Pop
roleDescription NROffline   = "offline"
174 da45c352 Iustin Pop
roleDescription NRDrained   = "drained"
175 da45c352 Iustin Pop
roleDescription NRRegular   = "regular"
176 da45c352 Iustin Pop
roleDescription NRCandidate = "master candidate"
177 da45c352 Iustin Pop
roleDescription NRMaster    = "master"
178 da45c352 Iustin Pop
179 6f732ae0 Helga Velroyen
-- * Network definitions
180 6f732ae0 Helga Velroyen
181 3a991f2d Iustin Pop
-- ** Ipv4 types
182 3a991f2d Iustin Pop
183 3a991f2d Iustin Pop
-- | Custom type for a simple IPv4 address.
184 3a991f2d Iustin Pop
data Ip4Address = Ip4Address Word8 Word8 Word8 Word8
185 3a991f2d Iustin Pop
                  deriving Eq
186 3a991f2d Iustin Pop
187 3a991f2d Iustin Pop
instance Show Ip4Address where
188 3a991f2d Iustin Pop
  show (Ip4Address a b c d) = show a ++ "." ++ show b ++ "." ++
189 3a991f2d Iustin Pop
                              show c ++ "." ++ show d
190 3a991f2d Iustin Pop
191 3a991f2d Iustin Pop
-- | Parses an IPv4 address from a string.
192 3a991f2d Iustin Pop
readIp4Address :: (Applicative m, Monad m) => String -> m Ip4Address
193 3a991f2d Iustin Pop
readIp4Address s =
194 3a991f2d Iustin Pop
  case sepSplit '.' s of
195 3a991f2d Iustin Pop
    [a, b, c, d] -> Ip4Address <$>
196 3a991f2d Iustin Pop
                      tryRead "first octect" a <*>
197 3a991f2d Iustin Pop
                      tryRead "second octet" b <*>
198 3a991f2d Iustin Pop
                      tryRead "third octet"  c <*>
199 3a991f2d Iustin Pop
                      tryRead "fourth octet" d
200 3a991f2d Iustin Pop
    _ -> fail $ "Can't parse IPv4 address from string " ++ s
201 3a991f2d Iustin Pop
202 3a991f2d Iustin Pop
-- | JSON instance for 'Ip4Address'.
203 3a991f2d Iustin Pop
instance JSON Ip4Address where
204 3a991f2d Iustin Pop
  showJSON = showJSON . show
205 3a991f2d Iustin Pop
  readJSON (JSString s) = readIp4Address (fromJSString s)
206 3a991f2d Iustin Pop
  readJSON v = fail $ "Invalid JSON value " ++ show v ++ " for an IPv4 address"
207 3a991f2d Iustin Pop
208 3a991f2d Iustin Pop
-- | \"Next\" address implementation for IPv4 addresses.
209 3a991f2d Iustin Pop
--
210 3a991f2d Iustin Pop
-- Note that this loops! Note also that this is a very dumb
211 3a991f2d Iustin Pop
-- implementation.
212 3a991f2d Iustin Pop
nextIp4Address :: Ip4Address -> Ip4Address
213 3a991f2d Iustin Pop
nextIp4Address (Ip4Address a b c d) =
214 3a991f2d Iustin Pop
  let inc xs y = if all (==0) xs then y + 1 else y
215 3a991f2d Iustin Pop
      d' = d + 1
216 3a991f2d Iustin Pop
      c' = inc [d'] c
217 3a991f2d Iustin Pop
      b' = inc [c', d'] b
218 3a991f2d Iustin Pop
      a' = inc [b', c', d'] a
219 3a991f2d Iustin Pop
  in Ip4Address a' b' c' d'
220 3a991f2d Iustin Pop
221 3a991f2d Iustin Pop
-- | Custom type for an IPv4 network.
222 3a991f2d Iustin Pop
data Ip4Network = Ip4Network Ip4Address Word8
223 3a991f2d Iustin Pop
                  deriving Eq
224 3a991f2d Iustin Pop
225 3a991f2d Iustin Pop
instance Show Ip4Network where
226 3a991f2d Iustin Pop
  show (Ip4Network ip netmask) = show ip ++ "/" ++ show netmask
227 3a991f2d Iustin Pop
228 3a991f2d Iustin Pop
-- | JSON instance for 'Ip4Network'.
229 3a991f2d Iustin Pop
instance JSON Ip4Network where
230 3a991f2d Iustin Pop
  showJSON = showJSON . show
231 3a991f2d Iustin Pop
  readJSON (JSString s) =
232 3a991f2d Iustin Pop
    case sepSplit '/' (fromJSString s) of
233 3a991f2d Iustin Pop
      [ip, nm] -> do
234 3a991f2d Iustin Pop
        ip' <- readIp4Address ip
235 3a991f2d Iustin Pop
        nm' <- tryRead "parsing netmask" nm
236 3a991f2d Iustin Pop
        if nm' >= 0 && nm' <= 32
237 3a991f2d Iustin Pop
          then return $ Ip4Network ip' nm'
238 3a991f2d Iustin Pop
          else fail $ "Invalid netmask " ++ show nm' ++ " from string " ++
239 3a991f2d Iustin Pop
                      fromJSString s
240 3a991f2d Iustin Pop
      _ -> fail $ "Can't parse IPv4 network from string " ++ fromJSString s
241 3a991f2d Iustin Pop
  readJSON v = fail $ "Invalid JSON value " ++ show v ++ " for an IPv4 network"
242 3a991f2d Iustin Pop
243 3a991f2d Iustin Pop
-- ** Ganeti \"network\" config object.
244 3a991f2d Iustin Pop
245 6f732ae0 Helga Velroyen
-- FIXME: Not all types might be correct here, since they
246 6f732ae0 Helga Velroyen
-- haven't been exhaustively deduced from the python code yet.
247 6f732ae0 Helga Velroyen
$(buildObject "Network" "network" $
248 6f732ae0 Helga Velroyen
  [ simpleField "name"             [t| NonEmptyString |]
249 6f732ae0 Helga Velroyen
  , optionalField $
250 6f732ae0 Helga Velroyen
    simpleField "mac_prefix"       [t| String |]
251 3a991f2d Iustin Pop
  , simpleField "network"          [t| Ip4Network |]
252 6f732ae0 Helga Velroyen
  , optionalField $
253 6f732ae0 Helga Velroyen
    simpleField "network6"         [t| String |]
254 6f732ae0 Helga Velroyen
  , optionalField $
255 3a991f2d Iustin Pop
    simpleField "gateway"          [t| Ip4Address |]
256 6f732ae0 Helga Velroyen
  , optionalField $
257 6f732ae0 Helga Velroyen
    simpleField "gateway6"         [t| String |]
258 6f732ae0 Helga Velroyen
  , optionalField $
259 6f732ae0 Helga Velroyen
    simpleField "reservations"     [t| String |]
260 6f732ae0 Helga Velroyen
  , optionalField $
261 6f732ae0 Helga Velroyen
    simpleField "ext_reservations" [t| String |]
262 6f732ae0 Helga Velroyen
  ]
263 b43064d0 Helga Velroyen
  ++ uuidFields
264 6f732ae0 Helga Velroyen
  ++ serialFields
265 6f732ae0 Helga Velroyen
  ++ tagsFields)
266 6f732ae0 Helga Velroyen
267 6f732ae0 Helga Velroyen
instance SerialNoObject Network where
268 6f732ae0 Helga Velroyen
  serialOf = networkSerial
269 6f732ae0 Helga Velroyen
270 6f732ae0 Helga Velroyen
instance TagsObject Network where
271 6f732ae0 Helga Velroyen
  tagsOf = networkTags
272 6f732ae0 Helga Velroyen
273 b43064d0 Helga Velroyen
instance UuidObject Network where
274 b43064d0 Helga Velroyen
  uuidOf = networkUuid
275 b43064d0 Helga Velroyen
276 b1e81520 Iustin Pop
-- * NIC definitions
277 b1e81520 Iustin Pop
278 b09cce64 Iustin Pop
$(buildParam "Nic" "nicp"
279 b1e81520 Iustin Pop
  [ simpleField "mode" [t| NICMode |]
280 b1e81520 Iustin Pop
  , simpleField "link" [t| String  |]
281 b1e81520 Iustin Pop
  ])
282 b1e81520 Iustin Pop
283 b09cce64 Iustin Pop
$(buildObject "PartialNic" "nic"
284 b1e81520 Iustin Pop
  [ simpleField "mac" [t| String |]
285 b1e81520 Iustin Pop
  , optionalField $ simpleField "ip" [t| String |]
286 b09cce64 Iustin Pop
  , simpleField "nicparams" [t| PartialNicParams |]
287 0c6d6a52 Helga Velroyen
  , optionalField $ simpleField "network" [t| String |]
288 b1e81520 Iustin Pop
  ])
289 b1e81520 Iustin Pop
290 b1e81520 Iustin Pop
-- * Disk definitions
291 b1e81520 Iustin Pop
292 b1e81520 Iustin Pop
$(declareSADT "DiskMode"
293 b1e81520 Iustin Pop
  [ ("DiskRdOnly", 'C.diskRdonly)
294 b1e81520 Iustin Pop
  , ("DiskRdWr",   'C.diskRdwr)
295 b1e81520 Iustin Pop
  ])
296 b1e81520 Iustin Pop
$(makeJSONInstance ''DiskMode)
297 b1e81520 Iustin Pop
298 b1e81520 Iustin Pop
$(declareSADT "DiskType"
299 b1e81520 Iustin Pop
  [ ("LD_LV",       'C.ldLv)
300 b1e81520 Iustin Pop
  , ("LD_DRBD8",    'C.ldDrbd8)
301 b1e81520 Iustin Pop
  , ("LD_FILE",     'C.ldFile)
302 b1e81520 Iustin Pop
  , ("LD_BLOCKDEV", 'C.ldBlockdev)
303 2e12944a Iustin Pop
  , ("LD_RADOS",    'C.ldRbd)
304 277a2ec9 Constantinos Venetsanopoulos
  , ("LD_EXT",      'C.ldExt)
305 b1e81520 Iustin Pop
  ])
306 b1e81520 Iustin Pop
$(makeJSONInstance ''DiskType)
307 b1e81520 Iustin Pop
308 2e12944a Iustin Pop
-- | The persistent block driver type. Currently only one type is allowed.
309 2e12944a Iustin Pop
$(declareSADT "BlockDriver"
310 2e12944a Iustin Pop
  [ ("BlockDrvManual", 'C.blockdevDriverManual)
311 2e12944a Iustin Pop
  ])
312 2e12944a Iustin Pop
$(makeJSONInstance ''BlockDriver)
313 2e12944a Iustin Pop
314 2e12944a Iustin Pop
-- | Constant for the dev_type key entry in the disk config.
315 2e12944a Iustin Pop
devType :: String
316 2e12944a Iustin Pop
devType = "dev_type"
317 2e12944a Iustin Pop
318 2e12944a Iustin Pop
-- | The disk configuration type. This includes the disk type itself,
319 2e12944a Iustin Pop
-- for a more complete consistency. Note that since in the Python
320 2e12944a Iustin Pop
-- code-base there's no authoritative place where we document the
321 2e12944a Iustin Pop
-- logical id, this is probably a good reference point.
322 2e12944a Iustin Pop
data DiskLogicalId
323 2e12944a Iustin Pop
  = LIDPlain String String  -- ^ Volume group, logical volume
324 2e12944a Iustin Pop
  | LIDDrbd8 String String Int Int Int String
325 2e12944a Iustin Pop
  -- ^ NodeA, NodeB, Port, MinorA, MinorB, Secret
326 2e12944a Iustin Pop
  | LIDFile FileDriver String -- ^ Driver, path
327 2e12944a Iustin Pop
  | LIDBlockDev BlockDriver String -- ^ Driver, path (must be under /dev)
328 2e12944a Iustin Pop
  | LIDRados String String -- ^ Unused, path
329 277a2ec9 Constantinos Venetsanopoulos
  | LIDExt String String -- ^ ExtProvider, unique name
330 139c0683 Iustin Pop
    deriving (Show, Eq)
331 2e12944a Iustin Pop
332 2e12944a Iustin Pop
-- | Mapping from a logical id to a disk type.
333 2e12944a Iustin Pop
lidDiskType :: DiskLogicalId -> DiskType
334 2e12944a Iustin Pop
lidDiskType (LIDPlain {}) = LD_LV
335 2e12944a Iustin Pop
lidDiskType (LIDDrbd8 {}) = LD_DRBD8
336 2e12944a Iustin Pop
lidDiskType (LIDFile  {}) = LD_FILE
337 2e12944a Iustin Pop
lidDiskType (LIDBlockDev {}) = LD_BLOCKDEV
338 2e12944a Iustin Pop
lidDiskType (LIDRados {}) = LD_RADOS
339 277a2ec9 Constantinos Venetsanopoulos
lidDiskType (LIDExt {}) = LD_EXT
340 2e12944a Iustin Pop
341 2e12944a Iustin Pop
-- | Builds the extra disk_type field for a given logical id.
342 2e12944a Iustin Pop
lidEncodeType :: DiskLogicalId -> [(String, JSValue)]
343 2e12944a Iustin Pop
lidEncodeType v = [(devType, showJSON . lidDiskType $ v)]
344 2e12944a Iustin Pop
345 2e12944a Iustin Pop
-- | Custom encoder for DiskLogicalId (logical id only).
346 2e12944a Iustin Pop
encodeDLId :: DiskLogicalId -> JSValue
347 2e12944a Iustin Pop
encodeDLId (LIDPlain vg lv) = JSArray [showJSON vg, showJSON lv]
348 2e12944a Iustin Pop
encodeDLId (LIDDrbd8 nodeA nodeB port minorA minorB key) =
349 2e12944a Iustin Pop
  JSArray [ showJSON nodeA, showJSON nodeB, showJSON port
350 2e12944a Iustin Pop
          , showJSON minorA, showJSON minorB, showJSON key ]
351 2e12944a Iustin Pop
encodeDLId (LIDRados pool name) = JSArray [showJSON pool, showJSON name]
352 2e12944a Iustin Pop
encodeDLId (LIDFile driver name) = JSArray [showJSON driver, showJSON name]
353 2e12944a Iustin Pop
encodeDLId (LIDBlockDev driver name) = JSArray [showJSON driver, showJSON name]
354 9f6f74b4 Iustin Pop
encodeDLId (LIDExt extprovider name) =
355 9f6f74b4 Iustin Pop
  JSArray [showJSON extprovider, showJSON name]
356 2e12944a Iustin Pop
357 2e12944a Iustin Pop
-- | Custom encoder for DiskLogicalId, composing both the logical id
358 2e12944a Iustin Pop
-- and the extra disk_type field.
359 2e12944a Iustin Pop
encodeFullDLId :: DiskLogicalId -> (JSValue, [(String, JSValue)])
360 2e12944a Iustin Pop
encodeFullDLId v = (encodeDLId v, lidEncodeType v)
361 2e12944a Iustin Pop
362 2e12944a Iustin Pop
-- | Custom decoder for DiskLogicalId. This is manual for now, since
363 2e12944a Iustin Pop
-- we don't have yet automation for separate-key style fields.
364 2e12944a Iustin Pop
decodeDLId :: [(String, JSValue)] -> JSValue -> J.Result DiskLogicalId
365 2e12944a Iustin Pop
decodeDLId obj lid = do
366 2e12944a Iustin Pop
  dtype <- fromObj obj devType
367 2e12944a Iustin Pop
  case dtype of
368 2e12944a Iustin Pop
    LD_DRBD8 ->
369 2e12944a Iustin Pop
      case lid of
370 2e12944a Iustin Pop
        JSArray [nA, nB, p, mA, mB, k] -> do
371 2e12944a Iustin Pop
          nA' <- readJSON nA
372 2e12944a Iustin Pop
          nB' <- readJSON nB
373 2e12944a Iustin Pop
          p'  <- readJSON p
374 2e12944a Iustin Pop
          mA' <- readJSON mA
375 2e12944a Iustin Pop
          mB' <- readJSON mB
376 2e12944a Iustin Pop
          k'  <- readJSON k
377 2e12944a Iustin Pop
          return $ LIDDrbd8 nA' nB' p' mA' mB' k'
378 5b11f8db Iustin Pop
        _ -> fail "Can't read logical_id for DRBD8 type"
379 2e12944a Iustin Pop
    LD_LV ->
380 2e12944a Iustin Pop
      case lid of
381 2e12944a Iustin Pop
        JSArray [vg, lv] -> do
382 2e12944a Iustin Pop
          vg' <- readJSON vg
383 2e12944a Iustin Pop
          lv' <- readJSON lv
384 2e12944a Iustin Pop
          return $ LIDPlain vg' lv'
385 5b11f8db Iustin Pop
        _ -> fail "Can't read logical_id for plain type"
386 2e12944a Iustin Pop
    LD_FILE ->
387 2e12944a Iustin Pop
      case lid of
388 2e12944a Iustin Pop
        JSArray [driver, path] -> do
389 2e12944a Iustin Pop
          driver' <- readJSON driver
390 2e12944a Iustin Pop
          path'   <- readJSON path
391 2e12944a Iustin Pop
          return $ LIDFile driver' path'
392 5b11f8db Iustin Pop
        _ -> fail "Can't read logical_id for file type"
393 2e12944a Iustin Pop
    LD_BLOCKDEV ->
394 2e12944a Iustin Pop
      case lid of
395 2e12944a Iustin Pop
        JSArray [driver, path] -> do
396 2e12944a Iustin Pop
          driver' <- readJSON driver
397 2e12944a Iustin Pop
          path'   <- readJSON path
398 2e12944a Iustin Pop
          return $ LIDBlockDev driver' path'
399 5b11f8db Iustin Pop
        _ -> fail "Can't read logical_id for blockdev type"
400 2e12944a Iustin Pop
    LD_RADOS ->
401 2e12944a Iustin Pop
      case lid of
402 2e12944a Iustin Pop
        JSArray [driver, path] -> do
403 2e12944a Iustin Pop
          driver' <- readJSON driver
404 2e12944a Iustin Pop
          path'   <- readJSON path
405 2e12944a Iustin Pop
          return $ LIDRados driver' path'
406 5b11f8db Iustin Pop
        _ -> fail "Can't read logical_id for rdb type"
407 277a2ec9 Constantinos Venetsanopoulos
    LD_EXT ->
408 277a2ec9 Constantinos Venetsanopoulos
      case lid of
409 277a2ec9 Constantinos Venetsanopoulos
        JSArray [extprovider, name] -> do
410 277a2ec9 Constantinos Venetsanopoulos
          extprovider' <- readJSON extprovider
411 277a2ec9 Constantinos Venetsanopoulos
          name'   <- readJSON name
412 277a2ec9 Constantinos Venetsanopoulos
          return $ LIDExt extprovider' name'
413 277a2ec9 Constantinos Venetsanopoulos
        _ -> fail "Can't read logical_id for extstorage type"
414 2e12944a Iustin Pop
415 b1e81520 Iustin Pop
-- | Disk data structure.
416 b1e81520 Iustin Pop
--
417 b1e81520 Iustin Pop
-- This is declared manually as it's a recursive structure, and our TH
418 b1e81520 Iustin Pop
-- code currently can't build it.
419 b1e81520 Iustin Pop
data Disk = Disk
420 2e12944a Iustin Pop
  { diskLogicalId  :: DiskLogicalId
421 b1e81520 Iustin Pop
--  , diskPhysicalId :: String
422 b1e81520 Iustin Pop
  , diskChildren   :: [Disk]
423 b1e81520 Iustin Pop
  , diskIvName     :: String
424 b1e81520 Iustin Pop
  , diskSize       :: Int
425 b1e81520 Iustin Pop
  , diskMode       :: DiskMode
426 139c0683 Iustin Pop
  } deriving (Show, Eq)
427 b1e81520 Iustin Pop
428 b1e81520 Iustin Pop
$(buildObjectSerialisation "Disk"
429 fa10983e Iustin Pop
  [ customField 'decodeDLId 'encodeFullDLId ["dev_type"] $
430 2e12944a Iustin Pop
      simpleField "logical_id"    [t| DiskLogicalId   |]
431 b1e81520 Iustin Pop
--  , simpleField "physical_id" [t| String   |]
432 b1e81520 Iustin Pop
  , defaultField  [| [] |] $ simpleField "children" [t| [Disk] |]
433 b1e81520 Iustin Pop
  , defaultField [| "" |] $ simpleField "iv_name" [t| String |]
434 b1e81520 Iustin Pop
  , simpleField "size" [t| Int |]
435 b1e81520 Iustin Pop
  , defaultField [| DiskRdWr |] $ simpleField "mode" [t| DiskMode |]
436 b1e81520 Iustin Pop
  ])
437 b1e81520 Iustin Pop
438 b1e81520 Iustin Pop
-- * Instance definitions
439 b1e81520 Iustin Pop
440 b1e81520 Iustin Pop
$(declareSADT "AdminState"
441 b1e81520 Iustin Pop
  [ ("AdminOffline", 'C.adminstOffline)
442 b1e81520 Iustin Pop
  , ("AdminDown",    'C.adminstDown)
443 b1e81520 Iustin Pop
  , ("AdminUp",      'C.adminstUp)
444 b1e81520 Iustin Pop
  ])
445 b1e81520 Iustin Pop
$(makeJSONInstance ''AdminState)
446 b1e81520 Iustin Pop
447 5b11f8db Iustin Pop
$(buildParam "Be" "bep"
448 b1e81520 Iustin Pop
  [ simpleField "minmem"       [t| Int  |]
449 b1e81520 Iustin Pop
  , simpleField "maxmem"       [t| Int  |]
450 b1e81520 Iustin Pop
  , simpleField "vcpus"        [t| Int  |]
451 b1e81520 Iustin Pop
  , simpleField "auto_balance" [t| Bool |]
452 b1e81520 Iustin Pop
  ])
453 b1e81520 Iustin Pop
454 b1e81520 Iustin Pop
$(buildObject "Instance" "inst" $
455 b1e81520 Iustin Pop
  [ simpleField "name"           [t| String             |]
456 b1e81520 Iustin Pop
  , simpleField "primary_node"   [t| String             |]
457 b1e81520 Iustin Pop
  , simpleField "os"             [t| String             |]
458 b09cce64 Iustin Pop
  , simpleField "hypervisor"     [t| Hypervisor         |]
459 b09cce64 Iustin Pop
  , simpleField "hvparams"       [t| HvParams           |]
460 b09cce64 Iustin Pop
  , simpleField "beparams"       [t| PartialBeParams    |]
461 b09cce64 Iustin Pop
  , simpleField "osparams"       [t| OsParams           |]
462 b1e81520 Iustin Pop
  , simpleField "admin_state"    [t| AdminState         |]
463 b09cce64 Iustin Pop
  , simpleField "nics"           [t| [PartialNic]       |]
464 b1e81520 Iustin Pop
  , simpleField "disks"          [t| [Disk]             |]
465 b1e81520 Iustin Pop
  , simpleField "disk_template"  [t| DiskTemplate       |]
466 b09cce64 Iustin Pop
  , optionalField $ simpleField "network_port" [t| Int  |]
467 b1e81520 Iustin Pop
  ]
468 b1e81520 Iustin Pop
  ++ timeStampFields
469 b1e81520 Iustin Pop
  ++ uuidFields
470 f2374060 Iustin Pop
  ++ serialFields
471 f2374060 Iustin Pop
  ++ tagsFields)
472 b1e81520 Iustin Pop
473 04dd53a3 Iustin Pop
instance TimeStampObject Instance where
474 04dd53a3 Iustin Pop
  cTimeOf = instCtime
475 04dd53a3 Iustin Pop
  mTimeOf = instMtime
476 04dd53a3 Iustin Pop
477 04dd53a3 Iustin Pop
instance UuidObject Instance where
478 04dd53a3 Iustin Pop
  uuidOf = instUuid
479 04dd53a3 Iustin Pop
480 04dd53a3 Iustin Pop
instance SerialNoObject Instance where
481 04dd53a3 Iustin Pop
  serialOf = instSerial
482 04dd53a3 Iustin Pop
483 04dd53a3 Iustin Pop
instance TagsObject Instance where
484 04dd53a3 Iustin Pop
  tagsOf = instTags
485 04dd53a3 Iustin Pop
486 7514fe92 Iustin Pop
-- * IPolicy definitions
487 7514fe92 Iustin Pop
488 5b11f8db Iustin Pop
$(buildParam "ISpec" "ispec"
489 7514fe92 Iustin Pop
  [ simpleField C.ispecMemSize     [t| Int |]
490 7514fe92 Iustin Pop
  , simpleField C.ispecDiskSize    [t| Int |]
491 7514fe92 Iustin Pop
  , simpleField C.ispecDiskCount   [t| Int |]
492 7514fe92 Iustin Pop
  , simpleField C.ispecCpuCount    [t| Int |]
493 db154319 Iustin Pop
  , simpleField C.ispecNicCount    [t| Int |]
494 7514fe92 Iustin Pop
  , simpleField C.ispecSpindleUse  [t| Int |]
495 7514fe92 Iustin Pop
  ])
496 7514fe92 Iustin Pop
497 da5f09ef Bernardo Dal Seno
-- | Partial min-max instance specs. These is not built via buildParam since
498 da5f09ef Bernardo Dal Seno
-- it has a special 2-level inheritance mode.
499 da5f09ef Bernardo Dal Seno
$(buildObject "PartialMinMaxISpecs" "mmis"
500 da5f09ef Bernardo Dal Seno
  [ renameField "MinSpecP" $ simpleField "min" [t| PartialISpecParams |]
501 da5f09ef Bernardo Dal Seno
  , renameField "MaxSpecP" $ simpleField "max" [t| PartialISpecParams |]
502 da5f09ef Bernardo Dal Seno
  ])
503 da5f09ef Bernardo Dal Seno
504 da5f09ef Bernardo Dal Seno
-- | Filled min-max instance specs. This is not built via buildParam since
505 da5f09ef Bernardo Dal Seno
-- it has a special 2-level inheritance mode.
506 da5f09ef Bernardo Dal Seno
$(buildObject "FilledMinMaxISpecs" "mmis"
507 da5f09ef Bernardo Dal Seno
  [ renameField "MinSpec" $ simpleField "min" [t| FilledISpecParams |]
508 da5f09ef Bernardo Dal Seno
  , renameField "MaxSpec" $ simpleField "max" [t| FilledISpecParams |]
509 da5f09ef Bernardo Dal Seno
  ])
510 da5f09ef Bernardo Dal Seno
511 7514fe92 Iustin Pop
-- | Custom partial ipolicy. This is not built via buildParam since it
512 7514fe92 Iustin Pop
-- has a special 2-level inheritance mode.
513 5b11f8db Iustin Pop
$(buildObject "PartialIPolicy" "ipolicy"
514 da5f09ef Bernardo Dal Seno
  [ optionalField . renameField "MinMaxISpecsP"
515 da5f09ef Bernardo Dal Seno
                    $ simpleField C.ispecsMinmax [t| PartialMinMaxISpecs |]
516 7514fe92 Iustin Pop
  , renameField "StdSpecP" $ simpleField "std" [t| PartialISpecParams |]
517 7514fe92 Iustin Pop
  , optionalField . renameField "SpindleRatioP"
518 7514fe92 Iustin Pop
                    $ simpleField "spindle-ratio"  [t| Double |]
519 7514fe92 Iustin Pop
  , optionalField . renameField "VcpuRatioP"
520 7514fe92 Iustin Pop
                    $ simpleField "vcpu-ratio"     [t| Double |]
521 7514fe92 Iustin Pop
  , optionalField . renameField "DiskTemplatesP"
522 7514fe92 Iustin Pop
                    $ simpleField "disk-templates" [t| [DiskTemplate] |]
523 7514fe92 Iustin Pop
  ])
524 7514fe92 Iustin Pop
525 7514fe92 Iustin Pop
-- | Custom filled ipolicy. This is not built via buildParam since it
526 7514fe92 Iustin Pop
-- has a special 2-level inheritance mode.
527 5b11f8db Iustin Pop
$(buildObject "FilledIPolicy" "ipolicy"
528 da5f09ef Bernardo Dal Seno
  [ renameField "MinMaxISpecs"
529 da5f09ef Bernardo Dal Seno
    $ simpleField C.ispecsMinmax [t| FilledMinMaxISpecs |]
530 7514fe92 Iustin Pop
  , renameField "StdSpec" $ simpleField "std" [t| FilledISpecParams |]
531 7514fe92 Iustin Pop
  , simpleField "spindle-ratio"  [t| Double |]
532 7514fe92 Iustin Pop
  , simpleField "vcpu-ratio"     [t| Double |]
533 7514fe92 Iustin Pop
  , simpleField "disk-templates" [t| [DiskTemplate] |]
534 7514fe92 Iustin Pop
  ])
535 7514fe92 Iustin Pop
536 da5f09ef Bernardo Dal Seno
-- | Custom filler for the min-max instance specs.
537 da5f09ef Bernardo Dal Seno
fillMinMaxISpecs :: FilledMinMaxISpecs -> Maybe PartialMinMaxISpecs ->
538 da5f09ef Bernardo Dal Seno
                    FilledMinMaxISpecs
539 da5f09ef Bernardo Dal Seno
fillMinMaxISpecs fminmax Nothing = fminmax
540 da5f09ef Bernardo Dal Seno
fillMinMaxISpecs (FilledMinMaxISpecs { mmisMinSpec = fmin
541 da5f09ef Bernardo Dal Seno
                                     , mmisMaxSpec = fmax })
542 da5f09ef Bernardo Dal Seno
                 (Just PartialMinMaxISpecs { mmisMinSpecP = pmin
543 da5f09ef Bernardo Dal Seno
                                           , mmisMaxSpecP = pmax }) =
544 da5f09ef Bernardo Dal Seno
  FilledMinMaxISpecs { mmisMinSpec = fillISpecParams fmin pmin
545 da5f09ef Bernardo Dal Seno
                     , mmisMaxSpec = fillISpecParams fmax pmax }
546 da5f09ef Bernardo Dal Seno
547 7514fe92 Iustin Pop
-- | Custom filler for the ipolicy types.
548 7514fe92 Iustin Pop
fillIPolicy :: FilledIPolicy -> PartialIPolicy -> FilledIPolicy
549 da5f09ef Bernardo Dal Seno
fillIPolicy (FilledIPolicy { ipolicyMinMaxISpecs  = fminmax
550 7514fe92 Iustin Pop
                           , ipolicyStdSpec       = fstd
551 7514fe92 Iustin Pop
                           , ipolicySpindleRatio  = fspindleRatio
552 7514fe92 Iustin Pop
                           , ipolicyVcpuRatio     = fvcpuRatio
553 7514fe92 Iustin Pop
                           , ipolicyDiskTemplates = fdiskTemplates})
554 da5f09ef Bernardo Dal Seno
            (PartialIPolicy { ipolicyMinMaxISpecsP  = pminmax
555 7514fe92 Iustin Pop
                            , ipolicyStdSpecP       = pstd
556 7514fe92 Iustin Pop
                            , ipolicySpindleRatioP  = pspindleRatio
557 7514fe92 Iustin Pop
                            , ipolicyVcpuRatioP     = pvcpuRatio
558 7514fe92 Iustin Pop
                            , ipolicyDiskTemplatesP = pdiskTemplates}) =
559 da5f09ef Bernardo Dal Seno
  FilledIPolicy { ipolicyMinMaxISpecs  = fillMinMaxISpecs fminmax pminmax
560 7514fe92 Iustin Pop
                , ipolicyStdSpec       = fillISpecParams fstd pstd
561 7514fe92 Iustin Pop
                , ipolicySpindleRatio  = fromMaybe fspindleRatio pspindleRatio
562 7514fe92 Iustin Pop
                , ipolicyVcpuRatio     = fromMaybe fvcpuRatio pvcpuRatio
563 7514fe92 Iustin Pop
                , ipolicyDiskTemplates = fromMaybe fdiskTemplates
564 7514fe92 Iustin Pop
                                         pdiskTemplates
565 7514fe92 Iustin Pop
                }
566 b1e81520 Iustin Pop
-- * Node definitions
567 b1e81520 Iustin Pop
568 5b11f8db Iustin Pop
$(buildParam "ND" "ndp"
569 7514fe92 Iustin Pop
  [ simpleField "oob_program"   [t| String |]
570 7514fe92 Iustin Pop
  , simpleField "spindle_count" [t| Int    |]
571 0ea11dcb Bernardo Dal Seno
  , simpleField "exclusive_storage" [t| Bool |]
572 b1e81520 Iustin Pop
  ])
573 b1e81520 Iustin Pop
574 b1e81520 Iustin Pop
$(buildObject "Node" "node" $
575 b1e81520 Iustin Pop
  [ simpleField "name"             [t| String |]
576 b1e81520 Iustin Pop
  , simpleField "primary_ip"       [t| String |]
577 b1e81520 Iustin Pop
  , simpleField "secondary_ip"     [t| String |]
578 b1e81520 Iustin Pop
  , simpleField "master_candidate" [t| Bool   |]
579 b1e81520 Iustin Pop
  , simpleField "offline"          [t| Bool   |]
580 b1e81520 Iustin Pop
  , simpleField "drained"          [t| Bool   |]
581 b1e81520 Iustin Pop
  , simpleField "group"            [t| String |]
582 b1e81520 Iustin Pop
  , simpleField "master_capable"   [t| Bool   |]
583 b1e81520 Iustin Pop
  , simpleField "vm_capable"       [t| Bool   |]
584 a957e150 Iustin Pop
  , simpleField "ndparams"         [t| PartialNDParams |]
585 b1e81520 Iustin Pop
  , simpleField "powered"          [t| Bool   |]
586 b1e81520 Iustin Pop
  ]
587 b1e81520 Iustin Pop
  ++ timeStampFields
588 b1e81520 Iustin Pop
  ++ uuidFields
589 f2374060 Iustin Pop
  ++ serialFields
590 f2374060 Iustin Pop
  ++ tagsFields)
591 b1e81520 Iustin Pop
592 04dd53a3 Iustin Pop
instance TimeStampObject Node where
593 04dd53a3 Iustin Pop
  cTimeOf = nodeCtime
594 04dd53a3 Iustin Pop
  mTimeOf = nodeMtime
595 04dd53a3 Iustin Pop
596 04dd53a3 Iustin Pop
instance UuidObject Node where
597 04dd53a3 Iustin Pop
  uuidOf = nodeUuid
598 04dd53a3 Iustin Pop
599 04dd53a3 Iustin Pop
instance SerialNoObject Node where
600 04dd53a3 Iustin Pop
  serialOf = nodeSerial
601 04dd53a3 Iustin Pop
602 04dd53a3 Iustin Pop
instance TagsObject Node where
603 04dd53a3 Iustin Pop
  tagsOf = nodeTags
604 04dd53a3 Iustin Pop
605 b1e81520 Iustin Pop
-- * NodeGroup definitions
606 b1e81520 Iustin Pop
607 b09cce64 Iustin Pop
-- | The disk parameters type.
608 b09cce64 Iustin Pop
type DiskParams = Container (Container JSValue)
609 b09cce64 Iustin Pop
610 da1dcce1 Helga Velroyen
-- | A mapping from network UUIDs to nic params of the networks.
611 2f3a3365 Helga Velroyen
type Networks = Container PartialNicParams
612 da1dcce1 Helga Velroyen
613 b1e81520 Iustin Pop
$(buildObject "NodeGroup" "group" $
614 b1e81520 Iustin Pop
  [ simpleField "name"         [t| String |]
615 0f0d7aba Helga Velroyen
  , defaultField [| [] |] $ simpleField "members" [t| [String] |]
616 a957e150 Iustin Pop
  , simpleField "ndparams"     [t| PartialNDParams |]
617 7514fe92 Iustin Pop
  , simpleField "alloc_policy" [t| AllocPolicy     |]
618 7514fe92 Iustin Pop
  , simpleField "ipolicy"      [t| PartialIPolicy  |]
619 b09cce64 Iustin Pop
  , simpleField "diskparams"   [t| DiskParams      |]
620 da1dcce1 Helga Velroyen
  , simpleField "networks"     [t| Networks        |]
621 b1e81520 Iustin Pop
  ]
622 b1e81520 Iustin Pop
  ++ timeStampFields
623 b1e81520 Iustin Pop
  ++ uuidFields
624 f2374060 Iustin Pop
  ++ serialFields
625 f2374060 Iustin Pop
  ++ tagsFields)
626 b1e81520 Iustin Pop
627 04dd53a3 Iustin Pop
instance TimeStampObject NodeGroup where
628 04dd53a3 Iustin Pop
  cTimeOf = groupCtime
629 04dd53a3 Iustin Pop
  mTimeOf = groupMtime
630 04dd53a3 Iustin Pop
631 04dd53a3 Iustin Pop
instance UuidObject NodeGroup where
632 04dd53a3 Iustin Pop
  uuidOf = groupUuid
633 04dd53a3 Iustin Pop
634 04dd53a3 Iustin Pop
instance SerialNoObject NodeGroup where
635 04dd53a3 Iustin Pop
  serialOf = groupSerial
636 04dd53a3 Iustin Pop
637 04dd53a3 Iustin Pop
instance TagsObject NodeGroup where
638 04dd53a3 Iustin Pop
  tagsOf = groupTags
639 04dd53a3 Iustin Pop
640 a957e150 Iustin Pop
-- | IP family type
641 a957e150 Iustin Pop
$(declareIADT "IpFamily"
642 a957e150 Iustin Pop
  [ ("IpFamilyV4", 'C.ip4Family)
643 a957e150 Iustin Pop
  , ("IpFamilyV6", 'C.ip6Family)
644 a957e150 Iustin Pop
  ])
645 a957e150 Iustin Pop
$(makeJSONInstance ''IpFamily)
646 a957e150 Iustin Pop
647 a957e150 Iustin Pop
-- | Conversion from IP family to IP version. This is needed because
648 a957e150 Iustin Pop
-- Python uses both, depending on context.
649 a957e150 Iustin Pop
ipFamilyToVersion :: IpFamily -> Int
650 a957e150 Iustin Pop
ipFamilyToVersion IpFamilyV4 = C.ip4Version
651 a957e150 Iustin Pop
ipFamilyToVersion IpFamilyV6 = C.ip6Version
652 a957e150 Iustin Pop
653 b09cce64 Iustin Pop
-- | Cluster HvParams (hvtype to hvparams mapping).
654 b09cce64 Iustin Pop
type ClusterHvParams = Container HvParams
655 b09cce64 Iustin Pop
656 b09cce64 Iustin Pop
-- | Cluster Os-HvParams (os to hvparams mapping).
657 b09cce64 Iustin Pop
type OsHvParams = Container ClusterHvParams
658 b09cce64 Iustin Pop
659 b09cce64 Iustin Pop
-- | Cluser BeParams.
660 b09cce64 Iustin Pop
type ClusterBeParams = Container FilledBeParams
661 b09cce64 Iustin Pop
662 b09cce64 Iustin Pop
-- | Cluster OsParams.
663 b09cce64 Iustin Pop
type ClusterOsParams = Container OsParams
664 b09cce64 Iustin Pop
665 b09cce64 Iustin Pop
-- | Cluster NicParams.
666 b09cce64 Iustin Pop
type ClusterNicParams = Container FilledNicParams
667 b09cce64 Iustin Pop
668 b09cce64 Iustin Pop
-- | Cluster UID Pool, list (low, high) UID ranges.
669 b09cce64 Iustin Pop
type UidPool = [(Int, Int)]
670 b09cce64 Iustin Pop
671 b1e81520 Iustin Pop
-- * Cluster definitions
672 b1e81520 Iustin Pop
$(buildObject "Cluster" "cluster" $
673 b09cce64 Iustin Pop
  [ simpleField "rsahostkeypub"           [t| String           |]
674 b09cce64 Iustin Pop
  , simpleField "highest_used_port"       [t| Int              |]
675 b09cce64 Iustin Pop
  , simpleField "tcpudp_port_pool"        [t| [Int]            |]
676 b09cce64 Iustin Pop
  , simpleField "mac_prefix"              [t| String           |]
677 64b0309a Dimitris Aragiorgis
  , optionalField $
678 64b0309a Dimitris Aragiorgis
    simpleField "volume_group_name"       [t| String           |]
679 b09cce64 Iustin Pop
  , simpleField "reserved_lvs"            [t| [String]         |]
680 b09cce64 Iustin Pop
  , optionalField $
681 b09cce64 Iustin Pop
    simpleField "drbd_usermode_helper"    [t| String           |]
682 b09cce64 Iustin Pop
  , simpleField "master_node"             [t| String           |]
683 b09cce64 Iustin Pop
  , simpleField "master_ip"               [t| String           |]
684 b09cce64 Iustin Pop
  , simpleField "master_netdev"           [t| String           |]
685 b09cce64 Iustin Pop
  , simpleField "master_netmask"          [t| Int              |]
686 b09cce64 Iustin Pop
  , simpleField "use_external_mip_script" [t| Bool             |]
687 b09cce64 Iustin Pop
  , simpleField "cluster_name"            [t| String           |]
688 b09cce64 Iustin Pop
  , simpleField "file_storage_dir"        [t| String           |]
689 b09cce64 Iustin Pop
  , simpleField "shared_file_storage_dir" [t| String           |]
690 f9b0084a Agata Murawska
  , simpleField "enabled_hypervisors"     [t| [Hypervisor]     |]
691 b09cce64 Iustin Pop
  , simpleField "hvparams"                [t| ClusterHvParams  |]
692 b09cce64 Iustin Pop
  , simpleField "os_hvp"                  [t| OsHvParams       |]
693 b09cce64 Iustin Pop
  , simpleField "beparams"                [t| ClusterBeParams  |]
694 b09cce64 Iustin Pop
  , simpleField "osparams"                [t| ClusterOsParams  |]
695 b09cce64 Iustin Pop
  , simpleField "nicparams"               [t| ClusterNicParams |]
696 b09cce64 Iustin Pop
  , simpleField "ndparams"                [t| FilledNDParams   |]
697 b09cce64 Iustin Pop
  , simpleField "diskparams"              [t| DiskParams       |]
698 b09cce64 Iustin Pop
  , simpleField "candidate_pool_size"     [t| Int              |]
699 b09cce64 Iustin Pop
  , simpleField "modify_etc_hosts"        [t| Bool             |]
700 b09cce64 Iustin Pop
  , simpleField "modify_ssh_setup"        [t| Bool             |]
701 b09cce64 Iustin Pop
  , simpleField "maintain_node_health"    [t| Bool             |]
702 b09cce64 Iustin Pop
  , simpleField "uid_pool"                [t| UidPool          |]
703 b09cce64 Iustin Pop
  , simpleField "default_iallocator"      [t| String           |]
704 b09cce64 Iustin Pop
  , simpleField "hidden_os"               [t| [String]         |]
705 b09cce64 Iustin Pop
  , simpleField "blacklisted_os"          [t| [String]         |]
706 b09cce64 Iustin Pop
  , simpleField "primary_ip_family"       [t| IpFamily         |]
707 b09cce64 Iustin Pop
  , simpleField "prealloc_wipe_disks"     [t| Bool             |]
708 b09cce64 Iustin Pop
  , simpleField "ipolicy"                 [t| FilledIPolicy    |]
709 d0de443e Helga Velroyen
  , simpleField "enabled_storage_types"   [t| [StorageType]    |]
710 b1e81520 Iustin Pop
 ]
711 02cccecd Iustin Pop
 ++ timeStampFields
712 02cccecd Iustin Pop
 ++ uuidFields
713 04dd53a3 Iustin Pop
 ++ serialFields
714 02cccecd Iustin Pop
 ++ tagsFields)
715 b1e81520 Iustin Pop
716 04dd53a3 Iustin Pop
instance TimeStampObject Cluster where
717 04dd53a3 Iustin Pop
  cTimeOf = clusterCtime
718 04dd53a3 Iustin Pop
  mTimeOf = clusterMtime
719 04dd53a3 Iustin Pop
720 04dd53a3 Iustin Pop
instance UuidObject Cluster where
721 04dd53a3 Iustin Pop
  uuidOf = clusterUuid
722 04dd53a3 Iustin Pop
723 04dd53a3 Iustin Pop
instance SerialNoObject Cluster where
724 04dd53a3 Iustin Pop
  serialOf = clusterSerial
725 04dd53a3 Iustin Pop
726 04dd53a3 Iustin Pop
instance TagsObject Cluster where
727 04dd53a3 Iustin Pop
  tagsOf = clusterTags
728 04dd53a3 Iustin Pop
729 b1e81520 Iustin Pop
-- * ConfigData definitions
730 b1e81520 Iustin Pop
731 b1e81520 Iustin Pop
$(buildObject "ConfigData" "config" $
732 b1e81520 Iustin Pop
--  timeStampFields ++
733 d5a93a80 Iustin Pop
  [ simpleField "version"    [t| Int                 |]
734 d5a93a80 Iustin Pop
  , simpleField "cluster"    [t| Cluster             |]
735 d5a93a80 Iustin Pop
  , simpleField "nodes"      [t| Container Node      |]
736 d5a93a80 Iustin Pop
  , simpleField "nodegroups" [t| Container NodeGroup |]
737 d5a93a80 Iustin Pop
  , simpleField "instances"  [t| Container Instance  |]
738 b43064d0 Helga Velroyen
  , simpleField "networks"   [t| Container Network   |]
739 b1e81520 Iustin Pop
  ]
740 b1e81520 Iustin Pop
  ++ serialFields)
741 04dd53a3 Iustin Pop
742 04dd53a3 Iustin Pop
instance SerialNoObject ConfigData where
743 04dd53a3 Iustin Pop
  serialOf = configSerial