Revision 12bce260 lib/rpc.py
b/lib/rpc.py | ||
---|---|---|
33 | 33 |
import os |
34 | 34 |
import socket |
35 | 35 |
import logging |
36 |
import zlib |
|
37 |
import base64 |
|
36 | 38 |
|
37 | 39 |
from ganeti import utils |
38 | 40 |
from ganeti import objects |
... | ... | |
334 | 336 |
c.ConnectNode(node) |
335 | 337 |
return c.GetResults()[node] |
336 | 338 |
|
339 |
@staticmethod |
|
340 |
def _Compress(data): |
|
341 |
"""Compresses a string for transport over RPC. |
|
342 |
|
|
343 |
Small amounts of data are not compressed. |
|
344 |
|
|
345 |
@type data: str |
|
346 |
@param data: Data |
|
347 |
@rtype: tuple |
|
348 |
@return: Encoded data to send |
|
349 |
|
|
350 |
""" |
|
351 |
# Small amounts of data are not compressed |
|
352 |
if len(data) < 512: |
|
353 |
return (constants.RPC_ENCODING_NONE, data) |
|
354 |
|
|
355 |
# Compress with zlib and encode in base64 |
|
356 |
return (constants.RPC_ENCODING_ZLIB_BASE64, |
|
357 |
base64.b64encode(zlib.compress(data, 3))) |
|
358 |
|
|
337 | 359 |
# |
338 | 360 |
# Begin RPC calls |
339 | 361 |
# |
... | ... | |
688 | 710 |
to optimize the RPC speed |
689 | 711 |
|
690 | 712 |
""" |
691 |
data = utils.ReadFile(file_name) |
|
713 |
file_contents = utils.ReadFile(file_name) |
|
714 |
data = cls._Compress(file_contents) |
|
692 | 715 |
st = os.stat(file_name) |
693 | 716 |
params = [file_name, data, st.st_mode, st.st_uid, st.st_gid, |
694 | 717 |
st.st_atime, st.st_mtime] |
... | ... | |
907 | 930 |
|
908 | 931 |
""" |
909 | 932 |
return cls._StaticMultiNodeCall(node_list, "jobqueue_update", |
910 |
[file_name, content],
|
|
933 |
[file_name, cls._Compress(content)],
|
|
911 | 934 |
address_list=address_list) |
912 | 935 |
|
913 | 936 |
@classmethod |
Also available in: Unified diff