Commit 21a17f33 authored by Hrvoje Ribicic's avatar Hrvoje Ribicic
Browse files

Add file info RPC call



Due to the need to determine the size of the temporary disk used for
the VM helper, an RPC call capable of supplying this information has
been added. It can be extended as needed to supply additional
information provided by Python's os.stat.
Signed-off-by: default avatarHrvoje Ribicic <riba@google.com>
Reviewed-by: default avatarJose A. Lopes <jabolopes@google.com>
parent b1b4b282
......@@ -4675,6 +4675,30 @@ def ConfigureOVS(ovs_name, ovs_link):
result.output), log=True)
def GetFileInfo(file_path):
""" Checks if a file exists and returns information related to it.
Currently returned information:
- file size: int, size in bytes
@type file_path: string
@param file_path: Name of file to examine.
@rtype: tuple of bool, dict
@return: Whether the file exists, and a dictionary of information about the
file gathered by os.stat.
"""
try:
stat_info = os.stat(file_path)
values_dict = {
constants.STAT_SIZE: stat_info.st_size,
}
return True, values_dict
except IOError:
return False, {}
class HooksRunner(object):
"""Hook runner.
......
......@@ -560,6 +560,9 @@ _MISC_CALLS = [
("set_watcher_pause", MULTI, None, constants.RPC_TMO_URGENT, [
("until", None, None),
], None, None, "Set watcher pause end"),
("get_file_info", SINGLE, None, constants.RPC_TMO_FAST, [
("file_path", None, None),
], None, None, "Checks if a file exists and reports on it"),
]
CALLS = {
......
......@@ -969,6 +969,14 @@ class NodeRequestHandler(http.server.HttpServerHandler):
(until, ) = params
return backend.SetWatcherPause(until)
@staticmethod
def perspective_get_file_info(params):
"""Get info on whether a file exists and its properties.
"""
(path, ) = params
return backend.GetFileInfo(path)
# os -----------------------
@staticmethod
......
......@@ -4873,3 +4873,12 @@ debugModeConfidentialityWarning :: String
debugModeConfidentialityWarning =
"ALERT: %s started in debug mode.\n\
\ Private and secret parameters WILL be logged!\n"
-- * Stat dictionary entries
--
-- The get_file_info RPC returns a number of values as a dictionary, and the
-- following constants are both descriptions and means of accessing them.
-- | The size of the file
statSize :: String
statSize = "size"
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