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