Commit 6b294c53 authored by Iustin Pop's avatar Iustin Pop
Browse files

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
parent 25348212
......@@ -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",
......
......@@ -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()
......
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