Revision 212b66c3 src/Ganeti/Types.hs
b/src/Ganeti/Types.hs | ||
---|---|---|
63 | 63 |
, hypervisorToRaw |
64 | 64 |
, OobCommand(..) |
65 | 65 |
, StorageType(..) |
66 |
, storageTypeToRaw |
|
66 | 67 |
, NodeEvacMode(..) |
67 | 68 |
, FileDriver(..) |
68 | 69 |
, InstCreateMode(..) |
... | ... | |
95 | 96 |
, ELogType(..) |
96 | 97 |
, ReasonElem |
97 | 98 |
, ReasonTrail |
99 |
, StorageUnit(..) |
|
100 |
, StorageUnitRaw(..) |
|
101 |
, StorageKey |
|
102 |
, addParamsToStorageUnit |
|
103 |
, diskTemplateToStorageType |
|
98 | 104 |
) where |
99 | 105 |
|
100 | 106 |
import Control.Monad (liftM) |
... | ... | |
311 | 317 |
]) |
312 | 318 |
$(THH.makeJSONInstance ''StorageType) |
313 | 319 |
|
320 |
-- | Storage keys are identifiers for storage units. Their content varies |
|
321 |
-- depending on the storage type, for example a storage key for LVM storage |
|
322 |
-- is the volume group name. |
|
323 |
type StorageKey = String |
|
324 |
|
|
325 |
-- | Storage parameters |
|
326 |
type SPExclusiveStorage = Bool |
|
327 |
|
|
328 |
-- | Storage units without storage-type-specific parameters |
|
329 |
data StorageUnitRaw = SURaw StorageType StorageKey |
|
330 |
|
|
331 |
-- | Full storage unit with storage-type-specific parameters |
|
332 |
data StorageUnit = SUFile StorageKey |
|
333 |
| SULvmPv StorageKey SPExclusiveStorage |
|
334 |
| SULvmVg StorageKey SPExclusiveStorage |
|
335 |
| SUDiskless StorageKey |
|
336 |
| SUBlock StorageKey |
|
337 |
| SURados StorageKey |
|
338 |
| SUExt StorageKey |
|
339 |
deriving (Eq) |
|
340 |
|
|
341 |
instance Show StorageUnit where |
|
342 |
show (SUFile key) = showSUSimple StorageFile key |
|
343 |
show (SULvmPv key es) = showSULvm StorageLvmPv key es |
|
344 |
show (SULvmVg key es) = showSULvm StorageLvmVg key es |
|
345 |
show (SUDiskless key) = showSUSimple StorageDiskless key |
|
346 |
show (SUBlock key) = showSUSimple StorageBlock key |
|
347 |
show (SURados key) = showSUSimple StorageRados key |
|
348 |
show (SUExt key) = showSUSimple StorageExt key |
|
349 |
|
|
350 |
instance JSON StorageUnit where |
|
351 |
showJSON (SUFile key) = showJSON (StorageFile, key, []::[String]) |
|
352 |
showJSON (SULvmPv key es) = showJSON (StorageLvmPv, key, [es]) |
|
353 |
showJSON (SULvmVg key es) = showJSON (StorageLvmVg, key, [es]) |
|
354 |
showJSON (SUDiskless key) = showJSON (StorageDiskless, key, []::[String]) |
|
355 |
showJSON (SUBlock key) = showJSON (StorageBlock, key, []::[String]) |
|
356 |
showJSON (SURados key) = showJSON (StorageRados, key, []::[String]) |
|
357 |
showJSON (SUExt key) = showJSON (StorageExt, key, []::[String]) |
|
358 |
-- FIXME: add readJSON implementation |
|
359 |
readJSON = fail "Not implemented" |
|
360 |
|
|
361 |
-- | Composes a string representation of storage types without |
|
362 |
-- storage parameters |
|
363 |
showSUSimple :: StorageType -> StorageKey -> String |
|
364 |
showSUSimple st sk = show (storageTypeToRaw st, sk, []::[String]) |
|
365 |
|
|
366 |
-- | Composes a string representation of the LVM storage types |
|
367 |
showSULvm :: StorageType -> StorageKey -> SPExclusiveStorage -> String |
|
368 |
showSULvm st sk es = show (storageTypeToRaw st, sk, [es]) |
|
369 |
|
|
370 |
-- | Mapping fo disk templates to storage type |
|
371 |
-- FIXME: This is semantically the same as the constant |
|
372 |
-- C.diskTemplatesStorageType, remove this when python constants |
|
373 |
-- are generated from haskell constants |
|
374 |
diskTemplateToStorageType :: DiskTemplate -> StorageType |
|
375 |
diskTemplateToStorageType DTExt = StorageExt |
|
376 |
diskTemplateToStorageType DTFile = StorageFile |
|
377 |
diskTemplateToStorageType DTSharedFile = StorageFile |
|
378 |
diskTemplateToStorageType DTDrbd8 = StorageLvmVg |
|
379 |
diskTemplateToStorageType DTPlain = StorageLvmVg |
|
380 |
diskTemplateToStorageType DTRbd = StorageRados |
|
381 |
diskTemplateToStorageType DTDiskless = StorageDiskless |
|
382 |
diskTemplateToStorageType DTBlock = StorageBlock |
|
383 |
|
|
384 |
-- | Equips a raw storage unit with its parameters |
|
385 |
addParamsToStorageUnit :: SPExclusiveStorage -> StorageUnitRaw -> StorageUnit |
|
386 |
addParamsToStorageUnit _ (SURaw StorageBlock key) = SUBlock key |
|
387 |
addParamsToStorageUnit _ (SURaw StorageDiskless key) = SUDiskless key |
|
388 |
addParamsToStorageUnit _ (SURaw StorageExt key) = SUExt key |
|
389 |
addParamsToStorageUnit _ (SURaw StorageFile key) = SUFile key |
|
390 |
addParamsToStorageUnit es (SURaw StorageLvmPv key) = SULvmPv key es |
|
391 |
addParamsToStorageUnit es (SURaw StorageLvmVg key) = SULvmVg key es |
|
392 |
addParamsToStorageUnit _ (SURaw StorageRados key) = SURados key |
|
393 |
|
|
314 | 394 |
-- | Node evac modes. |
315 | 395 |
$(THH.declareSADT "NodeEvacMode" |
316 | 396 |
[ ("NEvacPrimary", 'C.iallocatorNevacPri) |
Also available in: Unified diff