source: fedd/fedd_ftopo.py @ 479a7d9

axis_examplecompt_changesinfo-opsversion-3.01version-3.02
Last change on this file since 479a7d9 was d743d60, checked in by Ted Faber <faber@…>, 15 years ago

Totally refactor fedd_client.py into component scripts. The previous layout
have become a twisty hell of misdirected OOP and learning python run amok.
This version is actually pretty readable and will be much easier to build on.

  • Property mode set to 100755
File size: 1.9 KB
Line 
1#!/usr/local/bin/python
2
3import sys
4
5from federation import topdl
6from federation.remote_service import service_caller
7from federation.client_lib import client_opts, exit_with_fault, RPCException,\
8        wrangle_standard_options, do_rpc, get_experiment_names, info_format
9
10class 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
18parser = ftopo_opts()
19(opts, args) = parser.parse_args()
20try:
21    cert, fid = wrangle_standard_options(opts)
22except RuntimeError, e:
23    sys.exit("%s" % e)
24
25if opts.exp_name and opts.exp_certfile:
26    sys.exit("Only one of --experiment_cert and --experiment_name permitted")
27elif opts.exp_certfile:
28    exp_id = { 'fedid': fedid(file=opts.exp_certfile) }
29elif opts.exp_name:
30    exp_id = { 'localname' : opts.exp_name }
31else:
32    sys.exit("specify one of --experiment_cert and --experiment_name")
33
34req = { 'experiment': exp_id }
35
36try:
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')
42except RPCException, e:
43    exit_with_fault(e)
44except RuntimeError, e:
45    sys.exit("Error processing RPC: %s" % e)
46
47if '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])
59else:
60    sys.exit("Badly formatted response!?")
Note: See TracBrowser for help on using the repository browser.