From 44caf5a8a08f727e9971c5e6481acd9403ff4907 Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Fri, 5 Mar 2010 18:21:35 +0100 Subject: [PATCH] Validate the hostnames at creation time MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: Iustin Pop <iustin@google.com> Reviewed-by: Michael Hanselmann <hansmi@google.com> --- lib/bootstrap.py | 2 +- lib/cmdlib.py | 6 ++++++ scripts/gnt-node | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/bootstrap.py b/lib/bootstrap.py index b0fc18025..7d9671244 100644 --- a/lib/bootstrap.py +++ b/lib/bootstrap.py @@ -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): diff --git a/lib/cmdlib.py b/lib/cmdlib.py index 85555da39..99b11b407 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -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", diff --git a/scripts/gnt-node b/scripts/gnt-node index 55d36bcdf..aaef9daa3 100755 --- a/scripts/gnt-node +++ b/scripts/gnt-node @@ -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 -- GitLab