1 | #!/usr/local/bin/python |
---|
2 | |
---|
3 | import sys |
---|
4 | |
---|
5 | from federation import topdl |
---|
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 | |
---|
10 | class ftopo_opts(client_opts): |
---|
11 | def __init__(self): |
---|
12 | client_opts.__init__(self) |
---|
13 | self.add_option("--experiment_cert", dest="exp_certfile", |
---|
14 | type="string", help="experiment certificate file") |
---|
15 | self.add_option("--experiment_name", dest="exp_name", |
---|
16 | type="string", help="human readable experiment name") |
---|
17 | |
---|
18 | parser = ftopo_opts() |
---|
19 | (opts, args) = parser.parse_args() |
---|
20 | try: |
---|
21 | cert, fid = wrangle_standard_options(opts) |
---|
22 | except RuntimeError, e: |
---|
23 | sys.exit("%s" % e) |
---|
24 | |
---|
25 | if opts.exp_name and opts.exp_certfile: |
---|
26 | sys.exit("Only one of --experiment_cert and --experiment_name permitted") |
---|
27 | elif opts.exp_certfile: |
---|
28 | exp_id = { 'fedid': fedid(file=opts.exp_certfile) } |
---|
29 | elif opts.exp_name: |
---|
30 | exp_id = { 'localname' : opts.exp_name } |
---|
31 | else: |
---|
32 | sys.exit("specify one of --experiment_cert and --experiment_name") |
---|
33 | |
---|
34 | req = { 'experiment': exp_id } |
---|
35 | |
---|
36 | try: |
---|
37 | resp_dict = do_rpc(req, |
---|
38 | opts.url, opts.transport, cert, opts.trusted, |
---|
39 | serialize_only=opts.serialize_only, |
---|
40 | tracefile=opts.tracefile, |
---|
41 | caller=service_caller('Info'), responseBody='InfoResponseBody') |
---|
42 | except RPCException, e: |
---|
43 | exit_with_fault(e) |
---|
44 | except RuntimeError, e: |
---|
45 | sys.exit("Error processing RPC: %s" % e) |
---|
46 | |
---|
47 | if 'experimentdescription' in resp_dict and \ |
---|
48 | 'topdldescription' in resp_dict['experimentdescription']: |
---|
49 | top = \ |
---|
50 | topdl.Topology(\ |
---|
51 | **resp_dict['experimentdescription']['topdldescription']) |
---|
52 | |
---|
53 | for e in [ e for e in top.elements \ |
---|
54 | if isinstance(e, topdl.Computer)]: |
---|
55 | hn = e.get_attribute('hostname') |
---|
56 | tb = e.get_attribute('testbed') |
---|
57 | if hn and tb: |
---|
58 | print ":".join([",".join(e.name), hn, tb]) |
---|
59 | else: |
---|
60 | sys.exit("Badly formatted response!?") |
---|