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