source: fedd/fedd_ns2topdl.py @ d064566

compt_changes
Last change on this file since d064566 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
RevLine 
[2e46f35]1#!/usr/bin/env python
[d743d60]2
3import sys
4
[6bedbdba]5from deter import topdl
6
[e83f2f2]7from federation.proof import proof
[d743d60]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", 
[62f3dd9]16                action='callback', callback=self.expand_file, type='str',
[d743d60]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
[a0c2866]24try:
25    cert, fid, url = wrangle_standard_options(opts)
26except RuntimeError, e:
27    sys.exit("%s" %e)
[d743d60]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, 
[5d854e1]43            url, opts.transport, cert, opts.trusted, 
[d743d60]44            serialize_only=opts.serialize_only,
45            tracefile=opts.tracefile,
46            caller=service_caller('Ns2Topdl'),
47            responseBody="Ns2TopdlResponseBody")
48except RPCException, e:
[e83f2f2]49    exit_with_fault(e, 'Ns2Topdl', opts)
[d743d60]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")
[e83f2f2]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.