Revision be1ddd09 lib/rapi/baserlib.py
b/lib/rapi/baserlib.py | ||
---|---|---|
182 | 182 |
return op |
183 | 183 |
|
184 | 184 |
|
185 |
def SubmitJob(op, cl=None): |
|
186 |
"""Generic wrapper for submit job, for better http compatibility. |
|
187 |
|
|
188 |
@type op: list |
|
189 |
@param op: the list of opcodes for the job |
|
190 |
@type cl: None or luxi.Client |
|
191 |
@param cl: optional luxi client to use |
|
192 |
@rtype: string |
|
193 |
@return: the job ID |
|
194 |
|
|
195 |
""" |
|
196 |
try: |
|
197 |
if cl is None: |
|
198 |
cl = GetClient() |
|
199 |
return cl.SubmitJob(op) |
|
200 |
except errors.JobQueueFull: |
|
201 |
raise http.HttpServiceUnavailable("Job queue is full, needs archiving") |
|
202 |
except errors.JobQueueDrainError: |
|
203 |
raise http.HttpServiceUnavailable("Job queue is drained, cannot submit") |
|
204 |
except luxi.NoMasterError, err: |
|
205 |
raise http.HttpBadGateway("Master seems to be unreachable: %s" % str(err)) |
|
206 |
except luxi.PermissionError: |
|
207 |
raise http.HttpInternalServerError("Internal error: no permission to" |
|
208 |
" connect to the master daemon") |
|
209 |
except luxi.TimeoutError, err: |
|
210 |
raise http.HttpGatewayTimeout("Timeout while talking to the master" |
|
211 |
" daemon. Error: %s" % str(err)) |
|
212 |
|
|
213 |
|
|
214 | 185 |
def HandleItemQueryErrors(fn, *args, **kwargs): |
215 | 186 |
"""Converts errors when querying a single item. |
216 | 187 |
|
... | ... | |
224 | 195 |
raise |
225 | 196 |
|
226 | 197 |
|
227 |
def GetClient(): |
|
228 |
"""Geric wrapper for luxi.Client(), for better http compatiblity. |
|
229 |
|
|
230 |
""" |
|
231 |
try: |
|
232 |
return luxi.Client() |
|
233 |
except luxi.NoMasterError, err: |
|
234 |
raise http.HttpBadGateway("Master seems to unreachable: %s" % str(err)) |
|
235 |
except luxi.PermissionError: |
|
236 |
raise http.HttpInternalServerError("Internal error: no permission to" |
|
237 |
" connect to the master daemon") |
|
238 |
|
|
239 |
|
|
240 | 198 |
def FeedbackFn(msg): |
241 | 199 |
"""Feedback logging function for jobs. |
242 | 200 |
|
... | ... | |
392 | 350 |
|
393 | 351 |
""" |
394 | 352 |
return bool(self._checkIntVariable("dry-run")) |
353 |
|
|
354 |
def GetClient(self): |
|
355 |
"""Wrapper for L{luxi.Client} with HTTP-specific error handling. |
|
356 |
|
|
357 |
""" |
|
358 |
# Could be a function, pylint: disable=R0201 |
|
359 |
try: |
|
360 |
return luxi.Client() |
|
361 |
except luxi.NoMasterError, err: |
|
362 |
raise http.HttpBadGateway("Can't connect to master daemon: %s" % err) |
|
363 |
except luxi.PermissionError: |
|
364 |
raise http.HttpInternalServerError("Internal error: no permission to" |
|
365 |
" connect to the master daemon") |
|
366 |
|
|
367 |
def SubmitJob(self, op, cl=None): |
|
368 |
"""Generic wrapper for submit job, for better http compatibility. |
|
369 |
|
|
370 |
@type op: list |
|
371 |
@param op: the list of opcodes for the job |
|
372 |
@type cl: None or luxi.Client |
|
373 |
@param cl: optional luxi client to use |
|
374 |
@rtype: string |
|
375 |
@return: the job ID |
|
376 |
|
|
377 |
""" |
|
378 |
if cl is None: |
|
379 |
cl = self.GetClient() |
|
380 |
try: |
|
381 |
return cl.SubmitJob(op) |
|
382 |
except errors.JobQueueFull: |
|
383 |
raise http.HttpServiceUnavailable("Job queue is full, needs archiving") |
|
384 |
except errors.JobQueueDrainError: |
|
385 |
raise http.HttpServiceUnavailable("Job queue is drained, cannot submit") |
|
386 |
except luxi.NoMasterError, err: |
|
387 |
raise http.HttpBadGateway("Master seems to be unreachable: %s" % err) |
|
388 |
except luxi.PermissionError: |
|
389 |
raise http.HttpInternalServerError("Internal error: no permission to" |
|
390 |
" connect to the master daemon") |
|
391 |
except luxi.TimeoutError, err: |
|
392 |
raise http.HttpGatewayTimeout("Timeout while talking to the master" |
|
393 |
" daemon: %s" % err) |
Also available in: Unified diff