From d9c02ca60e750980153187266946abb384feb8c2 Mon Sep 17 00:00:00 2001 From: Michael Hanselmann <hansmi@google.com> Date: Thu, 12 Jun 2008 13:04:23 +0000 Subject: [PATCH] Move {Set,Remove}EtcHostsEntry wrappers to utils.py This is required for the split of the cluster initialization code. Reviewed-by: iustinp, ultrotter --- lib/cmdlib.py | 23 +++-------------------- lib/utils.py | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/lib/cmdlib.py b/lib/cmdlib.py index 86f6da22c..15f33b2a3 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -182,23 +182,6 @@ class NoHooksLU(LogicalUnit): HTYPE = None -def _AddHostToEtcHosts(hostname): - """Wrapper around utils.SetEtcHostsEntry. - - """ - hi = utils.HostInfo(name=hostname) - utils.SetEtcHostsEntry(constants.ETC_HOSTS, hi.ip, hi.name, [hi.ShortName()]) - - -def _RemoveHostFromEtcHosts(hostname): - """Wrapper around utils.RemoveEtcHostsEntry. - - """ - hi = utils.HostInfo(name=hostname) - utils.RemoveEtcHostsEntry(constants.ETC_HOSTS, hi.name) - utils.RemoveEtcHostsEntry(constants.ETC_HOSTS, hi.ShortName()) - - def _GetWantedNodes(lu, nodes): """Returns list of checked and expanded node names. @@ -556,7 +539,7 @@ class LUInitCluster(LogicalUnit): f.close() sshkey = sshline.split(" ")[1] - _AddHostToEtcHosts(hostname.name) + utils.AddHostToEtcHosts(hostname.name) _InitSSHSetup(hostname.name) # init of cluster config file @@ -1491,7 +1474,7 @@ class LURemoveNode(LogicalUnit): self.cfg.RemoveNode(node.name) - _RemoveHostFromEtcHosts(node.name) + utils.RemoveHostFromEtcHosts(node.name) class LUQueryNodes(NoHooksLU): @@ -1853,7 +1836,7 @@ class LUAddNode(LogicalUnit): raise errors.OpExecError("Cannot transfer ssh keys to the new node") # Add node to our /etc/hosts, and add key to known_hosts - _AddHostToEtcHosts(new_node.name) + utils.AddHostToEtcHosts(new_node.name) if new_node.secondary_ip != new_node.primary_ip: if not rpc.call_node_tcp_ping(new_node.name, diff --git a/lib/utils.py b/lib/utils.py index 7aa75e105..ba5fe3e35 100644 --- a/lib/utils.py +++ b/lib/utils.py @@ -781,6 +781,14 @@ def SetEtcHostsEntry(file_name, ip, hostname, aliases): raise +def AddHostToEtcHosts(hostname): + """Wrapper around SetEtcHostsEntry. + + """ + hi = HostInfo(name=hostname) + SetEtcHostsEntry(constants.ETC_HOSTS, hi.ip, hi.name, [hi.ShortName()]) + + def RemoveEtcHostsEntry(file_name, hostname): """Removes a hostname from /etc/hosts. @@ -817,6 +825,15 @@ def RemoveEtcHostsEntry(file_name, hostname): raise +def RemoveHostFromEtcHosts(hostname): + """Wrapper around RemoveEtcHostsEntry. + + """ + hi = HostInfo(name=hostname) + RemoveEtcHostsEntry(constants.ETC_HOSTS, hi.name) + RemoveEtcHostsEntry(constants.ETC_HOSTS, hi.ShortName()) + + def CreateBackup(file_name): """Creates a backup of a file. -- GitLab