Switch to the RPC call to update /etc/hosts in LUAddNode and LURemoveNode
authorRené Nussbaumer <rn@google.com>
Fri, 23 Jul 2010 11:49:19 +0000 (13:49 +0200)
committerRené Nussbaumer <rn@google.com>
Mon, 23 Aug 2010 12:40:40 +0000 (14:40 +0200)
Signed-off-by: René Nussbaumer <rn@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>

lib/bootstrap.py
lib/cmdlib.py
lib/utils.py

index 6e19112..5a07895 100644 (file)
@@ -348,7 +348,7 @@ def InitCluster(cluster_name, mac_prefix,
   sshkey = sshline.split(" ")[1]
 
   if modify_etc_hosts:
-    utils.AddHostToEtcHosts(hostname)
+    utils.AddHostToEtcHosts(hostname.name, hostname.ip)
 
   if modify_ssh_setup:
     _InitSSHSetup()
index 9ae3f62..0c63a69 100644 (file)
@@ -3272,8 +3272,11 @@ class LURemoveNode(LogicalUnit):
 
     # 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)
 
 
@@ -3829,8 +3832,12 @@ class LUAddNode(LogicalUnit):
 
     # 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,
index 7492484..f4a3db5 100644 (file)
@@ -1462,16 +1462,17 @@ def SetEtcHostsEntry(file_name, ip, hostname, aliases):
   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):