Commit ea8ac9c9 authored by René Nussbaumer's avatar René Nussbaumer

Switch to the RPC call to update /etc/hosts in LUAddNode and LURemoveNode

Signed-off-by: default avatarRené Nussbaumer <rn@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent 19ddc57a
...@@ -348,7 +348,7 @@ def InitCluster(cluster_name, mac_prefix, ...@@ -348,7 +348,7 @@ def InitCluster(cluster_name, mac_prefix,
sshkey = sshline.split(" ")[1] sshkey = sshline.split(" ")[1]
if modify_etc_hosts: if modify_etc_hosts:
utils.AddHostToEtcHosts(hostname) utils.AddHostToEtcHosts(hostname.name, hostname.ip)
if modify_ssh_setup: if modify_ssh_setup:
_InitSSHSetup() _InitSSHSetup()
......
...@@ -3272,8 +3272,11 @@ class LURemoveNode(LogicalUnit): ...@@ -3272,8 +3272,11 @@ class LURemoveNode(LogicalUnit):
# Remove node from our /etc/hosts # Remove node from our /etc/hosts
if self.cfg.GetClusterInfo().modify_etc_hosts: if self.cfg.GetClusterInfo().modify_etc_hosts:
# FIXME: this should be done via an rpc call to node daemon master_node = self.cfg.GetMasterNode()
utils.RemoveHostFromEtcHosts(node.name) result = self.rpc.call_etc_hosts_modify(master_node,
constants.ETC_HOSTS_REMOVE,
node.name, None)
result.Raise("Can't update hosts file with new host data")
_RedistributeAncillaryFiles(self) _RedistributeAncillaryFiles(self)
...@@ -3829,8 +3832,12 @@ class LUAddNode(LogicalUnit): ...@@ -3829,8 +3832,12 @@ class LUAddNode(LogicalUnit):
# Add node to our /etc/hosts, and add key to known_hosts # Add node to our /etc/hosts, and add key to known_hosts
if self.cfg.GetClusterInfo().modify_etc_hosts: if self.cfg.GetClusterInfo().modify_etc_hosts:
# FIXME: this should be done via an rpc call to node daemon master_node = self.cfg.GetMasterNode()
utils.AddHostToEtcHosts(self.hostname) result = self.rpc.call_etc_hosts_modify(master_node,
constants.ETC_HOSTS_ADD,
self.hostname.name,
self.hostname.ip)
result.Raise("Can't update hosts file with new host data")
if new_node.secondary_ip != new_node.primary_ip: if new_node.secondary_ip != new_node.primary_ip:
result = self.rpc.call_node_has_ip_address(new_node.name, result = self.rpc.call_node_has_ip_address(new_node.name,
......
...@@ -1462,16 +1462,17 @@ def SetEtcHostsEntry(file_name, ip, hostname, aliases): ...@@ -1462,16 +1462,17 @@ def SetEtcHostsEntry(file_name, ip, hostname, aliases):
WriteFile(file_name, fn=_WriteEtcHosts, mode=0644) WriteFile(file_name, fn=_WriteEtcHosts, mode=0644)
def AddHostToEtcHosts(hostname): def AddHostToEtcHosts(hostname, ip):
"""Wrapper around SetEtcHostsEntry. """Wrapper around SetEtcHostsEntry.
@type hostname: str @type hostname: str
@param hostname: a hostname that will be resolved and added to @param hostname: a hostname that will be resolved and added to
L{constants.ETC_HOSTS} L{constants.ETC_HOSTS}
@type ip: str
@param ip: The ip address of the host
""" """
SetEtcHostsEntry(constants.ETC_HOSTS, hostname.ip, hostname.name, SetEtcHostsEntry(constants.ETC_HOSTS, ip, hostname, [hostname.split(".")[0]])
[hostname.name.split(".")[0]])
def RemoveEtcHostsEntry(file_name, hostname): def RemoveEtcHostsEntry(file_name, hostname):
......
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