This resolver can use the internal, unlocked functions.
---
 lib/config.py |   15 +++++++++------
 lib/rpc.py    |    8 +-------
 2 files changed, 10 insertions(+), 13 deletions(-)

diff --git a/lib/config.py b/lib/config.py
index b394419..7185d27 100644
--- a/lib/config.py
+++ b/lib/config.py
@@ -49,6 +49,7 @@ from ganeti import serializer
 from ganeti import uidpool
 from ganeti import netutils
 from ganeti import runtime
+from ganeti import compat
 
 
 _config_lock = locking.SharedLock("ConfigWriter")
@@ -166,6 +167,11 @@ class ConfigWriter:
     self._cfg_id = None
     self._OpenConfig(accept_foreign)
 
+    resolver = compat.partial(rpc.NodeConfigResolver,
+                              self._UnlockedGetNodeInfo,
+                              self._UnlockedGetAllNodesInfo)
+    self._rpc = rpc.ConfigRunner(resolver)
+
   # this method needs to be static, so that we can call it on the class
   @staticmethod
   def IsCluster():
@@ -1715,12 +1721,12 @@ class ConfigWriter:
     bad = False
 
     node_list = []
-    addr_list = []
     myhostname = self._my_hostname
     # we can skip checking whether _UnlockedGetNodeInfo returns None
     # since the node list comes from _UnlocketGetNodeList, and we are
     # called with the lock held, so no modifications should take place
     # in between
+    # TODO: Cache list of node names instead of building it every time
     for node_name in self._UnlockedGetNodeList():
       if node_name == myhostname:
         continue
@@ -1728,11 +1734,8 @@ class ConfigWriter:
       if not node_info.master_candidate:
         continue
       node_list.append(node_info.name)
-      addr_list.append(node_info.primary_ip)
 
-    # TODO: Use dedicated resolver talking to config writer for name resolution
-    result = \
-      rpc.ConfigRunner(addr_list).call_upload_file(node_list, self._cfg_file)
+    result = self._rpc.call_upload_file(node_list, self._cfg_file)
     for to_node, to_result in result.items():
       msg = to_result.fail_msg
       if msg:
@@ -1791,7 +1794,7 @@ class ConfigWriter:
     # Write ssconf files on all nodes (including locally)
     if self._last_cluster_serial < self._config_data.cluster.serial_no:
       if not self._offline:
-        result = rpc.ConfigRunner(None).call_write_ssconf_files(
+        result = self._rpc.call_write_ssconf_files(
           self._UnlockedGetOnlineNodeList(),
           self._UnlockedGetSsconfValues())
 
diff --git a/lib/rpc.py b/lib/rpc.py
index 0aaf0a1..52e6db1 100644
--- a/lib/rpc.py
+++ b/lib/rpc.py
@@ -659,18 +659,12 @@ class ConfigRunner(_generated_rpc.RpcClientConfig):
   _PrepareFileUpload = \
     staticmethod(RpcRunner._PrepareFileUpload) # pylint: disable=W0212
 
-  def __init__(self, address_list):
+  def __init__(self, resolver):
     """Initializes this class.
 
     """
     _generated_rpc.RpcClientConfig.__init__(self)
 
-    if address_list is None:
-      resolver = _SsconfResolver
-    else:
-      # Caller provided an address list
-      resolver = _StaticResolver(address_list)
-
     self._proc = _RpcProcessor(resolver,
                                netutils.GetDaemonPort(constants.NODED))
 
-- 
1.7.6

Reply via email to