source: fedd/fedd_ftopo.py @ a96d946

axis_examplecompt_changesinfo-ops
Last change on this file since a96d946 was 62f3dd9, checked in by Ted Faber <faber@…>, 14 years ago

allow command line progams to expand tildes. Added a class derived from OptionParser? to make that easily available.

  • Property mode set to 100755
File size: 2.1 KB
RevLine 
[d743d60]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",
[62f3dd9]14                action='callback', callback=self.expand_file, type='str',
15                help="experiment certificate file")
[d743d60]16        self.add_option("--experiment_name", dest="exp_name",
17                type="string", help="human readable experiment name")
18
19parser = ftopo_opts()
20(opts, args) = parser.parse_args()
21try:
[5d854e1]22    cert, fid, url = wrangle_standard_options(opts)
[d743d60]23except RuntimeError, e:
24    sys.exit("%s" % e)
25
26if opts.exp_name and opts.exp_certfile:
27    sys.exit("Only one of --experiment_cert and --experiment_name permitted")
28elif opts.exp_certfile:
29    exp_id = { 'fedid': fedid(file=opts.exp_certfile) }
30elif opts.exp_name:
31    exp_id = { 'localname' : opts.exp_name }
32else:
33    sys.exit("specify one of --experiment_cert and --experiment_name")
34
35req = { 'experiment': exp_id }
36
37try:
38    resp_dict = do_rpc(req,
[5d854e1]39            url, opts.transport, cert, opts.trusted, 
[d743d60]40            serialize_only=opts.serialize_only,
41            tracefile=opts.tracefile,
42            caller=service_caller('Info'), responseBody='InfoResponseBody')
43except RPCException, e:
44    exit_with_fault(e)
45except RuntimeError, e:
46    sys.exit("Error processing RPC: %s" % e)
47
[ce81d09]48emap = { }
49if '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',"")))
55else:
56    sys.exit("No embedding")
57
[d743d60]58if 'experimentdescription' in resp_dict and \
59        'topdldescription' in resp_dict['experimentdescription']:
[ce81d09]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]
[d743d60]65else:
[ce81d09]66    sys.exit("Badly formatted response (no experiment descrption)!?")
Note: See TracBrowser for help on using the repository browser.