source: fedd/fedd_info.py @ d070d9f

Last change on this file since d070d9f was 6e33086, checked in by Ted Faber <faber@…>, 13 years ago

InfoSegment? to emulab access controllers

  • Property mode set to 100755
File size: 2.3 KB
RevLine 
[2e46f35]1#!/usr/bin/env python
[d743d60]2
3import sys
4
[e83f2f2]5from federation.proof import proof
[d743d60]6from federation.remote_service import service_caller
7from 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
11class 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")
[6e33086]24        self.add_option("--fresh", dest="fresh", action="store_true",
25                default=False, help="Force controller to gather fresh status")
[d743d60]26       
27parser = exp_data_opts()
28(opts, args) = parser.parse_args()
[5d854e1]29cert, fid, url = wrangle_standard_options(opts)
[d743d60]30
31if opts.exp_name and opts.exp_certfile:
32    sys.exit("Only one of --experiment_cert and --experiment_name permitted")
33elif opts.exp_certfile:
34    exp_id = { 'fedid': fedid(file=opts.exp_certfile) }
35elif opts.exp_name:
36    exp_id = { 'localname' : opts.exp_name }
37else:
38    sys.exit("specify one of --experiment_cert and --experiment_name")
39
[6e33086]40req = { 'experiment': exp_id, 'fresh': opts.fresh }
[d743d60]41
[80b1e82]42# If legacy data is requested, request it from the server.
43if 'vis' in opts.data  or 'vtopo' in opts.data:
44    req['legacy'] = True
45
[d743d60]46try:
47    resp_dict = do_rpc(req,
[5d854e1]48            url, opts.transport, cert, opts.trusted, 
[d743d60]49            serialize_only=opts.serialize_only,
50            tracefile=opts.tracefile,
51            caller=service_caller('Info'), responseBody='InfoResponseBody')
52except RPCException, e:
[e83f2f2]53    exit_with_fault(e, 'Info', opts)
[d743d60]54except RuntimeError, e:
55    sys.exit("Error processing RPC: %s" % e)
56
57formatter = info_format()
58for d in opts.data:
[2fd8f8c]59    try:
60        formatter(resp_dict, d)
61    except RuntimeError, e:
62        print >>sys.stderr, "Warning: %s" % e
[e83f2f2]63proof = proof.from_dict(resp_dict.get('proof', {}))
64if proof and opts.auth_log:
65    log_authentication(opts.auth_log, 'Info', 'succeeded', proof)
Note: See TracBrowser for help on using the repository browser.