Provides a set of tools for executing a wide range commands, statements, expressions or functions on a remote host by running a server process on the remote host serving requests without disconnecting. This allows for a sequence of operations to be done remotely and not losing state. A file could be opened remotely, do some other things and then write to the same opened file without opening the file again.
The remote server can be executed as a different user by using the sudo option and sending seteuid. The server can be executed locally as well using fork when running as the same user or using the shell when the sudo option is used.
In order to use this module the user id must be able to 'ssh' to the remote host without the need for a password.
Methods defined here: --------------------- __del__(self) Destructor __init__(self, port, logfile=None) Remote procedure server log(self, msg) Write message to log file start(self)
Rexec object Rexec() -> New remote procedure object Arguments: servername: Name or IP address of remote server logfile: Name of logfile to create on remote server sudo: Run remote server as root Usage: from nfstest.rexec import Rexec # Function to be defined at remote host def add_one(n): return n + 1 # Function to be defined at remote host def get_time(delay=0): time.sleep(delay) return time.time() # Create remote procedure object x = Rexec("192.168.0.85") # Define function at remote host x.rcode(add_one) # Evaluate the expression calling add_one() out = x.reval("add_one(67)") # Run the function with the given argument out = x.run("add_one", 7) # Run built-in functions import time out = x.run(time.time) # Import libraries and symbols x.rimport("time", ["sleep"]) x.run("sleep", 2) # Define function at remote host -- since function uses the # time module, this module must be first imported x.rimport("time") x.rcode(get_time) # Evaluate the expression calling get_time() out = x.reval("get_time()") # Run the function with the given argument out = x.run("get_time", 10) # Open file on remote host fd = x.run(os.open, "/tmp/testfile", os.O_WRONLY|os.O_CREAT|os.O_TRUNC) count = x.run(os.write, fd, "hello there ") x.run(os.close, fd) # Use of positional arguments out = x.run("get_time", 2) # Use of named arguments out = x.run("get_time", delay=2) # Use of NOWAIT option for long running functions so other things # can be done while waiting x.run("get_time", 2, NOWAIT=True) while True: # Poll every 0.1 secs to see if function has finished if x.poll(0.1): # Get results out = x.results() break # Create remote procedure object as a different user # First, run the remote server as root x = Rexec("192.168.0.85", sudo=True) # Then set the effective user id x.run(os.seteuid, 1000) Methods defined here: --------------------- __del__(self) Destructor __init__(self, servername=None, logfile=None, sudo=False, timeout=30.0) Constructor Initialize object's private data.