Changeset 65f3f29 for fedd/fedd_client.py
- Timestamp:
- Jul 25, 2009 10:52:45 AM (15 years ago)
- Branches:
- axis_example, compt_changes, info-ops, master, version-1.30, version-2.00, version-3.01, version-3.02
- Children:
- ca489e8
- Parents:
- d27fd76
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fedd/fedd_client.py
rd27fd76 r65f3f29 157 157 help="data to extract") 158 158 159 class fedd_multi_exp_data_opts(fedd_client_opts): 160 def __init__(self): 161 fedd_client_opts.__init__(self) 162 self.add_option("--data", dest="data", default=[], 163 action="append", type="choice", 164 choices=("id", "federant", "vtopo", "vis", "log", "status"), 165 help="data to extract") 166 159 167 class fedd_spew_opts(fedd_client_opts): 160 168 def __init__(self): … … 353 361 raise RuntimeError("No body in response??") 354 362 355 # Querying experiment data follows the same control flow regardless of the 356 # specific data retrieved. This class encapsulates that control flow. 357 class exp_data(fedd_rpc): 358 def __init__(self): 363 class exp_data_base(fedd_rpc): 364 def __init__(self, op='Info'): 359 365 """ 360 366 Init the various conversions 361 367 """ 362 368 363 fedd_rpc.__init__(self, 'Info')369 fedd_rpc.__init__(self, op) 364 370 # List of things one could ask for and what formatting routine is 365 371 # called. … … 374 380 } 375 381 376 382 # Utility functions 377 383 def print_string(self, d, out=sys.stdout): 378 384 print >>out, d … … 403 409 print >>out, str 404 410 411 412 413 # Querying experiment data follows the same control flow regardless of the 414 # specific data retrieved. This class encapsulates that control flow. 415 class exp_data(exp_data_base): 416 def __init__(self): 417 exp_data_base.__init__(self, 'Info') 418 405 419 def __call__(self): 406 420 """ … … 495 509 sys.argv.append('--data=status') 496 510 exp_data.__call__(self) 511 512 class multi_exp_data(exp_data_base): 513 def __init__(self): 514 exp_data_base.__init__(self, 'MultiInfo') 515 516 517 def __call__(self): 518 """ 519 The control flow. Compose the request and print the response. 520 """ 521 # Process the options using the customized option parser defined above 522 parser = fedd_multi_exp_data_opts() 523 524 (opts, args) = parser.parse_args() 525 526 if opts.trusted: 527 if ( not os.access(opts.trusted, os.R_OK) ) : 528 sys.exit("Cannot read trusted certificates (%s)" % opts.trusted) 529 530 if opts.debug > 0: opts.tracefile=sys.stderr 531 532 (user, cert) = self.get_user_info([]) 533 534 if opts.cert != None: cert = opts.cert 535 536 if cert == None: 537 sys.exit("No certificate given (--cert) or found") 538 539 if os.access(cert, os.R_OK): 540 fid = fedid(file=cert) 541 else: 542 sys.exit("Cannot read certificate (%s)" % cert) 543 544 req = { } 545 546 try: 547 resp_dict = self.do_rpc(req, 548 opts.url, opts.transport, cert, opts.trusted, 549 serialize_only=opts.serialize_only, 550 tracefile=opts.tracefile) 551 except self.RPCException, e: 552 exit_with_fault(\ 553 {'desc': e.desc, 'errstr': e.errstr, 'code': e.code}) 554 except RuntimeError, e: 555 print e 556 sys.exit("Error processing RPC: %s" % e) 557 558 exps = resp_dict.get('info', []) 559 if exps: 560 print '---' 561 for exp in exps: 562 for d in opts.data: 563 key, output = self.params[d] 564 try: 565 if exp.has_key(key): 566 output(exp[key]) 567 except RuntimeError, e: 568 sys.exit("Bad response. %s" % e.message) 569 print '---' 570 571 572 class multi_status(exp_data_base): 573 def __init__(self): 574 exp_data_base.__init__(self, 'MultiInfo') 575 576 577 def __call__(self): 578 """ 579 The control flow. Compose the request and print the response. 580 """ 581 # Process the options using the customized option parser defined above 582 parser = fedd_client_opts() 583 584 (opts, args) = parser.parse_args() 585 586 if opts.trusted: 587 if ( not os.access(opts.trusted, os.R_OK) ) : 588 sys.exit("Cannot read trusted certificates (%s)" % opts.trusted) 589 590 if opts.debug > 0: opts.tracefile=sys.stderr 591 592 (user, cert) = self.get_user_info([]) 593 594 if opts.cert != None: cert = opts.cert 595 596 if cert == None: 597 sys.exit("No certificate given (--cert) or found") 598 599 if os.access(cert, os.R_OK): 600 fid = fedid(file=cert) 601 else: 602 sys.exit("Cannot read certificate (%s)" % cert) 603 604 req = { } 605 606 try: 607 resp_dict = self.do_rpc(req, 608 opts.url, opts.transport, cert, opts.trusted, 609 serialize_only=opts.serialize_only, 610 tracefile=opts.tracefile) 611 except self.RPCException, e: 612 exit_with_fault(\ 613 {'desc': e.desc, 'errstr': e.errstr, 'code': e.code}) 614 except RuntimeError, e: 615 print e 616 sys.exit("Error processing RPC: %s" % e) 617 618 for exp in resp_dict.get('info', []): 619 out = [] 620 for eid in exp.get('experimentID', []): 621 if eid.has_key('localname'): 622 out.append(eid['localname']) 623 break 624 else: 625 out.append("") 626 for eid in exp.get('experimentID', []): 627 if eid.has_key('fedid'): 628 out.append("%s" % eid['fedid']) 629 break 630 else: 631 out.append("") 632 633 out.append(exp.get('experimentStatus', "")) 634 635 for f in exp.get('federant', []): 636 if f.get('master', False): 637 em = f.get('emulab', None) 638 if em: 639 project = em.get('project', None) 640 if project: 641 tb = project.get('testbed', None) 642 if tb and tb.has_key('localname'): 643 out.append(tb['localname']) 644 else: 645 out.append("") 646 pn = project.get('name', None) 647 if pn and pn.has_key('localname'): 648 out.append(pn['localname']) 649 else: 650 out.append("") 651 else: 652 out.extend(("", "")) 653 else: 654 out.extend(("", "")) 655 break 656 else: 657 out.extend(("","")) 658 659 print ":".join(out) 497 660 498 661 class image(fedd_rpc): … … 1302 1465 'vis': vis(),\ 1303 1466 'info': exp_data(),\ 1467 'multiinfo': multi_exp_data(),\ 1468 'multistatus': multi_status(),\ 1304 1469 'image': image(),\ 1305 1470 'ns_image': ns_image(),\
Note: See TracChangeset
for help on using the changeset viewer.