source: fedd/fedd_ftopo.py @ 6bff6d9

version-3.01version-3.02
Last change on this file since 6bff6d9 was ce81d09, checked in by Ted Faber <faber@…>, 15 years ago

topo using the embedding field.

  • Property mode set to 100755
File size: 2.1 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
47emap = { }
48if 'embedding' in resp_dict:
49    for e in resp_dict['embedding']:
50        tn = e.get('toponame', None)
51        if tn: 
52            emap[tn] = ":".join((tn, 
53                ",".join(e.get('physname', [])),e.get('testbed',"")))
54else:
55    sys.exit("No embedding")
56
57if 'experimentdescription' in resp_dict and \
58        'topdldescription' in resp_dict['experimentdescription']:
59    top = topdl.Topology(
60            **resp_dict['experimentdescription']['topdldescription'])
61    for e in top.elements:
62        if isinstance(e, topdl.Computer) and e.name in emap:
63            print emap[e.name]
64else:
65    sys.exit("Badly formatted response (no experiment descrption)!?")
Note: See TracBrowser for help on using the repository browser.