sshkey = sshline.split(" ")[1]
if modify_etc_hosts:
- utils.AddHostToEtcHosts(hostname)
+ utils.AddHostToEtcHosts(hostname.name, hostname.ip)
if modify_ssh_setup:
_InitSSHSetup()
# Remove node from our /etc/hosts
if self.cfg.GetClusterInfo().modify_etc_hosts:
- # FIXME: this should be done via an rpc call to node daemon
- utils.RemoveHostFromEtcHosts(node.name)
+ master_node = self.cfg.GetMasterNode()
+ 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)
# Add node to our /etc/hosts, and add key to known_hosts
if self.cfg.GetClusterInfo().modify_etc_hosts:
- # FIXME: this should be done via an rpc call to node daemon
- utils.AddHostToEtcHosts(self.hostname)
+ master_node = self.cfg.GetMasterNode()
+ 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:
result = self.rpc.call_node_has_ip_address(new_node.name,
WriteFile(file_name, fn=_WriteEtcHosts, mode=0644)
-def AddHostToEtcHosts(hostname):
+def AddHostToEtcHosts(hostname, ip):
"""Wrapper around SetEtcHostsEntry.
@type hostname: str
@param hostname: a hostname that will be resolved and added to
L{constants.ETC_HOSTS}
+ @type ip: str
+ @param ip: The ip address of the host
"""
- SetEtcHostsEntry(constants.ETC_HOSTS, hostname.ip, hostname.name,
- [hostname.name.split(".")[0]])
+ SetEtcHostsEntry(constants.ETC_HOSTS, ip, hostname, [hostname.split(".")[0]])
def RemoveEtcHostsEntry(file_name, hostname):