diff --git a/NEWS b/NEWS index dd823c05d9df4843f0943d1565e66a5b49e0d89f..09fc29e324c598d5ccd1427ff686235678ed98a0 100644 --- a/NEWS +++ b/NEWS @@ -11,6 +11,13 @@ Version 2.8.0 beta1 - The :doc:`Remote API <rapi>` daemon now supports a command line flag to always require authentication, ``--require-authentication``. It can be specified in ``$sysconfdir/default/ganeti``. +- A new cluster attribute 'enabled_storage_types' is introduced. It will + be used to manage the storage types to be used by instances in the cluster. + Initially, it will be set to a list that includes lvm, file and sharedfile + if those are enabled. Additionally, it will include all storage types that + are currently used by instances. The order of storage types will be based + on Ganeti's history of supporting them. In the future, the first entry of + the list will be used as a default storage type on instance creation. Version 2.7.0 beta1 diff --git a/lib/constants.py b/lib/constants.py index 458ee2c3799a0ab01e267c1c096217b740e7adb2..5a4e465313bef5121f4a34363676ea651a39c66a 100644 --- a/lib/constants.py +++ b/lib/constants.py @@ -373,24 +373,24 @@ HKR_FAIL = 1 HKR_SUCCESS = 2 # Storage types +ST_BLOCK = "blockdev" +ST_DISKLESS = "diskless" +ST_EXT = "ext" ST_FILE = "file" ST_LVM_PV = "lvm-pv" ST_LVM_VG = "lvm-vg" -ST_DISKLESS = "diskless" -ST_SHARED_FILE = "sharedfile" -ST_BLOCK = "blockdev" ST_RADOS = "rados" -ST_EXT = "ext" +ST_SHARED_FILE = "sharedfile" VALID_STORAGE_TYPES = compat.UniqueFrozenset([ + ST_BLOCK, + ST_DISKLESS, + ST_EXT, ST_FILE, ST_LVM_PV, ST_LVM_VG, - ST_DISKLESS, - ST_SHARED_FILE, - ST_BLOCK, ST_RADOS, - ST_EXT, + ST_SHARED_FILE, ]) # Per default, only lvm is enabled. @@ -398,6 +398,18 @@ 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" @@ -437,14 +449,26 @@ VALID_STORAGE_OPERATIONS = { LDS_FAULTY) = range(1, 4) # disk template types +DT_BLOCK = "blockdev" DT_DISKLESS = "diskless" -DT_PLAIN = "plain" DT_DRBD8 = "drbd" +DT_EXT = "ext" DT_FILE = "file" -DT_SHARED_FILE = "sharedfile" -DT_BLOCK = "blockdev" +DT_PLAIN = "plain" DT_RBD = "rbd" -DT_EXT = "ext" +DT_SHARED_FILE = "sharedfile" + +# mapping of disk templates to storage types +DISK_TEMPLATES_STORAGE_TYPE = { + DT_BLOCK: ST_BLOCK, + DT_DISKLESS: ST_DISKLESS, + DT_DRBD8: ST_LVM_VG, + DT_EXT: ST_EXT, + DT_FILE: ST_FILE, + DT_PLAIN: ST_LVM_VG, + DT_RBD: ST_RADOS, + DT_SHARED_FILE: ST_SHARED_FILE, + } # the set of network-mirrored disk templates DTS_INT_MIRROR = compat.UniqueFrozenset([DT_DRBD8]) diff --git a/lib/objects.py b/lib/objects.py index 2fdf7bce8b342cf6338b2e8342a7353108076121..782dacc9b93c60e59dc8c0d2fff32d2e606659f0 100644 --- a/lib/objects.py +++ b/lib/objects.py @@ -463,6 +463,37 @@ class ConfigData(ConfigObject): self.networks = {} for network in self.networks.values(): network.UpgradeConfig() + self._UpgradeStorageTypes() + + def _UpgradeStorageTypes(self): + """Upgrade the cluster's enabled storage types by inspecting the currently + enabled and/or used storage types. + + """ + # 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. + if self.cluster.volume_group_name: + storage_type_set.add(constants.ST_LVM_VG) + # FIXME: Adapt this when dis/enabling at configure time is removed. + if constants.ENABLE_FILE_STORAGE: + storage_type_set.add(constants.ST_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 + # 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)) class NIC(ConfigObject):