[2e46f35] | 1 | #!/usr/bin/env python |
---|
[d743d60] | 2 | |
---|
| 3 | import sys |
---|
| 4 | |
---|
[e83f2f2] | 5 | from federation.proof import proof |
---|
[d743d60] | 6 | from federation.remote_service import service_caller |
---|
| 7 | from federation.client_lib import client_opts, exit_with_fault, RPCException,\ |
---|
[e83f2f2] | 8 | wrangle_standard_options, do_rpc, get_experiment_names, info_format, \ |
---|
| 9 | log_authentication |
---|
[d743d60] | 10 | |
---|
| 11 | class exp_data_opts(client_opts): |
---|
| 12 | def __init__(self): |
---|
| 13 | client_opts.__init__(self) |
---|
| 14 | self.add_option("--experiment_cert", dest="exp_certfile", |
---|
[62f3dd9] | 15 | action='callback', callback=self.expand_file, type='str', |
---|
| 16 | help="experiment certificate file") |
---|
[d743d60] | 17 | self.add_option("--experiment_name", dest="exp_name", |
---|
| 18 | type="string", help="human readable experiment name") |
---|
| 19 | self.add_option("--data", dest="data", default=[], |
---|
| 20 | action="append", type="choice", |
---|
[80b1e82] | 21 | choices=("id", "experimentdescription", "vtopo", "vis", |
---|
| 22 | "log", "status"), |
---|
[d743d60] | 23 | help="data to extract") |
---|
| 24 | |
---|
| 25 | parser = exp_data_opts() |
---|
| 26 | (opts, args) = parser.parse_args() |
---|
[5d854e1] | 27 | cert, fid, url = wrangle_standard_options(opts) |
---|
[d743d60] | 28 | |
---|
| 29 | if opts.exp_name and opts.exp_certfile: |
---|
| 30 | sys.exit("Only one of --experiment_cert and --experiment_name permitted") |
---|
| 31 | elif opts.exp_certfile: |
---|
| 32 | exp_id = { 'fedid': fedid(file=opts.exp_certfile) } |
---|
| 33 | elif opts.exp_name: |
---|
| 34 | exp_id = { 'localname' : opts.exp_name } |
---|
| 35 | else: |
---|
| 36 | sys.exit("specify one of --experiment_cert and --experiment_name") |
---|
| 37 | |
---|
| 38 | req = { 'experiment': exp_id } |
---|
| 39 | |
---|
[80b1e82] | 40 | # If legacy data is requested, request it from the server. |
---|
| 41 | if 'vis' in opts.data or 'vtopo' in opts.data: |
---|
| 42 | req['legacy'] = True |
---|
| 43 | |
---|
[d743d60] | 44 | try: |
---|
| 45 | resp_dict = do_rpc(req, |
---|
[5d854e1] | 46 | url, opts.transport, cert, opts.trusted, |
---|
[d743d60] | 47 | serialize_only=opts.serialize_only, |
---|
| 48 | tracefile=opts.tracefile, |
---|
| 49 | caller=service_caller('Info'), responseBody='InfoResponseBody') |
---|
| 50 | except RPCException, e: |
---|
[e83f2f2] | 51 | exit_with_fault(e, 'Info', opts) |
---|
[d743d60] | 52 | except RuntimeError, e: |
---|
| 53 | sys.exit("Error processing RPC: %s" % e) |
---|
| 54 | |
---|
| 55 | formatter = info_format() |
---|
| 56 | for d in opts.data: |
---|
[2fd8f8c] | 57 | try: |
---|
| 58 | formatter(resp_dict, d) |
---|
| 59 | except RuntimeError, e: |
---|
| 60 | print >>sys.stderr, "Warning: %s" % e |
---|
[e83f2f2] | 61 | proof = proof.from_dict(resp_dict.get('proof', {})) |
---|
| 62 | if proof and opts.auth_log: |
---|
| 63 | log_authentication(opts.auth_log, 'Info', 'succeeded', proof) |
---|