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 | action='callback', callback=self.expand_file, type='str', |
---|
15 | help="experiment certificate file") |
---|
16 | self.add_option("--experiment_name", dest="exp_name", |
---|
17 | type="string", help="human readable experiment name") |
---|
18 | |
---|
19 | parser = ftopo_opts() |
---|
20 | (opts, args) = parser.parse_args() |
---|
21 | try: |
---|
22 | cert, fid, url = wrangle_standard_options(opts) |
---|
23 | except RuntimeError, e: |
---|
24 | sys.exit("%s" % e) |
---|
25 | |
---|
26 | if opts.exp_name and opts.exp_certfile: |
---|
27 | sys.exit("Only one of --experiment_cert and --experiment_name permitted") |
---|
28 | elif opts.exp_certfile: |
---|
29 | exp_id = { 'fedid': fedid(file=opts.exp_certfile) } |
---|
30 | elif opts.exp_name: |
---|
31 | exp_id = { 'localname' : opts.exp_name } |
---|
32 | else: |
---|
33 | sys.exit("specify one of --experiment_cert and --experiment_name") |
---|
34 | |
---|
35 | req = { 'experiment': exp_id } |
---|
36 | |
---|
37 | try: |
---|
38 | resp_dict = do_rpc(req, |
---|
39 | url, opts.transport, cert, opts.trusted, |
---|
40 | serialize_only=opts.serialize_only, |
---|
41 | tracefile=opts.tracefile, |
---|
42 | caller=service_caller('Info'), responseBody='InfoResponseBody') |
---|
43 | except RPCException, e: |
---|
44 | exit_with_fault(e) |
---|
45 | except RuntimeError, e: |
---|
46 | sys.exit("Error processing RPC: %s" % e) |
---|
47 | |
---|
48 | emap = { } |
---|
49 | if 'embedding' in resp_dict: |
---|
50 | for e in resp_dict['embedding']: |
---|
51 | tn = e.get('toponame', None) |
---|
52 | if tn: |
---|
53 | emap[tn] = ":".join((tn, |
---|
54 | ",".join(e.get('physname', [])),e.get('testbed',""))) |
---|
55 | else: |
---|
56 | sys.exit("No embedding") |
---|
57 | |
---|
58 | if 'experimentdescription' in resp_dict and \ |
---|
59 | 'topdldescription' in resp_dict['experimentdescription']: |
---|
60 | top = topdl.Topology( |
---|
61 | **resp_dict['experimentdescription']['topdldescription']) |
---|
62 | for e in top.elements: |
---|
63 | if isinstance(e, topdl.Computer) and e.name in emap: |
---|
64 | print emap[e.name] |
---|
65 | else: |
---|
66 | sys.exit("Badly formatted response (no experiment descrption)!?") |
---|