[d743d60] | 1 | #!/usr/local/bin/python |
---|
| 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") |
---|
| 20 | |
---|
| 21 | parser = ftopo_opts() |
---|
| 22 | (opts, args) = parser.parse_args() |
---|
| 23 | try: |
---|
[5d854e1] | 24 | cert, fid, url = wrangle_standard_options(opts) |
---|
[d743d60] | 25 | except RuntimeError, e: |
---|
| 26 | sys.exit("%s" % e) |
---|
| 27 | |
---|
| 28 | if opts.exp_name and opts.exp_certfile: |
---|
| 29 | sys.exit("Only one of --experiment_cert and --experiment_name permitted") |
---|
| 30 | elif opts.exp_certfile: |
---|
| 31 | exp_id = { 'fedid': fedid(file=opts.exp_certfile) } |
---|
| 32 | elif opts.exp_name: |
---|
| 33 | exp_id = { 'localname' : opts.exp_name } |
---|
| 34 | else: |
---|
| 35 | sys.exit("specify one of --experiment_cert and --experiment_name") |
---|
| 36 | |
---|
| 37 | req = { 'experiment': exp_id } |
---|
| 38 | |
---|
| 39 | try: |
---|
| 40 | resp_dict = do_rpc(req, |
---|
[5d854e1] | 41 | url, opts.transport, cert, opts.trusted, |
---|
[d743d60] | 42 | serialize_only=opts.serialize_only, |
---|
| 43 | tracefile=opts.tracefile, |
---|
| 44 | caller=service_caller('Info'), responseBody='InfoResponseBody') |
---|
| 45 | except RPCException, e: |
---|
[e83f2f2] | 46 | exit_with_fault(e, 'Ftopo', opts) |
---|
[d743d60] | 47 | except RuntimeError, e: |
---|
| 48 | sys.exit("Error processing RPC: %s" % e) |
---|
| 49 | |
---|
[ce81d09] | 50 | emap = { } |
---|
| 51 | if 'embedding' in resp_dict: |
---|
| 52 | for e in resp_dict['embedding']: |
---|
| 53 | tn = e.get('toponame', None) |
---|
| 54 | if tn: |
---|
| 55 | emap[tn] = ":".join((tn, |
---|
| 56 | ",".join(e.get('physname', [])),e.get('testbed',""))) |
---|
| 57 | else: |
---|
| 58 | sys.exit("No embedding") |
---|
| 59 | |
---|
[d743d60] | 60 | if 'experimentdescription' in resp_dict and \ |
---|
| 61 | 'topdldescription' in resp_dict['experimentdescription']: |
---|
[ce81d09] | 62 | top = topdl.Topology( |
---|
| 63 | **resp_dict['experimentdescription']['topdldescription']) |
---|
| 64 | for e in top.elements: |
---|
| 65 | if isinstance(e, topdl.Computer) and e.name in emap: |
---|
| 66 | print emap[e.name] |
---|
[d743d60] | 67 | else: |
---|
[ce81d09] | 68 | sys.exit("Badly formatted response (no experiment descrption)!?") |
---|
[e83f2f2] | 69 | proof = proof.from_dict(resp_dict.get('proof', {})) |
---|
| 70 | if proof and opts.auth_log: |
---|
| 71 | log_authentication(opts.auth_log, 'Ftopo', 'succeeded', proof) |
---|