From 1b02d7efb9c1d0fb7a635f588fde308ad885d898 Mon Sep 17 00:00:00 2001 From: Helga Velroyen <helgav@google.com> Date: Mon, 25 Mar 2013 16:56:48 +0100 Subject: [PATCH] Add enabled disk templates to cluster cfg This patch adds constants for enabling disk templates to the constants, and the cluster configuration in haskell and python. It removes the obsolete preference list for enabled storage types. Signed-off-by: Helga Velroyen <helgav@google.com> Reviewed-by: Michele Tartara <mtarara@google.com> --- lib/constants.py | 55 +++++++++++++++++++++++++------------------ lib/objects.py | 50 +++++++++++++++++++++------------------ src/Ganeti/Objects.hs | 3 +++ 3 files changed, 62 insertions(+), 46 deletions(-) diff --git a/lib/constants.py b/lib/constants.py index 3926f02ad..544f61f04 100644 --- a/lib/constants.py +++ b/lib/constants.py @@ -398,18 +398,6 @@ DEFAULT_ENABLED_STORAGE_TYPES = compat.UniqueFrozenset([ ST_LVM_VG, ]) -# This is used to order determine the default storage type when the list -# of enabled storage types is inferred from the current state of the cluster. -# This only happens on an upgrade from a version of Ganeti that did not -# support the 'enabled_storage_methods' so far. -STORAGE_TYPES_PREFERENCE = [ - ST_LVM_VG, - ST_FILE, - ST_SHARED_FILE, - ST_RADOS, - ST_BLOCK, - ] - # Storage fields # first two are valid in LU context only, not passed to backend SF_NODE = "node" @@ -458,6 +446,38 @@ DT_PLAIN = "plain" DT_RBD = "rbd" DT_SHARED_FILE = "sharedfile" +# This is used to order determine the default disk template when the list +# of enabled disk templates is inferred from the current state of the cluster. +# This only happens on an upgrade from a version of Ganeti that did not +# support the 'enabled_disk_templates' so far. +DISK_TEMPLATE_PREFERENCE = [ + DT_DRBD8, + DT_PLAIN, + DT_FILE, + DT_SHARED_FILE, + DT_RBD, + DT_BLOCK, + DT_DISKLESS, + DT_EXT + ] + +DISK_TEMPLATES = compat.UniqueFrozenset([ + DT_DISKLESS, + DT_PLAIN, + DT_DRBD8, + DT_FILE, + DT_SHARED_FILE, + DT_BLOCK, + DT_RBD, + DT_EXT + ]) + +# disk templates that are enabled by default +DEFAULT_ENABLED_DISK_TEMPLATES = compat.UniqueFrozenset([ + DT_DRBD8, + DT_PLAIN, + ]) + # mapping of disk templates to storage types DISK_TEMPLATES_STORAGE_TYPE = { DT_BLOCK: ST_BLOCK, @@ -645,17 +665,6 @@ RIE_CONNECT_RETRIES = 10 #: Give child process up to 5 seconds to exit after sending a signal CHILD_LINGER_TIMEOUT = 5.0 -DISK_TEMPLATES = compat.UniqueFrozenset([ - DT_DISKLESS, - DT_PLAIN, - DT_DRBD8, - DT_FILE, - DT_SHARED_FILE, - DT_BLOCK, - DT_RBD, - DT_EXT - ]) - FILE_DRIVER = compat.UniqueFrozenset([FD_LOOP, FD_BLKTAP]) # import/export config options diff --git a/lib/objects.py b/lib/objects.py index d8dbca0d8..4cc4c0c0b 100644 --- a/lib/objects.py +++ b/lib/objects.py @@ -477,37 +477,38 @@ class ConfigData(ConfigObject): self.networks = {} for network in self.networks.values(): network.UpgradeConfig() - self._UpgradeStorageTypes() + self._UpgradeEnabledDiskTemplates() - def _UpgradeStorageTypes(self): - """Upgrade the cluster's enabled storage types by inspecting the currently - enabled and/or used storage types. + def _UpgradeEnabledDiskTemplates(self): + """Upgrade the cluster's enabled disk templates by inspecting the currently + enabled and/or used disk templates. """ - # enabled_storage_types in the cluster config were introduced in 2.8. Remove - # this code once upgrading from earlier versions is deprecated. - if not self.cluster.enabled_storage_types: - storage_type_set = \ - set([constants.DISK_TEMPLATES_STORAGE_TYPE[inst.disk_template] - for inst in self.instances.values()]) - # Add lvm, file and shared file storage, if they are enabled, even though - # they might currently not be used. + # enabled_disk_templates in the cluster config were introduced in 2.8. + # Remove this code once upgrading from earlier versions is deprecated. + if not self.cluster.enabled_disk_templates: + template_set = \ + set([inst.disk_template for inst in self.instances.values()]) + # Add drbd and plain, if lvm is enabled (by specifying a volume group) if self.cluster.volume_group_name: - storage_type_set.add(constants.ST_LVM_VG) + template_set.add(constants.DT_DRBD8) + template_set.add(constants.DT_PLAIN) # FIXME: Adapt this when dis/enabling at configure time is removed. + # Enable 'file' and 'sharedfile', if they are enabled, even though they + # might currently not be used. if constants.ENABLE_FILE_STORAGE: - storage_type_set.add(constants.ST_FILE) + template_set.add(constants.DT_FILE) if constants.ENABLE_SHARED_FILE_STORAGE: - storage_type_set.add(constants.ST_SHARED_FILE) - # Set enabled_storage_types to the inferred storage types. Order them + template_set.add(constants.DT_SHARED_FILE) + # Set enabled_disk_templates to the inferred disk templates. Order them # according to a preference list that is based on Ganeti's history of - # supported storage types. - self.cluster.enabled_storage_types = [] - for preferred_type in constants.STORAGE_TYPES_PREFERENCE: - if preferred_type in storage_type_set: - self.cluster.enabled_storage_types.append(preferred_type) - storage_type_set.remove(preferred_type) - self.cluster.enabled_storage_types.extend(list(storage_type_set)) + # supported disk templates. + self.cluster.enabled_disk_templates = [] + for preferred_template in constants.DISK_TEMPLATE_PREFERENCE: + if preferred_template in template_set: + self.cluster.enabled_disk_templates.append(preferred_template) + template_set.remove(preferred_template) + self.cluster.enabled_disk_templates.extend(list(template_set)) class NIC(ConfigObject): @@ -1540,7 +1541,10 @@ class Cluster(TaggableObject): "prealloc_wipe_disks", "hv_state_static", "disk_state_static", + # Keeping this in temporarily to not break the build between patches of + # this series. Remove after 'enabled_disk_templates' is fully implemented. "enabled_storage_types", + "enabled_disk_templates", ] + _TIMESTAMPS + _UUID def UpgradeConfig(self): diff --git a/src/Ganeti/Objects.hs b/src/Ganeti/Objects.hs index bfbab6baa..2cb9984a2 100644 --- a/src/Ganeti/Objects.hs +++ b/src/Ganeti/Objects.hs @@ -706,7 +706,10 @@ $(buildObject "Cluster" "cluster" $ , simpleField "primary_ip_family" [t| IpFamily |] , simpleField "prealloc_wipe_disks" [t| Bool |] , simpleField "ipolicy" [t| FilledIPolicy |] + -- FIXME: Remove enabled storage types once enabled disk templates + -- is fully implemented. , simpleField "enabled_storage_types" [t| [StorageType] |] + , simpleField "enabled_disk_templates" [t| [DiskTemplate] |] ] ++ timeStampFields ++ uuidFields -- GitLab