source: fedd/fedd_ftopo.py @ 187a8f9

Last change on this file since 187a8f9 was dbc8b8e, checked in by Ted Faber <faber@…>, 12 years ago

Set default status for nodes in ftopo

  • Property mode set to 100755
File size: 2.3 KB
Line 
1#!/usr/bin/env python
2
3import sys
4
5from deter import topdl
6from deter import fedid
7
8from federation.proof import proof
9from federation.remote_service import service_caller
10from 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
14class 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
25parser = ftopo_opts()
26(opts, args) = parser.parse_args()
27try:
28    cert, fid, url = wrangle_standard_options(opts)
29except RuntimeError, e:
30    sys.exit("%s" % e)
31
32if opts.exp_name and opts.exp_certfile:
33    sys.exit("Only one of --experiment_cert and --experiment_name permitted")
34elif opts.exp_certfile:
35    exp_id = { 'fedid': fedid(file=opts.exp_certfile) }
36elif opts.exp_name:
37    exp_id = { 'localname' : opts.exp_name }
38else:
39    sys.exit("specify one of --experiment_cert and --experiment_name")
40
41req = { 'experiment': exp_id, 'fresh': opts.fresh }
42
43try:
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')
49except RPCException, e:
50    exit_with_fault(e, 'Ftopo', opts)
51except RuntimeError, e:
52    sys.exit("Error processing RPC: %s" % e)
53
54if '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 ""))
62else:
63    sys.exit("Badly formatted response (no experiment descrption)!?")
64proof = proof.from_dict(resp_dict.get('proof', {}))
65if proof and opts.auth_log:
66    log_authentication(opts.auth_log, 'Ftopo', 'succeeded', proof)
Note: See TracBrowser for help on using the repository browser.