Commit 066f465d authored by Guido Trotter's avatar Guido Trotter
Browse files

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: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 00b66530
......@@ -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,
......
......@@ -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]),
......
......@@ -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):
......
......@@ -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.
......
......@@ -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
......
......@@ -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"
......
......@@ -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,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment