| 456 | == Python binding == |
| 457 | |
| 458 | The file tools/submit_api.py contains a Python binding of some of above RPCs. |
| 459 | For examples of its use, se tools/submit_api_test.py. |
| 460 | |
| 461 | To build a description of a batch of jobs, |
| 462 | use the BATCH_DESC, JOB_DESC, and FILE_DESC objects: |
| 463 | {{{ |
| 464 | def make_batch(): |
| 465 | file = FILE_DESC() |
| 466 | file.mode = 'remote' |
| 467 | file.url = 'http://isaac.ssl.berkeley.edu/validate_logic.txt' |
| 468 | file.md5 = "eec5a142cea5202c9ab2e4575a8aaaa7" |
| 469 | file.nbytes = 4250 |
| 470 | |
| 471 | job = JOB_DESC() |
| 472 | job.files = [file] |
| 473 | |
| 474 | batch = BATCH_DESC() |
| 475 | batch.project = 'http://isaac.ssl.berkeley.edu/test/' |
| 476 | batch.authenticator = get_auth() |
| 477 | batch.app_name = "uppercase" |
| 478 | batch.batch_name = "blah" |
| 479 | batch.jobs = [] |
| 480 | |
| 481 | for i in range(3): |
| 482 | job.rsc_fpops_est = i*1e9 |
| 483 | job.command_line = '-i %s' %(i) |
| 484 | batch.jobs.append(copy.copy(job)) |
| 485 | |
| 486 | return batch |
| 487 | }}} |
| 488 | You can then pass this to either estimate_batch() or submit_batch(): |
| 489 | {{{ |
| 490 | batch = make_batch() |
| 491 | r = estimate_batch(batch) |
| 492 | if r.tag == 'error': |
| 493 | print 'error: ', r.find('error_msg').text |
| 494 | return |
| 495 | print 'estimated time: ', r.text, ' seconds' |
| 496 | }}} |
| 497 | |
| 498 | The return value of all the API functions is an !EntityTree representation |
| 499 | of the XML returned by the RPC. |
| 500 | |
| 501 | Other requests use a REQUEST object. |
| 502 | For example, to query the status of batch 271: |
| 503 | {{{ |
| 504 | req = REQUEST() |
| 505 | req.project = 'http://isaac.ssl.berkeley.edu/test/' |
| 506 | req.authenticator = get_auth() |
| 507 | req.batch_id = 271 |
| 508 | req.get_cpu_time = True |
| 509 | r = query_batch(req) |
| 510 | if r[0].tag == 'error': |
| 511 | print 'error: ', r[0].find('error_msg').text |
| 512 | return |
| 513 | print 'njobs: ', r.find('njobs').text |
| 514 | print 'fraction done: ', r.find('fraction_done').text |
| 515 | print 'total CPU time: ', r.find('total_cpu_time').text |
| 516 | # ... various other fields |
| 517 | print 'jobs:' |
| 518 | for job in r.findall('job'): |
| 519 | print ' id: ', job.find('id').text |
| 520 | print ' n_outfiles: ', job.find('n_outfiles').text |
| 521 | # ... various other fields |
| 522 | |
| 523 | }}} |
| 524 | |