Commit 44caf5a8 authored by Iustin Pop's avatar Iustin Pop
Browse files

Validate the hostnames at creation time



This patch adds validation of new names used, i.e. at cluster init time,
node add time, and instance creation.

For instances, especially when using «--no-name-check» (which skips DNS
checks), we should validate the give name, and also normalize it
(otherwise, we could have two instances named inst1 and Inst1).
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent 26288e68
......@@ -190,7 +190,7 @@ def InitCluster(cluster_name, mac_prefix,
" belong to this host. Aborting." %
hostname.ip, errors.ECODE_ENVIRON)
clustername = utils.GetHostInfo(cluster_name)
clustername = utils.GetHostInfo(utils.HostInfo.NormalizeName(cluster_name))
if utils.TcpPing(clustername.ip, constants.DEFAULT_NODED_PORT,
timeout=5):
......
......@@ -2907,6 +2907,10 @@ class LUAddNode(LogicalUnit):
HTYPE = constants.HTYPE_NODE
_OP_REQP = ["node_name"]
def CheckArguments(self):
# validate/normalize the node name
self.op.node_name = utils.HostInfo.NormalizeName(self.op.node_name)
def BuildHooksEnv(self):
"""Build hooks env.
......@@ -5654,6 +5658,8 @@ class LUCreateInstance(LogicalUnit):
# for tools
if not hasattr(self.op, "name_check"):
self.op.name_check = True
# validate/normalize the instance name
self.op.instance_name = utils.HostInfo.NormalizeName(self.op.instance_name)
if self.op.ip_check and not self.op.name_check:
# TODO: make the ip check more flexible and not depend on the name check
raise errors.OpPrereqError("Cannot do ip checks without a name check",
......
......@@ -133,7 +133,7 @@ def AddNode(opts, args):
"""
cl = GetClient()
dns_data = utils.GetHostInfo(args[0])
dns_data = utils.GetHostInfo(utils.HostInfo.NormalizeName(args[0]))
node = dns_data.name
readd = opts.readd
......
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