source: fedd/fedd_ftopo.py @ 29d5f7c

compt_changesinfo-ops
Last change on this file since 29d5f7c was 29d5f7c, checked in by Ted Faber <faber@…>, 12 years ago

More new Info stuff. Create, terminate, ftopo all work.

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