1 | #!/usr/local/bin/python |
---|
2 | |
---|
3 | import sys |
---|
4 | |
---|
5 | from federation.fedid import fedid, generate_fedid |
---|
6 | from federation.remote_service import service_caller |
---|
7 | from federation.client_lib import client_opts, exit_with_fault, RPCException, \ |
---|
8 | wrangle_standard_options, do_rpc, get_experiment_names, \ |
---|
9 | save_certfile, get_abac_certs |
---|
10 | |
---|
11 | |
---|
12 | class new_opts(client_opts): |
---|
13 | def __init__(self): |
---|
14 | client_opts.__init__(self) |
---|
15 | self.add_option("--experiment_cert", dest="out_certfile", |
---|
16 | type="string", help="output certificate file") |
---|
17 | self.add_option("--experiment_name", dest="exp_name", |
---|
18 | type="string", help="Suggested experiment name") |
---|
19 | self.add_option('--gen_cert', action='store_true', dest='gen_cert', |
---|
20 | default=False, |
---|
21 | help='generate a cert to which to delegate rights') |
---|
22 | |
---|
23 | parser = new_opts() |
---|
24 | (opts, args) = parser.parse_args() |
---|
25 | |
---|
26 | cert, fid, url = wrangle_standard_options(opts) |
---|
27 | try: |
---|
28 | acerts = get_abac_certs(opts.abac_dir) |
---|
29 | except EnvironmentError, e: |
---|
30 | sys.exit('%s: %s' % (e.filename, e.strerror)) |
---|
31 | |
---|
32 | out_certfile = opts.out_certfile |
---|
33 | |
---|
34 | msg = { } |
---|
35 | |
---|
36 | if opts.gen_cert: |
---|
37 | expid, expcert = generate_fedid(opts.exp_name or 'dummy') |
---|
38 | msg['experimentAccess'] = { 'X509': expcert } |
---|
39 | else: |
---|
40 | expcert = None |
---|
41 | |
---|
42 | if opts.exp_name: |
---|
43 | msg['experimentID'] = { 'localname': opts.exp_name } |
---|
44 | |
---|
45 | if acerts: |
---|
46 | msg['credential'] = acerts |
---|
47 | |
---|
48 | if opts.debug > 1: print >>sys.stderr, msg |
---|
49 | |
---|
50 | try: |
---|
51 | resp_dict = do_rpc(msg, |
---|
52 | url, opts.transport, cert, opts.trusted, |
---|
53 | serialize_only=opts.serialize_only, |
---|
54 | tracefile=opts.tracefile, |
---|
55 | caller=service_caller("New"), responseBody='NewResponseBody') |
---|
56 | except RPCException, e: |
---|
57 | exit_with_fault(e) |
---|
58 | except RuntimeError, e: |
---|
59 | sys.exit("Error processing RPC: %s" % e) |
---|
60 | |
---|
61 | if opts.debug > 1: print >>sys.stderr, resp_dict |
---|
62 | |
---|
63 | try: |
---|
64 | save_certfile(opts.out_certfile, resp_dict.get('experimentAccess', None), |
---|
65 | expcert) |
---|
66 | except EnvironmentError, e: |
---|
67 | sys.exit('Could not write to %s:' % (e.strerror, e.filename)) |
---|
68 | except CertificateMismatchError: |
---|
69 | printf >>sys.stderr, "Fedid of created experiment does not match generated" |
---|
70 | |
---|
71 | |
---|
72 | e_fedid, e_local = get_experiment_names(resp_dict.get('experimentID', None)) |
---|
73 | st = resp_dict.get('experimentStatus', None) |
---|
74 | |
---|
75 | if e_local: print "localname: %s" % e_local |
---|
76 | if e_fedid: print "fedid: %s" % e_fedid |
---|
77 | if st: print "status: %s" % st |
---|