From 066f465dbc53dd8ae80442dfe2592602be1ac231 Mon Sep 17 00:00:00 2001 From: Guido Trotter <ultrotter@google.com> Date: Tue, 14 Jul 2009 18:37:49 +0200 Subject: [PATCH] Get rid of the default_hypervisor slot Currently we have both a default_hypervisor and an enabled_hypervisors list. The former is only settable at cluster init time, while the latter can be changed with cluster modify. This becomes cumbersome in a few ways: at cluster init time for example if we pass in a list of enabled hypervisors which doesn't include the "default" xen-pvm one, we're also forced to pass a default hypervisor, or an error will be reported. It is also currently possible to disable the default hypervisor in cluster-modify (with unknown results). In order to avoid this we get rid of this field altogether, and define the "first" enabled hypervisor as the default one. This allows ease of changing which one is the default, and at the same time maintains coherency. At configuration upgrade we make sure that the old default is first in the list, so that 2.0 cluster defaults are preserved. Signed-off-by: Guido Trotter <ultrotter@google.com> Reviewed-by: Iustin Pop <iustin@google.com> --- lib/bootstrap.py | 3 +-- lib/cmdlib.py | 2 +- lib/config.py | 2 +- lib/objects.py | 8 ++++++++ man/gnt-cluster.sgml | 12 +++--------- scripts/gnt-cluster | 19 ++----------------- test/ganeti.config_unittest.py | 2 +- 7 files changed, 17 insertions(+), 31 deletions(-) diff --git a/lib/bootstrap.py b/lib/bootstrap.py index d4e5a091e..a94a9e5ff 100644 --- a/lib/bootstrap.py +++ b/lib/bootstrap.py @@ -128,7 +128,7 @@ def InitCluster(cluster_name, mac_prefix, master_netdev, file_storage_dir, candidate_pool_size, secondary_ip=None, vg_name=None, beparams=None, nicparams=None, hvparams=None, enabled_hypervisors=None, - default_hypervisor=None, modify_etc_hosts=True): + modify_etc_hosts=True): """Initialise the cluster. @type candidate_pool_size: int @@ -252,7 +252,6 @@ def InitCluster(cluster_name, mac_prefix, cluster_name=clustername.name, file_storage_dir=file_storage_dir, enabled_hypervisors=enabled_hypervisors, - default_hypervisor=default_hypervisor, beparams={constants.PP_DEFAULT: beparams}, nicparams={constants.PP_DEFAULT: nicparams}, hvparams=hvparams, diff --git a/lib/cmdlib.py b/lib/cmdlib.py index 493f5a19e..88d600d07 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -2627,7 +2627,7 @@ class LUQueryClusterInfo(NoHooksLU): "architecture": (platform.architecture()[0], platform.machine()), "name": cluster.cluster_name, "master": cluster.master_node, - "default_hypervisor": cluster.default_hypervisor, + "default_hypervisor": cluster.enabled_hypervisors[0], "enabled_hypervisors": cluster.enabled_hypervisors, "hvparams": dict([(hypervisor_name, cluster.hvparams[hypervisor_name]) for hypervisor_name in cluster.enabled_hypervisors]), diff --git a/lib/config.py b/lib/config.py index acdca2ea0..d75236351 100644 --- a/lib/config.py +++ b/lib/config.py @@ -658,7 +658,7 @@ class ConfigWriter: """Get the hypervisor type for this cluster. """ - return self._config_data.cluster.default_hypervisor + return self._config_data.cluster.enabled_hypervisors[0] @locking.ssynchronized(_config_lock, shared=1) def GetHostKey(self): diff --git a/lib/objects.py b/lib/objects.py index 106b704aa..918411241 100644 --- a/lib/objects.py +++ b/lib/objects.py @@ -811,6 +811,14 @@ class Cluster(TaggableObject): if self.default_bridge is not None: self.default_bridge = None + # default_hypervisor is just the first enabled one in 2.1 + if self.default_hypervisor is not None: + self.enabled_hypervisors = [self.default_hypervisor] + \ + [hvname for hvname in self.enabled_hypervisors + if hvname != self.default_hypervisor] + self.default_hypervisor = None + + def ToDict(self): """Custom function for cluster. diff --git a/man/gnt-cluster.sgml b/man/gnt-cluster.sgml index 220b3c90b..4c39cbd18 100644 --- a/man/gnt-cluster.sgml +++ b/man/gnt-cluster.sgml @@ -313,8 +313,9 @@ The <option>--enabled-hypervisors</option> option allows you to set the list of hypervisors that will be enabled for this cluster. Instance hypervisors can only be choosen from - the list of enabled hypervisors. Currently, the following - hypervisors are available: + the list of enabled hypervisors, and the first entry of this list + will be used by default. Currently, the following hypervisors are + available: </para> <para> @@ -360,13 +361,6 @@ specified, only the xen-pvm hypervisor is enabled by default. </para> - <para> - With the <option>-t</option> option, the default hypervisor - can be set. It has to be a member of the list of enabled - hypervisors. If not specified, the first entry on the list of - enabled hypervisors will be used by default. - </para> - <para> The <option>--backend-parameters</option> option allows you to set the default backend parameters for the cluster. The parameter diff --git a/scripts/gnt-cluster b/scripts/gnt-cluster index 66c9c65eb..b41a380c2 100755 --- a/scripts/gnt-cluster +++ b/scripts/gnt-cluster @@ -58,17 +58,7 @@ def InitCluster(opts, args): vg_name = constants.DEFAULT_VG hvlist = opts.enabled_hypervisors - if hvlist is not None: - hvlist = hvlist.split(",") - else: - hvlist = [opts.default_hypervisor] - - # avoid an impossible situation - if opts.default_hypervisor not in hvlist: - ToStderr("The default hypervisor requested (%s) is not" - " within the enabled hypervisor list (%s)" % - (opts.default_hypervisor, hvlist)) - return 1 + hvlist = hvlist.split(",") hvparams = dict(opts.hvparams) beparams = opts.beparams @@ -101,7 +91,6 @@ def InitCluster(opts, args): master_netdev=opts.master_netdev, file_storage_dir=opts.file_storage_dir, enabled_hypervisors=hvlist, - default_hypervisor=opts.default_hypervisor, hvparams=hvparams, beparams=beparams, nicparams=nicparams, @@ -578,11 +567,7 @@ commands = { action="store_false", default=True,), make_option("--enabled-hypervisors", dest="enabled_hypervisors", help="Comma-separated list of hypervisors", - type="string", default=None), - make_option("-t", "--default-hypervisor", - dest="default_hypervisor", - help="Default hypervisor to use for instance creation", - choices=list(constants.HYPER_TYPES), + type="string", default=constants.DEFAULT_ENABLED_HYPERVISOR), ikv_option("-H", "--hypervisor-parameters", dest="hvparams", help="Hypervisor and hypervisor options, in the" diff --git a/test/ganeti.config_unittest.py b/test/ganeti.config_unittest.py index 9287fc3d0..64210d9bb 100755 --- a/test/ganeti.config_unittest.py +++ b/test/ganeti.config_unittest.py @@ -68,7 +68,7 @@ class TestConfigRunner(unittest.TestCase): volume_group_name="xenvg", nicparams={constants.PP_DEFAULT: constants.NICC_DEFAULTS}, tcpudp_port_pool=set(), - default_hypervisor=constants.HT_FAKE, + enabled_hypervisors=[constants.HT_FAKE], master_node=me.name, master_ip="127.0.0.1", master_netdev=constants.DEFAULT_BRIDGE, -- GitLab