[2e46f35] | 1 | #!/usr/bin/env python |
---|
[d743d60] | 2 | |
---|
| 3 | import sys |
---|
| 4 | |
---|
| 5 | from federation import topdl |
---|
[e83f2f2] | 6 | from federation.proof import proof |
---|
[d743d60] | 7 | from federation.remote_service import service_caller |
---|
| 8 | from federation.client_lib import client_opts, exit_with_fault, RPCException,\ |
---|
[e83f2f2] | 9 | wrangle_standard_options, do_rpc, get_experiment_names, info_format, \ |
---|
| 10 | log_authentication |
---|
[d743d60] | 11 | |
---|
| 12 | class ftopo_opts(client_opts): |
---|
| 13 | def __init__(self): |
---|
| 14 | client_opts.__init__(self) |
---|
| 15 | self.add_option("--experiment_cert", dest="exp_certfile", |
---|
[62f3dd9] | 16 | action='callback', callback=self.expand_file, type='str', |
---|
| 17 | help="experiment certificate file") |
---|
[d743d60] | 18 | self.add_option("--experiment_name", dest="exp_name", |
---|
| 19 | type="string", help="human readable experiment name") |
---|
[6e33086] | 20 | self.add_option("--fresh", dest="fresh", action="store_true", |
---|
| 21 | default=False, help="Force controller to gather fresh status") |
---|
[d743d60] | 22 | |
---|
| 23 | parser = ftopo_opts() |
---|
| 24 | (opts, args) = parser.parse_args() |
---|
| 25 | try: |
---|
[5d854e1] | 26 | cert, fid, url = wrangle_standard_options(opts) |
---|
[d743d60] | 27 | except RuntimeError, e: |
---|
| 28 | sys.exit("%s" % e) |
---|
| 29 | |
---|
| 30 | if opts.exp_name and opts.exp_certfile: |
---|
| 31 | sys.exit("Only one of --experiment_cert and --experiment_name permitted") |
---|
| 32 | elif opts.exp_certfile: |
---|
| 33 | exp_id = { 'fedid': fedid(file=opts.exp_certfile) } |
---|
| 34 | elif opts.exp_name: |
---|
| 35 | exp_id = { 'localname' : opts.exp_name } |
---|
| 36 | else: |
---|
| 37 | sys.exit("specify one of --experiment_cert and --experiment_name") |
---|
| 38 | |
---|
[6e33086] | 39 | req = { 'experiment': exp_id, 'fresh': opts.fresh } |
---|
[d743d60] | 40 | |
---|
| 41 | try: |
---|
| 42 | resp_dict = do_rpc(req, |
---|
[5d854e1] | 43 | url, opts.transport, cert, opts.trusted, |
---|
[d743d60] | 44 | serialize_only=opts.serialize_only, |
---|
| 45 | tracefile=opts.tracefile, |
---|
| 46 | caller=service_caller('Info'), responseBody='InfoResponseBody') |
---|
| 47 | except RPCException, e: |
---|
[e83f2f2] | 48 | exit_with_fault(e, 'Ftopo', opts) |
---|
[d743d60] | 49 | except RuntimeError, e: |
---|
| 50 | sys.exit("Error processing RPC: %s" % e) |
---|
| 51 | |
---|
| 52 | if 'experimentdescription' in resp_dict and \ |
---|
| 53 | 'topdldescription' in resp_dict['experimentdescription']: |
---|
[ce81d09] | 54 | top = topdl.Topology( |
---|
| 55 | **resp_dict['experimentdescription']['topdldescription']) |
---|
| 56 | for e in top.elements: |
---|
[29d5f7c] | 57 | if isinstance(e, topdl.Computer): |
---|
| 58 | print ":".join((e.name, ",".join(e.localname), e.status, |
---|
| 59 | ",".join(e.operation), e.get_attribute('testbed') or "")) |
---|
[d743d60] | 60 | else: |
---|
[ce81d09] | 61 | sys.exit("Badly formatted response (no experiment descrption)!?") |
---|
[e83f2f2] | 62 | proof = proof.from_dict(resp_dict.get('proof', {})) |
---|
| 63 | if proof and opts.auth_log: |
---|
| 64 | log_authentication(opts.auth_log, 'Ftopo', 'succeeded', proof) |
---|