1REXEC(3) rexec 1.2 REXEC(3)
2
3
4
6 nfstest.rexec - Remote procedure module
7
9 Provides a set of tools for executing a wide range commands, stateā
10 ments, expressions or functions on a remote host by running a server
11 process on the remote host serving requests without disconnecting. This
12 allows for a sequence of operations to be done remotely and not losing
13 state. A file could be opened remotely, do some other things and then
14 write to the same opened file without opening the file again.
15
16 The remote server can be executed as a different user by using the sudo
17 option and sending seteuid. The server can be executed locally as well
18 using fork when running as the same user or using the shell when the
19 sudo option is used.
20
21 In order to use this module the user id must be able to 'ssh' to the
22 remote host without the need for a password.
23
25 class RemoteServer
26 Methods defined here:
27 ---------------------
28
29 __del__(self)
30 Destructor
31
32 __init__(self, port, logfile=None)
33 Remote procedure server
34
35 log(self, msg)
36 Write message to log file
37
38 start(self)
39
40 class Rexec(baseobj.BaseObj)
41 Rexec object
42
43 Rexec() -> New remote procedure object
44
45 Arguments:
46 servername:
47 Name or IP address of remote server
48 logfile:
49 Name of logfile to create on remote server
50 sudo:
51 Run remote server as root
52
53 Usage:
54 from nfstest.rexec import Rexec
55
56 # Function to be defined at remote host
57 def add_one(n):
58 return n + 1
59
60 # Function to be defined at remote host
61 def get_time(delay=0):
62 time.sleep(delay)
63 return time.time()
64
65 # Create remote procedure object
66 x = Rexec("192.168.0.85")
67
68 # Define function at remote host
69 x.rcode(add_one)
70
71 # Evaluate the expression calling add_one()
72 out = x.reval("add_one(67)")
73
74 # Run the function with the given argument
75 out = x.run("add_one", 7)
76
77 # Run built-in functions
78 import time
79 out = x.run(time.time)
80
81 # Import libraries and symbols
82 x.rimport("time", ["sleep"])
83 x.run("sleep", 2)
84
85 # Define function at remote host -- since function uses the
86 # time module, this module must be first imported
87 x.rimport("time")
88 x.rcode(get_time)
89
90 # Evaluate the expression calling get_time()
91 out = x.reval("get_time()")
92
93 # Run the function with the given argument
94 out = x.run("get_time", 10)
95
96 # Open file on remote host
97 fd = x.run(os.open, "/tmp/testfile", os.O_WRONLY|os.O_CREAT|os.O_TRUNC)
98 count = x.run(os.write, fd, "hello there
99 ")
100 x.run(os.close, fd)
101
102 # Use of positional arguments
103 out = x.run("get_time", 2)
104
105 # Use of named arguments
106 out = x.run("get_time", delay=2)
107
108 # Use of NOWAIT option for long running functions so other things
109 # can be done while waiting
110 x.run("get_time", 2, NOWAIT=True)
111 while True:
112 # Poll every 0.1 secs to see if function has finished
113 if x.poll(0.1):
114 # Get results
115 out = x.results()
116 break
117
118 # Create remote procedure object as a different user
119 # First, run the remote server as root
120 x = Rexec("192.168.0.85", sudo=True)
121 # Then set the effective user id
122 x.run(os.seteuid, 1000)
123
124
125 Methods defined here:
126 ---------------------
127
128 __del__(self)
129 Destructor
130
131 __init__(self, servername=None, logfile=None, sudo=False, sync_timeout=0.1)
132 Constructor
133
134 Initialize object's private data.
135
136
137 servername:
138 Host name or IP address of host where remote server will run
139 [Default: None (run locally)]
140
141 logfile:
142 Pathname of log file to be created on remote host
143 [Default: None]
144
145 sudo: Run remote procedure server as root
146 [Default: False]
147
148 sync_timeout:
149 Timeout used for synchronizing the connection stream
150 [Default: 0.1]
151
152 close(self)
153 Close connection to remote server
154
155 poll(self, timeout=0)
156 Return whether there is any data available to be read
157
158
159 timeout:
160 Maximum time in seconds to block, if timeout is None then
161 an infinite timeout is used
162
163 rcode(self, code)
164 Define function on remote server
165
166 results(self)
167 Return pending results
168
169 reval(self, expr)
170 Evaluate expression on remote server
171
172 rexec(self, expr)
173 Execute statement on remote server
174
175 rimport(self, module, symbols=[])
176 Import module on remote server
177
178
179 module:
180 Module to import in the remote server
181
182 symbols:
183 If given, import only these symbols from the module
184
185 run(self, *kwts, **kwds)
186 Run function on remote server
187
188 The first positional argument is the function to be executed.
189 All other positional arguments and any named arguments are treated
190 as arguments to the function
191
192 wait(self, objlist=None, timeout=0)
193 Return a list of Rexec objects where data is available to be read
194
195
196 objlist:
197 List of Rexec objects to poll, if not given use current object
198
199 timeout:
200 Maximum time in seconds to block, if timeout is None then
201 an infinite timeout is used
202
204 baseobj(3)
205
206
208 No known bugs.
209
211 Jorge Mora (mora@netapp.com)
212
213
214
215NFStest 2.1.5 14 February 2017 REXEC(3)