Commit d9c02ca6 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

Move {Set,Remove}EtcHostsEntry wrappers to utils.py

This is required for the split of the cluster initialization code.

Reviewed-by: iustinp, ultrotter
parent c6d58a2b
......@@ -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,
......
......@@ -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.
......
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