Commit 02691904 authored by Alexander Schreiber's avatar Alexander Schreiber
Browse files

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
parent 99aabbed
......@@ -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,
)
......
......@@ -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,
......
......@@ -688,7 +688,7 @@ class Cluster(TaggableObject):
"mac_prefix",
"volume_group_name",
"default_bridge",
"hypervisor",
"default_hypervisor",
"master_node",
"master_ip",
"master_netdev",
......
......@@ -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"
......
......@@ -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,
......
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