#!/usr/bin/env python import sys from federation.proof import proof from federation.remote_service import service_caller from federation.client_lib import client_opts, exit_with_fault, RPCException,\ wrangle_standard_options, do_rpc, get_experiment_names, info_format, \ log_authentication class exp_data_opts(client_opts): def __init__(self): client_opts.__init__(self) self.add_option("--experiment_cert", dest="exp_certfile", action='callback', callback=self.expand_file, type='str', help="experiment certificate file") self.add_option("--experiment_name", dest="exp_name", type="string", help="human readable experiment name") self.add_option("--data", dest="data", default=[], action="append", type="choice", choices=("id", "experimentdescription", "vtopo", "vis", "log", "status"), help="data to extract") self.add_option("--fresh", dest="fresh", action="store_true", default=False, help="Force controller to gather fresh status") parser = exp_data_opts() (opts, args) = parser.parse_args() cert, fid, url = wrangle_standard_options(opts) if opts.exp_name and opts.exp_certfile: sys.exit("Only one of --experiment_cert and --experiment_name permitted") elif opts.exp_certfile: exp_id = { 'fedid': fedid(file=opts.exp_certfile) } elif opts.exp_name: exp_id = { 'localname' : opts.exp_name } else: sys.exit("specify one of --experiment_cert and --experiment_name") req = { 'experiment': exp_id, 'fresh': opts.fresh } # If legacy data is requested, request it from the server. if 'vis' in opts.data or 'vtopo' in opts.data: req['legacy'] = True try: resp_dict = do_rpc(req, url, opts.transport, cert, opts.trusted, serialize_only=opts.serialize_only, tracefile=opts.tracefile, caller=service_caller('Info'), responseBody='InfoResponseBody') except RPCException, e: exit_with_fault(e, 'Info', opts) except RuntimeError, e: sys.exit("Error processing RPC: %s" % e) formatter = info_format() for d in opts.data: try: formatter(resp_dict, d) except RuntimeError, e: print >>sys.stderr, "Warning: %s" % e proof = proof.from_dict(resp_dict.get('proof', {})) if proof and opts.auth_log: log_authentication(opts.auth_log, 'Info', 'succeeded', proof)