root / lib / luxi.py @ f9780ccd
History | View | Annotate | Download (10.8 kB)
1 | c2a03789 | Iustin Pop | #
|
---|---|---|---|
2 | c2a03789 | Iustin Pop | #
|
3 | c2a03789 | Iustin Pop | |
4 | c2a03789 | Iustin Pop | # Copyright (C) 2006, 2007 Google Inc.
|
5 | c2a03789 | Iustin Pop | #
|
6 | c2a03789 | Iustin Pop | # This program is free software; you can redistribute it and/or modify
|
7 | c2a03789 | Iustin Pop | # it under the terms of the GNU General Public License as published by
|
8 | c2a03789 | Iustin Pop | # the Free Software Foundation; either version 2 of the License, or
|
9 | c2a03789 | Iustin Pop | # (at your option) any later version.
|
10 | c2a03789 | Iustin Pop | #
|
11 | c2a03789 | Iustin Pop | # This program is distributed in the hope that it will be useful, but
|
12 | c2a03789 | Iustin Pop | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | c2a03789 | Iustin Pop | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | c2a03789 | Iustin Pop | # General Public License for more details.
|
15 | c2a03789 | Iustin Pop | #
|
16 | c2a03789 | Iustin Pop | # You should have received a copy of the GNU General Public License
|
17 | c2a03789 | Iustin Pop | # along with this program; if not, write to the Free Software
|
18 | c2a03789 | Iustin Pop | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 | c2a03789 | Iustin Pop | # 02110-1301, USA.
|
20 | c2a03789 | Iustin Pop | |
21 | c2a03789 | Iustin Pop | |
22 | c2a03789 | Iustin Pop | """Module for the unix socket protocol
|
23 | c2a03789 | Iustin Pop |
|
24 | 8d5b316c | Iustin Pop | This module implements the local unix socket protocol. You only need
|
25 | c2a03789 | Iustin Pop | this module and the opcodes module in the client program in order to
|
26 | c2a03789 | Iustin Pop | communicate with the master.
|
27 | c2a03789 | Iustin Pop |
|
28 | 7577196d | Guido Trotter | The module is also used by the master daemon.
|
29 | c2a03789 | Iustin Pop |
|
30 | c2a03789 | Iustin Pop | """
|
31 | c2a03789 | Iustin Pop | |
32 | c2a03789 | Iustin Pop | import socket |
33 | c2a03789 | Iustin Pop | import collections |
34 | c2a03789 | Iustin Pop | import time |
35 | 03a8dbdc | Iustin Pop | import errno |
36 | c2a03789 | Iustin Pop | |
37 | fad50141 | Michael Hanselmann | from ganeti import serializer |
38 | ceab32dd | Iustin Pop | from ganeti import constants |
39 | 6797ec29 | Iustin Pop | from ganeti import errors |
40 | c2a03789 | Iustin Pop | |
41 | c2a03789 | Iustin Pop | |
42 | 3d8548c4 | Michael Hanselmann | KEY_METHOD = 'method'
|
43 | 3d8548c4 | Michael Hanselmann | KEY_ARGS = 'args'
|
44 | 3d8548c4 | Michael Hanselmann | KEY_SUCCESS = "success"
|
45 | 3d8548c4 | Michael Hanselmann | KEY_RESULT = "result"
|
46 | 3d8548c4 | Michael Hanselmann | |
47 | 0bbe448c | Michael Hanselmann | REQ_SUBMIT_JOB = "SubmitJob"
|
48 | 2971c913 | Iustin Pop | REQ_SUBMIT_MANY_JOBS = "SubmitManyJobs"
|
49 | dfe57c22 | Michael Hanselmann | REQ_WAIT_FOR_JOB_CHANGE = "WaitForJobChange"
|
50 | 0bbe448c | Michael Hanselmann | REQ_CANCEL_JOB = "CancelJob"
|
51 | 0bbe448c | Michael Hanselmann | REQ_ARCHIVE_JOB = "ArchiveJob"
|
52 | 07cd723a | Iustin Pop | REQ_AUTOARCHIVE_JOBS = "AutoArchiveJobs"
|
53 | 0bbe448c | Michael Hanselmann | REQ_QUERY_JOBS = "QueryJobs"
|
54 | ee6c7b94 | Michael Hanselmann | REQ_QUERY_INSTANCES = "QueryInstances"
|
55 | 02f7fe54 | Michael Hanselmann | REQ_QUERY_NODES = "QueryNodes"
|
56 | 32f93223 | Michael Hanselmann | REQ_QUERY_EXPORTS = "QueryExports"
|
57 | ae5849b5 | Michael Hanselmann | REQ_QUERY_CONFIG_VALUES = "QueryConfigValues"
|
58 | 66baeccc | Iustin Pop | REQ_QUERY_CLUSTER_INFO = "QueryClusterInfo"
|
59 | 3ccafd0e | Iustin Pop | REQ_QUEUE_SET_DRAIN_FLAG = "SetDrainFlag"
|
60 | c2a03789 | Iustin Pop | |
61 | c2a03789 | Iustin Pop | DEF_CTMO = 10
|
62 | c2a03789 | Iustin Pop | DEF_RWTO = 60
|
63 | c2a03789 | Iustin Pop | |
64 | c2a03789 | Iustin Pop | |
65 | c2a03789 | Iustin Pop | class ProtocolError(Exception): |
66 | c2a03789 | Iustin Pop | """Denotes an error in the server communication"""
|
67 | c2a03789 | Iustin Pop | |
68 | c2a03789 | Iustin Pop | |
69 | c2a03789 | Iustin Pop | class ConnectionClosedError(ProtocolError): |
70 | c2a03789 | Iustin Pop | """Connection closed error"""
|
71 | c2a03789 | Iustin Pop | |
72 | c2a03789 | Iustin Pop | |
73 | c2a03789 | Iustin Pop | class TimeoutError(ProtocolError): |
74 | c2a03789 | Iustin Pop | """Operation timeout error"""
|
75 | c2a03789 | Iustin Pop | |
76 | c2a03789 | Iustin Pop | |
77 | c2a03789 | Iustin Pop | class EncodingError(ProtocolError): |
78 | c2a03789 | Iustin Pop | """Encoding failure on the sending side"""
|
79 | c2a03789 | Iustin Pop | |
80 | c2a03789 | Iustin Pop | |
81 | c2a03789 | Iustin Pop | class DecodingError(ProtocolError): |
82 | c2a03789 | Iustin Pop | """Decoding failure on the receiving side"""
|
83 | c2a03789 | Iustin Pop | |
84 | c2a03789 | Iustin Pop | |
85 | b77acb3e | Iustin Pop | class RequestError(ProtocolError): |
86 | b77acb3e | Iustin Pop | """Error on request
|
87 | b77acb3e | Iustin Pop |
|
88 | b77acb3e | Iustin Pop | This signifies an error in the request format or request handling,
|
89 | b77acb3e | Iustin Pop | but not (e.g.) an error in starting up an instance.
|
90 | b77acb3e | Iustin Pop |
|
91 | b77acb3e | Iustin Pop | Some common conditions that can trigger this exception:
|
92 | b77acb3e | Iustin Pop | - job submission failed because the job data was wrong
|
93 | b77acb3e | Iustin Pop | - query failed because required fields were missing
|
94 | b77acb3e | Iustin Pop |
|
95 | b77acb3e | Iustin Pop | """
|
96 | b77acb3e | Iustin Pop | |
97 | 3d8548c4 | Michael Hanselmann | |
98 | 03a8dbdc | Iustin Pop | class NoMasterError(ProtocolError): |
99 | 03a8dbdc | Iustin Pop | """The master cannot be reached
|
100 | 03a8dbdc | Iustin Pop |
|
101 | 03a8dbdc | Iustin Pop | This means that the master daemon is not running or the socket has
|
102 | 03a8dbdc | Iustin Pop | been removed.
|
103 | 03a8dbdc | Iustin Pop |
|
104 | 03a8dbdc | Iustin Pop | """
|
105 | 03a8dbdc | Iustin Pop | |
106 | b77acb3e | Iustin Pop | |
107 | c2a03789 | Iustin Pop | class Transport: |
108 | c2a03789 | Iustin Pop | """Low-level transport class.
|
109 | c2a03789 | Iustin Pop |
|
110 | c2a03789 | Iustin Pop | This is used on the client side.
|
111 | c2a03789 | Iustin Pop |
|
112 | c2a03789 | Iustin Pop | This could be replace by any other class that provides the same
|
113 | c2a03789 | Iustin Pop | semantics to the Client. This means:
|
114 | c2a03789 | Iustin Pop | - can send messages and receive messages
|
115 | c2a03789 | Iustin Pop | - safe for multithreading
|
116 | c2a03789 | Iustin Pop |
|
117 | c2a03789 | Iustin Pop | """
|
118 | c2a03789 | Iustin Pop | |
119 | c2a03789 | Iustin Pop | def __init__(self, address, timeouts=None, eom=None): |
120 | c2a03789 | Iustin Pop | """Constructor for the Client class.
|
121 | c2a03789 | Iustin Pop |
|
122 | c2a03789 | Iustin Pop | Arguments:
|
123 | c2a03789 | Iustin Pop | - address: a valid address the the used transport class
|
124 | c2a03789 | Iustin Pop | - timeout: a list of timeouts, to be used on connect and read/write
|
125 | c2a03789 | Iustin Pop | - eom: an identifier to be used as end-of-message which the
|
126 | c2a03789 | Iustin Pop | upper-layer will guarantee that this identifier will not appear
|
127 | c2a03789 | Iustin Pop | in any message
|
128 | c2a03789 | Iustin Pop |
|
129 | c2a03789 | Iustin Pop | There are two timeouts used since we might want to wait for a long
|
130 | c2a03789 | Iustin Pop | time for a response, but the connect timeout should be lower.
|
131 | c2a03789 | Iustin Pop |
|
132 | c2a03789 | Iustin Pop | If not passed, we use a default of 10 and respectively 60 seconds.
|
133 | c2a03789 | Iustin Pop |
|
134 | c2a03789 | Iustin Pop | Note that on reading data, since the timeout applies to an
|
135 | c2a03789 | Iustin Pop | invidual receive, it might be that the total duration is longer
|
136 | c2a03789 | Iustin Pop | than timeout value passed (we make a hard limit at twice the read
|
137 | c2a03789 | Iustin Pop | timeout).
|
138 | c2a03789 | Iustin Pop |
|
139 | c2a03789 | Iustin Pop | """
|
140 | c2a03789 | Iustin Pop | self.address = address
|
141 | c2a03789 | Iustin Pop | if timeouts is None: |
142 | c2a03789 | Iustin Pop | self._ctimeout, self._rwtimeout = DEF_CTMO, DEF_RWTO |
143 | c2a03789 | Iustin Pop | else:
|
144 | c2a03789 | Iustin Pop | self._ctimeout, self._rwtimeout = timeouts |
145 | c2a03789 | Iustin Pop | |
146 | c2a03789 | Iustin Pop | self.socket = None |
147 | c2a03789 | Iustin Pop | self._buffer = "" |
148 | c2a03789 | Iustin Pop | self._msgs = collections.deque()
|
149 | c2a03789 | Iustin Pop | |
150 | c2a03789 | Iustin Pop | if eom is None: |
151 | c2a03789 | Iustin Pop | self.eom = '\3' |
152 | c2a03789 | Iustin Pop | else:
|
153 | c2a03789 | Iustin Pop | self.eom = eom
|
154 | c2a03789 | Iustin Pop | |
155 | c2a03789 | Iustin Pop | try:
|
156 | c2a03789 | Iustin Pop | self.socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
157 | c2a03789 | Iustin Pop | self.socket.settimeout(self._ctimeout) |
158 | c2a03789 | Iustin Pop | try:
|
159 | c2a03789 | Iustin Pop | self.socket.connect(address)
|
160 | c2a03789 | Iustin Pop | except socket.timeout, err:
|
161 | 03a8dbdc | Iustin Pop | raise TimeoutError("Connect timed out: %s" % str(err)) |
162 | 03a8dbdc | Iustin Pop | except socket.error, err:
|
163 | 082c5adb | Michael Hanselmann | if err.args[0] in (errno.ENOENT, errno.ECONNREFUSED): |
164 | 03a8dbdc | Iustin Pop | raise NoMasterError((address,))
|
165 | 03a8dbdc | Iustin Pop | raise
|
166 | c2a03789 | Iustin Pop | self.socket.settimeout(self._rwtimeout) |
167 | 03a8dbdc | Iustin Pop | except (socket.error, NoMasterError):
|
168 | c2a03789 | Iustin Pop | if self.socket is not None: |
169 | c2a03789 | Iustin Pop | self.socket.close()
|
170 | c2a03789 | Iustin Pop | self.socket = None |
171 | c2a03789 | Iustin Pop | raise
|
172 | c2a03789 | Iustin Pop | |
173 | c2a03789 | Iustin Pop | def _CheckSocket(self): |
174 | c2a03789 | Iustin Pop | """Make sure we are connected.
|
175 | c2a03789 | Iustin Pop |
|
176 | c2a03789 | Iustin Pop | """
|
177 | c2a03789 | Iustin Pop | if self.socket is None: |
178 | c2a03789 | Iustin Pop | raise ProtocolError("Connection is closed") |
179 | c2a03789 | Iustin Pop | |
180 | c2a03789 | Iustin Pop | def Send(self, msg): |
181 | c2a03789 | Iustin Pop | """Send a message.
|
182 | c2a03789 | Iustin Pop |
|
183 | c2a03789 | Iustin Pop | This just sends a message and doesn't wait for the response.
|
184 | c2a03789 | Iustin Pop |
|
185 | c2a03789 | Iustin Pop | """
|
186 | c2a03789 | Iustin Pop | if self.eom in msg: |
187 | c2a03789 | Iustin Pop | raise EncodingError("Message terminator found in payload") |
188 | c2a03789 | Iustin Pop | self._CheckSocket()
|
189 | c2a03789 | Iustin Pop | try:
|
190 | 6096ee13 | Michael Hanselmann | # TODO: sendall is not guaranteed to send everything
|
191 | c2a03789 | Iustin Pop | self.socket.sendall(msg + self.eom) |
192 | c2a03789 | Iustin Pop | except socket.timeout, err:
|
193 | c2a03789 | Iustin Pop | raise TimeoutError("Sending timeout: %s" % str(err)) |
194 | c2a03789 | Iustin Pop | |
195 | c2a03789 | Iustin Pop | def Recv(self): |
196 | 5bbd3f7f | Michael Hanselmann | """Try to receive a message from the socket.
|
197 | c2a03789 | Iustin Pop |
|
198 | c2a03789 | Iustin Pop | In case we already have messages queued, we just return from the
|
199 | c2a03789 | Iustin Pop | queue. Otherwise, we try to read data with a _rwtimeout network
|
200 | c2a03789 | Iustin Pop | timeout, and making sure we don't go over 2x_rwtimeout as a global
|
201 | c2a03789 | Iustin Pop | limit.
|
202 | c2a03789 | Iustin Pop |
|
203 | c2a03789 | Iustin Pop | """
|
204 | c2a03789 | Iustin Pop | self._CheckSocket()
|
205 | c2a03789 | Iustin Pop | etime = time.time() + self._rwtimeout
|
206 | c2a03789 | Iustin Pop | while not self._msgs: |
207 | c2a03789 | Iustin Pop | if time.time() > etime:
|
208 | c2a03789 | Iustin Pop | raise TimeoutError("Extended receive timeout") |
209 | 6096ee13 | Michael Hanselmann | while True: |
210 | 6096ee13 | Michael Hanselmann | try:
|
211 | 6096ee13 | Michael Hanselmann | data = self.socket.recv(4096) |
212 | 6096ee13 | Michael Hanselmann | except socket.error, err:
|
213 | 6096ee13 | Michael Hanselmann | if err.args and err.args[0] == errno.EAGAIN: |
214 | 6096ee13 | Michael Hanselmann | continue
|
215 | 6096ee13 | Michael Hanselmann | raise
|
216 | 6096ee13 | Michael Hanselmann | except socket.timeout, err:
|
217 | 6096ee13 | Michael Hanselmann | raise TimeoutError("Receive timeout: %s" % str(err)) |
218 | 6096ee13 | Michael Hanselmann | break
|
219 | c2a03789 | Iustin Pop | if not data: |
220 | c2a03789 | Iustin Pop | raise ConnectionClosedError("Connection closed while reading") |
221 | c2a03789 | Iustin Pop | new_msgs = (self._buffer + data).split(self.eom) |
222 | c2a03789 | Iustin Pop | self._buffer = new_msgs.pop()
|
223 | c2a03789 | Iustin Pop | self._msgs.extend(new_msgs)
|
224 | c2a03789 | Iustin Pop | return self._msgs.popleft() |
225 | c2a03789 | Iustin Pop | |
226 | c2a03789 | Iustin Pop | def Call(self, msg): |
227 | c2a03789 | Iustin Pop | """Send a message and wait for the response.
|
228 | c2a03789 | Iustin Pop |
|
229 | c2a03789 | Iustin Pop | This is just a wrapper over Send and Recv.
|
230 | c2a03789 | Iustin Pop |
|
231 | c2a03789 | Iustin Pop | """
|
232 | c2a03789 | Iustin Pop | self.Send(msg)
|
233 | c2a03789 | Iustin Pop | return self.Recv() |
234 | c2a03789 | Iustin Pop | |
235 | c2a03789 | Iustin Pop | def Close(self): |
236 | c2a03789 | Iustin Pop | """Close the socket"""
|
237 | c2a03789 | Iustin Pop | if self.socket is not None: |
238 | c2a03789 | Iustin Pop | self.socket.close()
|
239 | c2a03789 | Iustin Pop | self.socket = None |
240 | c2a03789 | Iustin Pop | |
241 | c2a03789 | Iustin Pop | |
242 | c2a03789 | Iustin Pop | class Client(object): |
243 | c2a03789 | Iustin Pop | """High-level client implementation.
|
244 | c2a03789 | Iustin Pop |
|
245 | c2a03789 | Iustin Pop | This uses a backing Transport-like class on top of which it
|
246 | c2a03789 | Iustin Pop | implements data serialization/deserialization.
|
247 | c2a03789 | Iustin Pop |
|
248 | c2a03789 | Iustin Pop | """
|
249 | ceab32dd | Iustin Pop | def __init__(self, address=None, timeouts=None, transport=Transport): |
250 | c2a03789 | Iustin Pop | """Constructor for the Client class.
|
251 | c2a03789 | Iustin Pop |
|
252 | c2a03789 | Iustin Pop | Arguments:
|
253 | c2a03789 | Iustin Pop | - address: a valid address the the used transport class
|
254 | c2a03789 | Iustin Pop | - timeout: a list of timeouts, to be used on connect and read/write
|
255 | c2a03789 | Iustin Pop | - transport: a Transport-like class
|
256 | c2a03789 | Iustin Pop |
|
257 | c2a03789 | Iustin Pop |
|
258 | c2a03789 | Iustin Pop | If timeout is not passed, the default timeouts of the transport
|
259 | c2a03789 | Iustin Pop | class are used.
|
260 | c2a03789 | Iustin Pop |
|
261 | c2a03789 | Iustin Pop | """
|
262 | ceab32dd | Iustin Pop | if address is None: |
263 | ceab32dd | Iustin Pop | address = constants.MASTER_SOCKET |
264 | 8d5b316c | Iustin Pop | self.address = address
|
265 | 8d5b316c | Iustin Pop | self.timeouts = timeouts
|
266 | 8d5b316c | Iustin Pop | self.transport_class = transport
|
267 | 8d5b316c | Iustin Pop | self.transport = None |
268 | 8d5b316c | Iustin Pop | self._InitTransport()
|
269 | 8d5b316c | Iustin Pop | |
270 | 8d5b316c | Iustin Pop | def _InitTransport(self): |
271 | 8d5b316c | Iustin Pop | """(Re)initialize the transport if needed.
|
272 | 8d5b316c | Iustin Pop |
|
273 | 8d5b316c | Iustin Pop | """
|
274 | 8d5b316c | Iustin Pop | if self.transport is None: |
275 | 8d5b316c | Iustin Pop | self.transport = self.transport_class(self.address, |
276 | 8d5b316c | Iustin Pop | timeouts=self.timeouts)
|
277 | 8d5b316c | Iustin Pop | |
278 | 8d5b316c | Iustin Pop | def _CloseTransport(self): |
279 | 8d5b316c | Iustin Pop | """Close the transport, ignoring errors.
|
280 | 8d5b316c | Iustin Pop |
|
281 | 8d5b316c | Iustin Pop | """
|
282 | 8d5b316c | Iustin Pop | if self.transport is None: |
283 | 8d5b316c | Iustin Pop | return
|
284 | 8d5b316c | Iustin Pop | try:
|
285 | 8d5b316c | Iustin Pop | old_transp = self.transport
|
286 | 8d5b316c | Iustin Pop | self.transport = None |
287 | 8d5b316c | Iustin Pop | old_transp.Close() |
288 | 7c4d6c7b | Michael Hanselmann | except Exception: |
289 | 8d5b316c | Iustin Pop | pass
|
290 | c2a03789 | Iustin Pop | |
291 | 3d8548c4 | Michael Hanselmann | def CallMethod(self, method, args): |
292 | c2a03789 | Iustin Pop | """Send a generic request and return the response.
|
293 | c2a03789 | Iustin Pop |
|
294 | c2a03789 | Iustin Pop | """
|
295 | 3d8548c4 | Michael Hanselmann | # Build request
|
296 | 3d8548c4 | Michael Hanselmann | request = { |
297 | 3d8548c4 | Michael Hanselmann | KEY_METHOD: method, |
298 | 3d8548c4 | Michael Hanselmann | KEY_ARGS: args, |
299 | 3d8548c4 | Michael Hanselmann | } |
300 | 3d8548c4 | Michael Hanselmann | |
301 | 8d5b316c | Iustin Pop | # Serialize the request
|
302 | 8d5b316c | Iustin Pop | send_data = serializer.DumpJson(request, indent=False)
|
303 | 8d5b316c | Iustin Pop | |
304 | 3d8548c4 | Michael Hanselmann | # Send request and wait for response
|
305 | 8d5b316c | Iustin Pop | try:
|
306 | 8d5b316c | Iustin Pop | self._InitTransport()
|
307 | 8d5b316c | Iustin Pop | result = self.transport.Call(send_data)
|
308 | 8d5b316c | Iustin Pop | except Exception: |
309 | 8d5b316c | Iustin Pop | self._CloseTransport()
|
310 | 8d5b316c | Iustin Pop | raise
|
311 | 8d5b316c | Iustin Pop | |
312 | 8d5b316c | Iustin Pop | # Parse the result
|
313 | c2a03789 | Iustin Pop | try:
|
314 | fad50141 | Michael Hanselmann | data = serializer.LoadJson(result) |
315 | c2a03789 | Iustin Pop | except Exception, err: |
316 | c2a03789 | Iustin Pop | raise ProtocolError("Error while deserializing response: %s" % str(err)) |
317 | 3d8548c4 | Michael Hanselmann | |
318 | 3d8548c4 | Michael Hanselmann | # Validate response
|
319 | a14a17fc | Iustin Pop | if (not isinstance(data, dict) or |
320 | 3d8548c4 | Michael Hanselmann | KEY_SUCCESS not in data or |
321 | 3d8548c4 | Michael Hanselmann | KEY_RESULT not in data): |
322 | a14a17fc | Iustin Pop | raise DecodingError("Invalid response from server: %s" % str(data)) |
323 | 3d8548c4 | Michael Hanselmann | |
324 | 6797ec29 | Iustin Pop | result = data[KEY_RESULT] |
325 | 6797ec29 | Iustin Pop | |
326 | 3d8548c4 | Michael Hanselmann | if not data[KEY_SUCCESS]: |
327 | 3d8548c4 | Michael Hanselmann | # TODO: decide on a standard exception
|
328 | 6797ec29 | Iustin Pop | if (isinstance(result, (tuple, list)) and len(result) == 2 and |
329 | 6797ec29 | Iustin Pop | isinstance(result[1], (tuple, list))): |
330 | 6797ec29 | Iustin Pop | # custom ganeti errors
|
331 | 6797ec29 | Iustin Pop | err_class = errors.GetErrorClass(result[0])
|
332 | 6797ec29 | Iustin Pop | if err_class is not None: |
333 | 6797ec29 | Iustin Pop | raise err_class, tuple(result[1]) |
334 | 6797ec29 | Iustin Pop | |
335 | 6797ec29 | Iustin Pop | raise RequestError(result)
|
336 | 3d8548c4 | Michael Hanselmann | |
337 | 6797ec29 | Iustin Pop | return result
|
338 | c2a03789 | Iustin Pop | |
339 | 3ccafd0e | Iustin Pop | def SetQueueDrainFlag(self, drain_flag): |
340 | 3ccafd0e | Iustin Pop | return self.CallMethod(REQ_QUEUE_SET_DRAIN_FLAG, drain_flag) |
341 | 3ccafd0e | Iustin Pop | |
342 | 0bbe448c | Michael Hanselmann | def SubmitJob(self, ops): |
343 | 0bbe448c | Michael Hanselmann | ops_state = map(lambda op: op.__getstate__(), ops) |
344 | 0bbe448c | Michael Hanselmann | return self.CallMethod(REQ_SUBMIT_JOB, ops_state) |
345 | 0bbe448c | Michael Hanselmann | |
346 | 2971c913 | Iustin Pop | def SubmitManyJobs(self, jobs): |
347 | 2971c913 | Iustin Pop | jobs_state = [] |
348 | 2971c913 | Iustin Pop | for ops in jobs: |
349 | 2971c913 | Iustin Pop | jobs_state.append([op.__getstate__() for op in ops]) |
350 | 2971c913 | Iustin Pop | return self.CallMethod(REQ_SUBMIT_MANY_JOBS, jobs_state) |
351 | 2971c913 | Iustin Pop | |
352 | 0bbe448c | Michael Hanselmann | def CancelJob(self, job_id): |
353 | 0bbe448c | Michael Hanselmann | return self.CallMethod(REQ_CANCEL_JOB, job_id) |
354 | 0bbe448c | Michael Hanselmann | |
355 | 0bbe448c | Michael Hanselmann | def ArchiveJob(self, job_id): |
356 | 0bbe448c | Michael Hanselmann | return self.CallMethod(REQ_ARCHIVE_JOB, job_id) |
357 | 0bbe448c | Michael Hanselmann | |
358 | 07cd723a | Iustin Pop | def AutoArchiveJobs(self, age): |
359 | f8ad5591 | Michael Hanselmann | timeout = (DEF_RWTO - 1) / 2 |
360 | f8ad5591 | Michael Hanselmann | return self.CallMethod(REQ_AUTOARCHIVE_JOBS, (age, timeout)) |
361 | 07cd723a | Iustin Pop | |
362 | 6c5a7090 | Michael Hanselmann | def WaitForJobChange(self, job_id, fields, prev_job_info, prev_log_serial): |
363 | 5c735209 | Iustin Pop | timeout = (DEF_RWTO - 1) / 2 |
364 | 5c735209 | Iustin Pop | while True: |
365 | 5c735209 | Iustin Pop | result = self.CallMethod(REQ_WAIT_FOR_JOB_CHANGE,
|
366 | 5c735209 | Iustin Pop | (job_id, fields, prev_job_info, |
367 | 5c735209 | Iustin Pop | prev_log_serial, timeout)) |
368 | 5c735209 | Iustin Pop | if result != constants.JOB_NOTCHANGED:
|
369 | 5c735209 | Iustin Pop | break
|
370 | 5c735209 | Iustin Pop | return result
|
371 | dfe57c22 | Michael Hanselmann | |
372 | 0bbe448c | Michael Hanselmann | def QueryJobs(self, job_ids, fields): |
373 | 0bbe448c | Michael Hanselmann | return self.CallMethod(REQ_QUERY_JOBS, (job_ids, fields)) |
374 | 3d8548c4 | Michael Hanselmann | |
375 | ec79568d | Iustin Pop | def QueryInstances(self, names, fields, use_locking): |
376 | ec79568d | Iustin Pop | return self.CallMethod(REQ_QUERY_INSTANCES, (names, fields, use_locking)) |
377 | ee6c7b94 | Michael Hanselmann | |
378 | ec79568d | Iustin Pop | def QueryNodes(self, names, fields, use_locking): |
379 | ec79568d | Iustin Pop | return self.CallMethod(REQ_QUERY_NODES, (names, fields, use_locking)) |
380 | 02f7fe54 | Michael Hanselmann | |
381 | ec79568d | Iustin Pop | def QueryExports(self, nodes, use_locking): |
382 | ec79568d | Iustin Pop | return self.CallMethod(REQ_QUERY_EXPORTS, (nodes, use_locking)) |
383 | 32f93223 | Michael Hanselmann | |
384 | 66baeccc | Iustin Pop | def QueryClusterInfo(self): |
385 | 66baeccc | Iustin Pop | return self.CallMethod(REQ_QUERY_CLUSTER_INFO, ()) |
386 | 66baeccc | Iustin Pop | |
387 | ae5849b5 | Michael Hanselmann | def QueryConfigValues(self, fields): |
388 | ae5849b5 | Michael Hanselmann | return self.CallMethod(REQ_QUERY_CONFIG_VALUES, fields) |
389 | ae5849b5 | Michael Hanselmann | |
390 | 3ccafd0e | Iustin Pop | |
391 | 3d8548c4 | Michael Hanselmann | # TODO: class Server(object) |