From 02691904fad3df9d657d65b980dfca6893b6e3f4 Mon Sep 17 00:00:00 2001 From: Alexander Schreiber <als@google.com> Date: Mon, 20 Oct 2008 16:38:28 +0000 Subject: [PATCH] Set default hypervisor at cluster init During cluster init, set the default hypervisor to be used for instances. Ensure that the default hypervisor belongs to the set enabled hypervisors for this cluster. Also fix a small bug with setting the default enabled hypervisor list. Reviewed-by: imsnah --- lib/bootstrap.py | 3 ++- lib/cmdlib.py | 2 +- lib/objects.py | 2 +- scripts/gnt-cluster | 16 ++++++++++++++-- test/ganeti.config_unittest.py | 2 +- 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/lib/bootstrap.py b/lib/bootstrap.py index 74cead0b2..0fa69bb6a 100644 --- a/lib/bootstrap.py +++ b/lib/bootstrap.py @@ -109,7 +109,7 @@ def InitCluster(cluster_name, mac_prefix, def_bridge, master_netdev, file_storage_dir, secondary_ip=None, vg_name=None, beparams=None, hvparams=None, - enabled_hypervisors=None): + enabled_hypervisors=None, default_hypervisor=None): """Initialise the cluster. """ @@ -215,6 +215,7 @@ def InitCluster(cluster_name, mac_prefix, def_bridge, cluster_name=clustername.name, file_storage_dir=file_storage_dir, enabled_hypervisors=enabled_hypervisors, + default_hypervisor=default_hypervisor, beparams={constants.BEGR_DEFAULT: beparams}, hvparams=hvparams, ) diff --git a/lib/cmdlib.py b/lib/cmdlib.py index 3d2ccc8ce..ac3f26864 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -1915,7 +1915,7 @@ class LUQueryClusterInfo(NoHooksLU): "architecture": (platform.architecture()[0], platform.machine()), "name": cluster.cluster_name, "master": cluster.master_node, - "hypervisor_type": cluster.hypervisor, + "default_hypervisor": cluster.default_hypervisor, "enabled_hypervisors": cluster.enabled_hypervisors, "hvparams": cluster.hvparams, "beparams": cluster.beparams, diff --git a/lib/objects.py b/lib/objects.py index d941ed0a8..6c74876d7 100644 --- a/lib/objects.py +++ b/lib/objects.py @@ -688,7 +688,7 @@ class Cluster(TaggableObject): "mac_prefix", "volume_group_name", "default_bridge", - "hypervisor", + "default_hypervisor", "master_node", "master_ip", "master_netdev", diff --git a/scripts/gnt-cluster b/scripts/gnt-cluster index 6b2e93984..d150966f9 100755 --- a/scripts/gnt-cluster +++ b/scripts/gnt-cluster @@ -56,7 +56,13 @@ def InitCluster(opts, args): if hvlist is not None: hvlist = hvlist.split(",") else: - hvlist = constants.DEFAULT_ENABLED_HYPERVISOR + hvlist = [constants.DEFAULT_ENABLED_HYPERVISOR] + + # avoid an impossible situation + if opts.default_hypervisor in hvlist: + default_hypervisor = opts.default_hypervisor + else: + default_hypervisor = hvlist[0] hvparams = opts.hvparams if hvparams: @@ -108,6 +114,7 @@ def InitCluster(opts, args): master_netdev=opts.master_netdev, file_storage_dir=opts.file_storage_dir, enabled_hypervisors=hvlist, + default_hypervisor=default_hypervisor, hvparams=hvparams, beparams=beparams) return 0 @@ -197,7 +204,7 @@ def ShowClusterConfig(opts, args): ToStdout("Architecture (this node): %s (%s)", result["architecture"][0], result["architecture"][1]) - ToStdout("Default hypervisor: %s", result["hypervisor_type"]) + ToStdout("Default hypervisor: %s", result["default_hypervisor"]) ToStdout("Enabled hypervisors: %s", ", ".join(result["enabled_hypervisors"])) ToStdout("Hypervisor parameters:") @@ -490,6 +497,11 @@ commands = { 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), + default=constants.DEFAULT_ENABLED_HYPERVISOR), ikv_option("-H", "--hypervisor-parameters", dest="hvparams", help="Hypervisor and hypervisor options, in the" " format" diff --git a/test/ganeti.config_unittest.py b/test/ganeti.config_unittest.py index 5588830f2..eb3ebc797 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", default_bridge=constants.DEFAULT_BRIDGE, tcpudp_port_pool=set(), - hypervisor=constants.HT_FAKE, + default_hypervisor=constants.HT_FAKE, master_node=me.name, master_ip="127.0.0.1", master_netdev=constants.DEFAULT_BRIDGE, -- GitLab