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