source: fedd/fedd_ftopo.py @ 6e33086

compt_changesinfo-ops
Last change on this file since 6e33086 was 6e33086, checked in by Ted Faber <faber@…>, 12 years ago

InfoSegment? to emulab access controllers

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