diff --git a/lib/bootstrap.py b/lib/bootstrap.py index 1401aba93ee42acc8fd6d502dc65639b0285c311..6d53c2ee5fa5b43a65d57c987600415b441024ef 100644 --- a/lib/bootstrap.py +++ b/lib/bootstrap.py @@ -170,7 +170,7 @@ def InitCluster(cluster_name, mac_prefix, " entries: %s" % invalid_hvs, errors.ECODE_INVAL) - hostname = utils.HostInfo() + hostname = utils.GetHostInfo() if hostname.ip.startswith("127."): raise errors.OpPrereqError("This host's IP resolves to the private" @@ -184,7 +184,7 @@ def InitCluster(cluster_name, mac_prefix, " belong to this host. Aborting." % hostname.ip, errors.ECODE_ENVIRON) - clustername = utils.HostInfo(cluster_name) + clustername = utils.GetHostInfo(cluster_name) if utils.TcpPing(clustername.ip, constants.DEFAULT_NODED_PORT, timeout=5): diff --git a/lib/cmdlib.py b/lib/cmdlib.py index c054e6b0f08c5086f24d6f790fc8f1734c5fb8e0..9b11c98cafb6aa7d3f32053c8d7334dfdd94d31d 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -1788,7 +1788,7 @@ class LURenameCluster(LogicalUnit): """Verify that the passed name is a valid one. """ - hostname = utils.HostInfo(self.op.name) + hostname = utils.GetHostInfo(self.op.name) new_name = hostname.name self.ip = new_ip = hostname.ip @@ -2843,7 +2843,7 @@ class LUAddNode(LogicalUnit): node_name = self.op.node_name cfg = self.cfg - dns_data = utils.HostInfo(node_name) + dns_data = utils.GetHostInfo(node_name) node = dns_data.name primary_ip = self.op.primary_ip = dns_data.ip @@ -4041,7 +4041,7 @@ class LURenameInstance(LogicalUnit): self.instance = instance # new name verification - name_info = utils.HostInfo(self.op.new_name) + name_info = utils.GetHostInfo(self.op.new_name) self.op.new_name = new_name = name_info.name instance_list = self.cfg.GetInstanceList() @@ -5606,7 +5606,7 @@ class LUCreateInstance(LogicalUnit): #### instance parameters check # instance name verification - hostname1 = utils.HostInfo(self.op.instance_name) + hostname1 = utils.GetHostInfo(self.op.instance_name) self.op.instance_name = instance_name = hostname1.name # this is just a preventive check, but someone might still add this diff --git a/lib/errors.py b/lib/errors.py index 81fa565c98b3d59bb015d195b3148c3c3d1b11f4..d11959130d281ee5c4ce3b6bbdbee465192a6a0a 100644 --- a/lib/errors.py +++ b/lib/errors.py @@ -24,6 +24,8 @@ # OpPrereqError failure types +# resolver errors +ECODE_RESOLVER = "resolver_error" # not enough resources (iallocator failure, disk space, memory, etc.) ECODE_NORES = "insufficient_resources" # wrong arguments (at syntax level) diff --git a/lib/utils.py b/lib/utils.py index 36ae6e56239fad484b8a9eb55ac421a72067c91a..ec7fec83844c86d6d99ef7523349518cc22268be 100644 --- a/lib/utils.py +++ b/lib/utils.py @@ -590,6 +590,16 @@ class HostInfo: return result +def GetHostInfo(name=None): + """Lookup host name and raise an OpPrereqError for failures""" + + try: + return HostInfo(name) + except errors.ResolverError, err: + raise errors.OpPrereqError("The given name (%s) does not resolve: %s" % + (err[0], err[2]), errors.ECODE_RESOLVER) + + def ListVolumeGroups(): """List volume groups and their size diff --git a/scripts/gnt-cluster b/scripts/gnt-cluster index f398cc51a7992703fed06f1c3c530025d0c60f35..f6101ba3735a593cb3e032432dc1793d6c07b0fa 100755 --- a/scripts/gnt-cluster +++ b/scripts/gnt-cluster @@ -285,7 +285,7 @@ def ClusterCopyFile(opts, args): cl = GetClient() - myname = utils.HostInfo().name + myname = utils.GetHostInfo().name cluster_name = cl.QueryConfigValues(["cluster_name"])[0] diff --git a/scripts/gnt-node b/scripts/gnt-node index 205365af97c7e21e1ae117b23a2057b07d0d4464..e4421105413cf55a503f2ba27bfd8da477fba9ff 100755 --- a/scripts/gnt-node +++ b/scripts/gnt-node @@ -130,7 +130,7 @@ def AddNode(opts, args): """ cl = GetClient() - dns_data = utils.HostInfo(args[0]) + dns_data = utils.GetHostInfo(args[0]) node = dns_data.name readd = opts.readd