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