On Wed, Apr 2, 2014 at 4:23 PM, Jose A. Lopes <[email protected]> wrote:
> On Apr 02 13:30, Hrvoje Ribicic wrote: > > 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: Hrvoje Ribicic <[email protected]> > > --- > > lib/backend.py | 17 +++++++++++++++++ > > lib/rpc_defs.py | 3 +++ > > lib/server/noded.py | 8 ++++++++ > > src/Ganeti/Constants.hs | 9 +++++++++ > > 4 files changed, 37 insertions(+) > > > > diff --git a/lib/backend.py b/lib/backend.py > > index 3118242..98a6fb7 100644 > > --- a/lib/backend.py > > +++ b/lib/backend.py > > @@ -4631,6 +4631,23 @@ 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. > > + > > + @type file_path: string > > + @param file_path: Name of file to examine. > > @return, @rtype > > Ack. > > + > > + """ > > + 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. > > > > diff --git a/lib/rpc_defs.py b/lib/rpc_defs.py > > index ccf2359..4b81712 100644 > > --- a/lib/rpc_defs.py > > +++ b/lib/rpc_defs.py > > @@ -557,6 +557,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_NORMAL, [ > > RPC_TMO_URGENT instead of NORMAL? > Will change it to FAST instead, 1 minute may be too little time. > > + ("file_path", None, None), > > + ], None, None, "Checks if a file exists and reports on it"), > > ] > > > > CALLS = { > > diff --git a/lib/server/noded.py b/lib/server/noded.py > > index cbffa8e2..4fe42b7 100644 > > --- a/lib/server/noded.py > > +++ b/lib/server/noded.py > > @@ -961,6 +961,14 @@ class > NodeRequestHandler(http.server.HttpServerHandler): > > (until, ) = params > > return backend.SetWatcherPause(until) > > > > + @staticmethod > > + def perspective_get_file_info(params): > > + """Retrieves the status of an import or export daemon. > > Docstring is incorrect. > Ack. > > > + > > + """ > > + (path, ) = params > > + return backend.GetFileInfo(path) > > + > > # os ----------------------- > > > > @staticmethod > > diff --git a/src/Ganeti/Constants.hs b/src/Ganeti/Constants.hs > > index c2e3e36..8be545a 100644 > > --- a/src/Ganeti/Constants.hs > > +++ b/src/Ganeti/Constants.hs > > @@ -4867,3 +4867,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 function returns a number of values as a > dictionary, and > > s/GetFileInfo/get_file_info/ or s/function/RPC > Ack. > > Rest LGTM. > > Thanks, > Jose > > > +-- the following constants are both descriptions and means of accessing > them. > > + > > +-- | The size of the file > > +statSize :: String > > +statSize = "size" > > -- > > 1.9.1.423.g4596e3a > > > > -- > Jose Antonio Lopes > Ganeti Engineering > Google Germany GmbH > Dienerstr. 12, 80331, München > > Registergericht und -nummer: Hamburg, HRB 86891 > Sitz der Gesellschaft: Hamburg > Geschäftsführer: Graham Law, Christine Elizabeth Flores > Steuernummer: 48/725/00206 > Umsatzsteueridentifikationsnummer: DE813741370 > Thanks for the review, interdiff is: diff --git a/lib/backend.py b/lib/backend.py index 98a6fb7..c97d859 100644 --- a/lib/backend.py +++ b/lib/backend.py @@ -4637,6 +4637,13 @@ def GetFileInfo(file_path): @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. + + Currently returned information: + file size: int, size in bytes + """ try: stat_info = os.stat(file_path) diff --git a/lib/rpc_defs.py b/lib/rpc_defs.py index 4b81712..763bf08 100644 --- a/lib/rpc_defs.py +++ b/lib/rpc_defs.py @@ -557,7 +557,7 @@ _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_NORMAL, [ + ("get_file_info", SINGLE, None, constants.RPC_TMO_FAST, [ ("file_path", None, None), ], None, None, "Checks if a file exists and reports on it"), ] diff --git a/lib/server/noded.py b/lib/server/noded.py index 4fe42b7..eaa1b97 100644 --- a/lib/server/noded.py +++ b/lib/server/noded.py @@ -963,7 +963,7 @@ class NodeRequestHandler(http.server.HttpServerHandler): @staticmethod def perspective_get_file_info(params): - """Retrieves the status of an import or export daemon. + """Get info on whether a file exists and its properties. """ (path, ) = params diff --git a/src/Ganeti/Constants.hs b/src/Ganeti/Constants.hs index 8be545a..ee550bf 100644 --- a/src/Ganeti/Constants.hs +++ b/src/Ganeti/Constants.hs @@ -4870,8 +4870,8 @@ debugModeConfidentialityWarning = -- * Stat dictionary entries -- --- The get_file_info function returns a number of values as a dictionary, and --- the following constants are both descriptions and means of accessing them. +-- 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
