From 6b294c53bb19399e67a6663270cf0579d921727f Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Mon, 20 Oct 2008 14:47:07 +0000 Subject: [PATCH] Convert rpc.call_upload_file to use addresses This patch allows rpc.call_upload_file to use addresses (if passed), and also converts the ConfigWriter._DistributeConfig to pass them, since this is an often-done operation. Reviewed-by: imsnah --- lib/config.py | 11 +++++++++-- lib/rpc.py | 12 ++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/config.py b/lib/config.py index 2b30e608b..3fd8dc57f 100644 --- a/lib/config.py +++ b/lib/config.py @@ -820,8 +820,15 @@ class ConfigWriter: nodelist.remove(myhostname) except ValueError: pass - - result = rpc.RpcRunner.call_upload_file(nodelist, self._cfg_file) + # 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 + address_list = [self._UnlockedGetNodeInfo(name).primary_ip + for name in nodelist] + + result = rpc.RpcRunner.call_upload_file(nodelist, self._cfg_file, + address_list=address_list) for node in nodelist: if not result[node]: logging.error("copy of file %s to node %s failed", diff --git a/lib/rpc.py b/lib/rpc.py index 096699d51..dab37f8ad 100644 --- a/lib/rpc.py +++ b/lib/rpc.py @@ -666,7 +666,7 @@ class RpcRunner(object): return c.GetResults().get(node, False) @staticmethod - def call_upload_file(node_list, file_name): + def call_upload_file(node_list, file_name, address_list=None): """Upload a file. The node will refuse the operation in case the file is not on the @@ -674,6 +674,14 @@ class RpcRunner(object): This is a multi-node call. + @type node_list: list + @param node_list: the list of node names to upload to + @type file_name: str + @param file_name: the filename to upload + @type address_list: list or None + @keyword address_list: an optional list of node addresses, in order + to optimize the RPC speed + """ fh = file(file_name) try: @@ -684,7 +692,7 @@ class RpcRunner(object): params = [file_name, data, st.st_mode, st.st_uid, st.st_gid, st.st_atime, st.st_mtime] c = Client("upload_file", params) - c.ConnectList(node_list) + c.ConnectList(node_list, address_list=address_list) c.Run() return c.GetResults() -- GitLab