source: fedd/fedd_ns2topdl.py @ b745876

compt_changes
Last change on this file since b745876 was 6bedbdba, checked in by Ted Faber <faber@…>, 13 years ago

Split topdl and fedid out to different packages. Add differential
installs

  • Property mode set to 100755
File size: 2.2 KB
Line 
1#!/usr/bin/env python
2
3import sys
4
5from deter import topdl
6
7from federation.proof import proof
8from federation.remote_service import service_caller
9from federation.client_lib import client_opts, exit_with_fault, RPCException, \
10        wrangle_standard_options, do_rpc, get_experiment_names, save_certfile
11
12class ns_topdl_opts(client_opts):
13    def __init__(self):
14        client_opts.__init__(self)
15        self.add_option("--file", dest="file", 
16                action='callback', callback=self.expand_file, type='str',
17                help="experiment description file")
18        self.add_option("--output", dest="outfile", type="string",
19                help="output topdl file")
20
21parser = ns_topdl_opts()
22(opts, args) = parser.parse_args()
23
24try:
25    cert, fid, url = wrangle_standard_options(opts)
26except RuntimeError, e:
27    sys.exit("%s" %e)
28
29if opts.file:
30    try:
31        contents = "".join([l for l in open(opts.file, "r")])
32    except EnvironmentError, e:
33        sys.exit("Can't read %s: %s" % (opts.file, e))
34else:
35    sys.exit("Must specify an experiment description (--file)")
36
37msg = { 'description': { 'ns2description': contents }, }
38
39if opts.debug > 1: print >>sys.stderr, msg
40
41try:
42    resp_dict = do_rpc(msg, 
43            url, opts.transport, cert, opts.trusted, 
44            serialize_only=opts.serialize_only,
45            tracefile=opts.tracefile,
46            caller=service_caller('Ns2Topdl'),
47            responseBody="Ns2TopdlResponseBody")
48except RPCException, e:
49    exit_with_fault(e, 'Ns2Topdl', opts)
50except RuntimeError, e:
51    sys.exit("Error processing RPC: %s" % e)
52
53if 'experimentdescription' in resp_dict:
54    if 'topdldescription' in resp_dict['experimentdescription']:
55        exp = resp_dict['experimentdescription']['topdldescription']
56        top = topdl.Topology(**exp)
57    else:
58        sys.exit("Bad response: could not translate")
59elif opts.serialize_only:
60    sys.exit(0)
61else:
62    sys.exit("Bad response. %s" % e.message)
63
64if opts.outfile:
65    try:
66        f = open(opts.outfile, "w")
67        print >>f, topdl.topology_to_xml(top, top="experiment")
68        f.close()
69    except EnvironmentError, e:
70        sys.exit("Can't write to %s: %s" % (opts.outfile, e))
71else:
72    print topdl.topology_to_xml(top, top="experiment")
73proof = proof.from_dict(resp_dict.get('proof', {}))
74if proof and opts.auth_log:
75    log_authentication(opts.auth_log, 'New (create)', 'succeeded', proof)
Note: See TracBrowser for help on using the repository browser.