diff --git a/lib/cmdlib.py b/lib/cmdlib.py index 86f6da22ce385cbd839800f74ff75c514ddfcacd..15f33b2a39851acb4614a4eaf3019612b4e0e5e7 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 7aa75e105d1b1935be7b767b17d89a38e06005dd..ba5fe3e35e3875c52e01d1dcadbb93978cd2abe2 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.