| 1 | #!/usr/bin/env python |
|---|
| 2 | |
|---|
| 3 | import sys |
|---|
| 4 | |
|---|
| 5 | from federation.proof import proof |
|---|
| 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 | log_authentication |
|---|
| 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", |
|---|
| 15 | action='callback', callback=self.expand_file, type='str', |
|---|
| 16 | help="experiment certificate file") |
|---|
| 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", |
|---|
| 21 | choices=("id", "experimentdescription", "vtopo", "vis", |
|---|
| 22 | "log", "status"), |
|---|
| 23 | help="data to extract") |
|---|
| 24 | self.add_option("--fresh", dest="fresh", action="store_true", |
|---|
| 25 | default=False, help="Force controller to gather fresh status") |
|---|
| 26 | |
|---|
| 27 | parser = exp_data_opts() |
|---|
| 28 | (opts, args) = parser.parse_args() |
|---|
| 29 | cert, fid, url = wrangle_standard_options(opts) |
|---|
| 30 | |
|---|
| 31 | if opts.exp_name and opts.exp_certfile: |
|---|
| 32 | sys.exit("Only one of --experiment_cert and --experiment_name permitted") |
|---|
| 33 | elif opts.exp_certfile: |
|---|
| 34 | exp_id = { 'fedid': fedid(file=opts.exp_certfile) } |
|---|
| 35 | elif opts.exp_name: |
|---|
| 36 | exp_id = { 'localname' : opts.exp_name } |
|---|
| 37 | else: |
|---|
| 38 | sys.exit("specify one of --experiment_cert and --experiment_name") |
|---|
| 39 | |
|---|
| 40 | req = { 'experiment': exp_id, 'fresh': opts.fresh } |
|---|
| 41 | |
|---|
| 42 | # If legacy data is requested, request it from the server. |
|---|
| 43 | if 'vis' in opts.data or 'vtopo' in opts.data: |
|---|
| 44 | req['legacy'] = True |
|---|
| 45 | |
|---|
| 46 | try: |
|---|
| 47 | resp_dict = do_rpc(req, |
|---|
| 48 | url, opts.transport, cert, opts.trusted, |
|---|
| 49 | serialize_only=opts.serialize_only, |
|---|
| 50 | tracefile=opts.tracefile, |
|---|
| 51 | caller=service_caller('Info'), responseBody='InfoResponseBody') |
|---|
| 52 | except RPCException, e: |
|---|
| 53 | exit_with_fault(e, 'Info', opts) |
|---|
| 54 | except RuntimeError, e: |
|---|
| 55 | sys.exit("Error processing RPC: %s" % e) |
|---|
| 56 | |
|---|
| 57 | formatter = info_format() |
|---|
| 58 | for d in opts.data: |
|---|
| 59 | try: |
|---|
| 60 | formatter(resp_dict, d) |
|---|
| 61 | except RuntimeError, e: |
|---|
| 62 | print >>sys.stderr, "Warning: %s" % e |
|---|
| 63 | proof = proof.from_dict(resp_dict.get('proof', {})) |
|---|
| 64 | if proof and opts.auth_log: |
|---|
| 65 | log_authentication(opts.auth_log, 'Info', 'succeeded', proof) |
|---|