1 | #!/usr/local/bin/python |
---|
2 | |
---|
3 | import sys |
---|
4 | |
---|
5 | from federation.remote_service import service_caller |
---|
6 | from federation.client_lib import client_opts, exit_with_fault, RPCException, \ |
---|
7 | wrangle_standard_options, do_rpc, get_experiment_names, save_certfile |
---|
8 | |
---|
9 | |
---|
10 | class new_opts(client_opts): |
---|
11 | def __init__(self): |
---|
12 | client_opts.__init__(self) |
---|
13 | self.add_option("--experiment_cert", dest="out_certfile", |
---|
14 | type="string", help="output certificate file") |
---|
15 | self.add_option("--experiment_name", dest="exp_name", |
---|
16 | type="string", help="Suggested experiment name") |
---|
17 | |
---|
18 | parser = new_opts() |
---|
19 | (opts, args) = parser.parse_args() |
---|
20 | |
---|
21 | cert, fid = wrangle_standard_options(opts) |
---|
22 | |
---|
23 | out_certfile = opts.out_certfile |
---|
24 | |
---|
25 | msg = { } |
---|
26 | |
---|
27 | if opts.exp_name: |
---|
28 | msg['experimentID'] = { 'localname': opts.exp_name } |
---|
29 | |
---|
30 | if opts.debug > 1: print >>sys.stderr, msg |
---|
31 | |
---|
32 | try: |
---|
33 | resp_dict = do_rpc(msg, |
---|
34 | opts.url, opts.transport, cert, opts.trusted, |
---|
35 | serialize_only=opts.serialize_only, |
---|
36 | tracefile=opts.tracefile, |
---|
37 | caller=service_caller("New"), responseBody='NewResponseBody') |
---|
38 | except RPCException, e: |
---|
39 | exit_with_fault(e) |
---|
40 | except RuntimeError, e: |
---|
41 | sys.exit("Error processing RPC: %s" % e) |
---|
42 | |
---|
43 | if opts.debug > 1: print >>sys.stderr, resp_dict |
---|
44 | |
---|
45 | try: |
---|
46 | save_certfile(opts.out_certfile, resp_dict.get('experimentAccess', None)) |
---|
47 | except EnvironmentError: |
---|
48 | sys.exit('Could not write to %s' % out_certfile) |
---|
49 | |
---|
50 | e_fedid, e_local = get_experiment_names(resp_dict.get('experimentID', None)) |
---|
51 | st = resp_dict.get('experimentStatus', None) |
---|
52 | |
---|
53 | if e_local: print "localname: %s" % e_local |
---|
54 | if e_fedid: print "fedid: %s" % e_fedid |
---|
55 | if st: print "status: %s" % st |
---|