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