Hs2Py constants: add network mirrored disk templates
authorJose A. Lopes <jabolopes@google.com>
Fri, 4 Oct 2013 14:16:48 +0000 (16:16 +0200)
committerJose A. Lopes <jabolopes@google.com>
Tue, 8 Oct 2013 12:57:27 +0000 (14:57 +0200)
Add network mirrored disk template constants to the Haskell to Python
constant generation.

Signed-off-by: Jose A. Lopes <jabolopes@google.com>
Reviewed-by: Thomas Thrainer <thomasth@google.com>

lib/constants.py
src/Ganeti/ConstantUtils.hs
src/Ganeti/HsConstants.hs

index ba8d4bb..24c52f4 100644 (file)
@@ -392,82 +392,6 @@ MAP_DISK_TEMPLATE_STORAGE_TYPE = {
   DT_SHARED_FILE: ST_FILE,
   }
 
   DT_SHARED_FILE: ST_FILE,
   }
 
-# the set of network-mirrored disk templates
-DTS_INT_MIRROR = compat.UniqueFrozenset([DT_DRBD8])
-
-# the set of externally-mirrored disk templates (e.g. SAN, NAS)
-DTS_EXT_MIRROR = compat.UniqueFrozenset([
-  DT_DISKLESS, # 'trivially' externally mirrored
-  DT_SHARED_FILE,
-  DT_BLOCK,
-  DT_RBD,
-  DT_EXT,
-  ])
-
-# the set of non-lvm-based disk templates
-DTS_NOT_LVM = compat.UniqueFrozenset([
-  DT_DISKLESS,
-  DT_FILE,
-  DT_SHARED_FILE,
-  DT_BLOCK,
-  DT_RBD,
-  DT_EXT,
-  ])
-
-# the set of disk templates which can be grown
-DTS_GROWABLE = compat.UniqueFrozenset([
-  DT_PLAIN,
-  DT_DRBD8,
-  DT_FILE,
-  DT_SHARED_FILE,
-  DT_RBD,
-  DT_EXT,
-  ])
-
-# the set of disk templates that allow adoption
-DTS_MAY_ADOPT = compat.UniqueFrozenset([
-  DT_PLAIN,
-  DT_BLOCK,
-  ])
-
-# the set of disk templates that *must* use adoption
-DTS_MUST_ADOPT = compat.UniqueFrozenset([DT_BLOCK])
-
-# the set of disk templates that allow migrations
-DTS_MIRRORED = frozenset.union(DTS_INT_MIRROR, DTS_EXT_MIRROR)
-
-# the set of file based disk templates
-DTS_FILEBASED = compat.UniqueFrozenset([
-  DT_FILE,
-  DT_SHARED_FILE,
-  ])
-
-# the set of disk templates that can be moved by copying
-# Note: a requirement is that they're not accessed externally or shared between
-# nodes; in particular, sharedfile is not suitable.
-DTS_COPYABLE = compat.UniqueFrozenset([
-  DT_FILE,
-  DT_PLAIN,
-  ])
-
-# the set of disk templates that are supported by exclusive_storage
-DTS_EXCL_STORAGE = compat.UniqueFrozenset([DT_PLAIN])
-
-# templates for which we don't perform checks on free space
-DTS_NO_FREE_SPACE_CHECK = compat.UniqueFrozenset([
-  DT_FILE,
-  DT_SHARED_FILE,
-  DT_RBD,
-  DT_EXT,
-  ])
-
-DTS_BLOCK = compat.UniqueFrozenset([
-  DT_PLAIN,
-  DT_DRBD8,
-  DT_BLOCK,
-  DT_RBD,
-  DT_EXT,
-  ])
 
 # drbd constants
 DRBD_HMAC_ALG = "md5"
 
 # drbd constants
 DRBD_HMAC_ALG = "md5"
@@ -478,6 +402,18 @@ DRBD_STATUS_FILE = "/proc/drbd"
 #: Size of DRBD meta block device
 DRBD_META_SIZE = 128
 
 #: Size of DRBD meta block device
 DRBD_META_SIZE = 128
 
+DTS_INT_MIRROR = _constants.DTS_INT_MIRROR
+DTS_EXT_MIRROR = _constants.DTS_EXT_MIRROR
+DTS_NOT_LVM = _constants.DTS_NOT_LVM
+DTS_GROWABLE = _constants.DTS_GROWABLE
+DTS_MAY_ADOPT = _constants.DTS_MAY_ADOPT
+DTS_MUST_ADOPT = _constants.DTS_MUST_ADOPT
+DTS_MIRRORED = _constants.DTS_MIRRORED
+DTS_FILEBASED = _constants.DTS_FILEBASED
+DTS_COPYABLE = _constants.DTS_COPYABLE
+DTS_EXCL_STORAGE = _constants.DTS_EXCL_STORAGE
+DTS_NO_FREE_SPACE_CHECK = _constants.DTS_NO_FREE_SPACE_CHECK
+DTS_BLOCK = _constants.DTS_BLOCK
 # drbd barrier types
 DRBD_B_NONE = "n"
 DRBD_B_DISK_BARRIERS = "b"
 # drbd barrier types
 DRBD_B_NONE = "n"
 DRBD_B_DISK_BARRIERS = "b"
index 0c3dd0c..2eb8518 100644 (file)
@@ -30,7 +30,7 @@ module Ganeti.ConstantUtils where
 
 import Data.Char (ord)
 import Data.Set (Set)
 
 import Data.Char (ord)
 import Data.Set (Set)
-import qualified Data.Set as Set (fromList, toList)
+import qualified Data.Set as Set (fromList, toList, union)
 
 import Ganeti.THH (PyValue(..))
 import Ganeti.PyValueInstances ()
 
 import Ganeti.THH (PyValue(..))
 import Ganeti.PyValueInstances ()
@@ -61,6 +61,9 @@ instance PyValue a => PyValue (FrozenSet a) where
 mkSet :: Ord a => [a] -> FrozenSet a
 mkSet = FrozenSet . Set.fromList
 
 mkSet :: Ord a => [a] -> FrozenSet a
 mkSet = FrozenSet . Set.fromList
 
+union :: Ord a => FrozenSet a -> FrozenSet a -> FrozenSet a
+union x y = FrozenSet (unFrozenSet x `Set.union` unFrozenSet y)
+
 -- | 'Protocol' represents the protocols used by the daemons
 data Protocol = Tcp | Udp
   deriving (Show)
 -- | 'Protocol' represents the protocols used by the daemons
 data Protocol = Tcp | Udp
   deriving (Show)
index 4bd9139..bd8e066 100644 (file)
@@ -530,6 +530,71 @@ diskTemplates = ConstantUtils.mkSet $ map Types.diskTemplateToRaw [minBound..]
 defaultEnabledDiskTemplates :: [String]
 defaultEnabledDiskTemplates = map Types.diskTemplateToRaw [DTDrbd8, DTPlain]
 
 defaultEnabledDiskTemplates :: [String]
 defaultEnabledDiskTemplates = map Types.diskTemplateToRaw [DTDrbd8, DTPlain]
 
+-- | The set of network-mirrored disk templates
+dtsIntMirror :: FrozenSet String
+dtsIntMirror = ConstantUtils.mkSet [dtDrbd8]
+
+-- | 'DTDiskless' is 'trivially' externally mirrored
+dtsExtMirror :: FrozenSet String
+dtsExtMirror =
+  ConstantUtils.mkSet $
+  map Types.diskTemplateToRaw [DTDiskless, DTBlock, DTExt, DTSharedFile, DTRbd]
+
+-- | The set of non-lvm-based disk templates
+dtsNotLvm :: FrozenSet String
+dtsNotLvm =
+  ConstantUtils.mkSet $
+  map Types.diskTemplateToRaw
+  [DTSharedFile, DTDiskless, DTBlock, DTExt, DTFile, DTRbd]
+
+-- | The set of disk templates which can be grown
+dtsGrowable :: FrozenSet String
+dtsGrowable =
+  ConstantUtils.mkSet $
+  map Types.diskTemplateToRaw
+  [DTSharedFile, DTDrbd8, DTPlain, DTExt, DTFile, DTRbd]
+
+-- | The set of disk templates that allow adoption
+dtsMayAdopt :: FrozenSet String
+dtsMayAdopt =
+  ConstantUtils.mkSet $ map Types.diskTemplateToRaw [DTBlock, DTPlain]
+
+-- | The set of disk templates that *must* use adoption
+dtsMustAdopt :: FrozenSet String
+dtsMustAdopt = ConstantUtils.mkSet [Types.diskTemplateToRaw DTBlock]
+
+-- | The set of disk templates that allow migrations
+dtsMirrored :: FrozenSet String
+dtsMirrored = dtsIntMirror `ConstantUtils.union` dtsExtMirror
+
+-- | The set of file based disk templates
+dtsFilebased :: FrozenSet String
+dtsFilebased =
+  ConstantUtils.mkSet $ map Types.diskTemplateToRaw [DTSharedFile, DTFile]
+
+-- | The set of disk templates that can be moved by copying
+--
+-- Note: a requirement is that they're not accessed externally or
+-- shared between nodes; in particular, sharedfile is not suitable.
+dtsCopyable :: FrozenSet String
+dtsCopyable =
+  ConstantUtils.mkSet $ map Types.diskTemplateToRaw [DTPlain, DTFile]
+
+-- | The set of disk templates that are supported by exclusive_storage
+dtsExclStorage :: FrozenSet String
+dtsExclStorage = ConstantUtils.mkSet $ map Types.diskTemplateToRaw [DTPlain]
+
+-- | Templates for which we don't perform checks on free space
+dtsNoFreeSpaceCheck :: FrozenSet String
+dtsNoFreeSpaceCheck =
+  ConstantUtils.mkSet $
+  map Types.diskTemplateToRaw [DTExt, DTSharedFile, DTFile, DTRbd]
+
+dtsBlock :: FrozenSet String
+dtsBlock =
+  ConstantUtils.mkSet $
+  map Types.diskTemplateToRaw [DTPlain, DTDrbd8, DTBlock, DTRbd, DTExt]
+
 -- * File backend driver
 
 fdBlktap :: String
 -- * File backend driver
 
 fdBlktap :: String