Commit 2f20d07b authored by Manuel Franceschini's avatar Manuel Franceschini

Add new cluster parameter primary_ip_version

We expose the ip_version (4, 6) to the external interface and internally
we convert it to ip_family (AF_INET=2, AF_INET6=10). This makes the code
more concise as all functions deal with family rather than version.

This patch does not yet expose this parameter via gnt-cluster, but only uses
the constant IP4_VERSION. This will be enabled in a future patch.
Signed-off-by: default avatarManuel Franceschini <livewire@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent e7b3ad26
......@@ -223,7 +223,8 @@ def InitCluster(cluster_name, mac_prefix,
nicparams=None, hvparams=None, enabled_hypervisors=None,
modify_etc_hosts=True, modify_ssh_setup=True,
maintain_node_health=False, drbd_helper=None,
uid_pool=None, default_iallocator=None):
uid_pool=None, default_iallocator=None,
primary_ip_version=None):
"""Initialise the cluster.
@type candidate_pool_size: int
......@@ -244,39 +245,56 @@ def InitCluster(cluster_name, mac_prefix,
" entries: %s" % invalid_hvs,
errors.ECODE_INVAL)
hostname = netutils.GetHostname()
if netutils.IP4Address.IsLoopback(hostname.ip):
ipcls = None
if primary_ip_version == constants.IP4_VERSION:
ipcls = netutils.IP4Address
elif primary_ip_version == constants.IP6_VERSION:
ipcls = netutils.IP6Address
else:
raise errors.OpPrereqError("Invalid primary ip version: %d." %
primary_ip_version)
hostname = netutils.GetHostname(family=ipcls.family)
if not ipcls.IsValid(hostname.ip):
raise errors.OpPrereqError("This host's IP (%s) is not a valid IPv%d"
" address." % (hostname.ip, primary_ip_version))
if ipcls.IsLoopback(hostname.ip):
raise errors.OpPrereqError("This host's IP (%s) resolves to a loopback"
" address. Please fix DNS or %s." %
(hostname.ip, constants.ETC_HOSTS),
errors.ECODE_ENVIRON)
if not netutils.IPAddress.Own(hostname.ip):
if not ipcls.Own(hostname.ip):
raise errors.OpPrereqError("Inconsistency: this host's name resolves"
" to %s,\nbut this ip address does not"
" belong to this host. Aborting." %
hostname.ip, errors.ECODE_ENVIRON)
clustername = netutils.GetHostname(name=cluster_name)
clustername = netutils.GetHostname(name=cluster_name, family=ipcls.family)
if netutils.TcpPing(clustername.ip, constants.DEFAULT_NODED_PORT,
timeout=5):
if netutils.TcpPing(clustername.ip, constants.DEFAULT_NODED_PORT, timeout=5):
raise errors.OpPrereqError("Cluster IP already active. Aborting.",
errors.ECODE_NOTUNIQUE)
if secondary_ip:
if not netutils.IP4Address.IsValid(secondary_ip):
raise errors.OpPrereqError("Invalid secondary ip given",
errors.ECODE_INVAL)
if (secondary_ip != hostname.ip and
not netutils.IPAddress.Own(secondary_ip)):
raise errors.OpPrereqError("You gave %s as secondary IP,"
" but it does not belong to this host." %
secondary_ip, errors.ECODE_ENVIRON)
else:
if not secondary_ip:
if primary_ip_version == constants.IP6_VERSION:
raise errors.OpPrereqError("When using a IPv6 primary address, a valid"
" IPv4 address must be given as secondary."
" Aborting.", errors.ECODE_INVAL)
secondary_ip = hostname.ip
if not netutils.IP4Address.IsValid(secondary_ip):
raise errors.OpPrereqError("Secondary IP address (%s) has to be a valid"
" IPv4 address." % secondary_ip,
errors.ECODE_INVAL)
if not netutils.IP4Address.Own(secondary_ip):
raise errors.OpPrereqError("You gave %s as secondary IP,"
" but it does not belong to this host." %
secondary_ip, errors.ECODE_ENVIRON)
if vg_name is not None:
# Check if volume group is valid
vgstatus = utils.CheckVolumeGroupSize(utils.ListVolumeGroups(), vg_name,
......@@ -373,6 +391,7 @@ def InitCluster(cluster_name, mac_prefix,
maintain_node_health=maintain_node_health,
drbd_usermode_helper=drbd_helper,
default_iallocator=default_iallocator,
primary_ip_family=ipcls.family,
)
master_node_config = objects.Node(name=hostname.name,
primary_ip=hostname.ip,
......
......@@ -450,6 +450,8 @@ IP4_ADDRESS_LOCALHOST = "127.0.0.1"
IP4_ADDRESS_ANY = "0.0.0.0"
IP6_ADDRESS_LOCALHOST = "::1"
IP6_ADDRESS_ANY = "::"
IP4_VERSION = 4
IP6_VERSION = 6
TCP_PING_TIMEOUT = 10
GANETI_RUNAS = "root"
DEFAULT_VG = "xenvg"
......
#
#
# Copyright (C) 2006, 2007 Google Inc.
# Copyright (C) 2006, 2007, 2010 Google Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......@@ -919,6 +919,7 @@ class Cluster(TaggableObject):
"maintain_node_health",
"uid_pool",
"default_iallocator",
"primary_ip_family",
] + _TIMESTAMPS + _UUID
def UpgradeConfig(self):
......
#!/usr/bin/python
#
# Copyright (C) 2006, 2007 Google Inc.
# Copyright (C) 2006, 2007, 2010 Google Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......@@ -122,6 +122,7 @@ def InitCluster(opts, args):
drbd_helper=drbd_helper,
uid_pool=uid_pool,
default_iallocator=opts.default_iallocator,
primary_ip_version=constants.IP4_VERSION,
)
op = opcodes.OpPostInitCluster()
SubmitOpCode(op, opts=opts)
......
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