[d743d60] | 1 | #!/usr/local/bin/python |
---|
| 2 | |
---|
| 3 | import sys |
---|
| 4 | |
---|
[7206e5a] | 5 | from federation.fedid import fedid, generate_fedid |
---|
[d743d60] | 6 | from federation.remote_service import service_caller |
---|
| 7 | from federation.client_lib import client_opts, exit_with_fault, RPCException, \ |
---|
[7206e5a] | 8 | wrangle_standard_options, do_rpc, get_experiment_names, \ |
---|
| 9 | save_certfile, get_abac_certs |
---|
[d743d60] | 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", |
---|
[62f3dd9] | 16 | action='callback', callback=self.expand_file, type='str', |
---|
| 17 | help="output certificate file") |
---|
[d743d60] | 18 | self.add_option("--experiment_name", dest="exp_name", |
---|
| 19 | type="string", help="Suggested experiment name") |
---|
[353db8c] | 20 | self.add_option('--gen_cert', action='store_true', dest='gen_cert', |
---|
[7206e5a] | 21 | default=False, |
---|
| 22 | help='generate a cert to which to delegate rights') |
---|
[d743d60] | 23 | |
---|
| 24 | parser = new_opts() |
---|
| 25 | (opts, args) = parser.parse_args() |
---|
| 26 | |
---|
[7206e5a] | 27 | try: |
---|
[a0c2866] | 28 | cert, fid, url = wrangle_standard_options(opts) |
---|
[7206e5a] | 29 | acerts = get_abac_certs(opts.abac_dir) |
---|
| 30 | except EnvironmentError, e: |
---|
| 31 | sys.exit('%s: %s' % (e.filename, e.strerror)) |
---|
[a0c2866] | 32 | except RuntimeError, e: |
---|
| 33 | sys.exit("%s" %e) |
---|
[d743d60] | 34 | |
---|
| 35 | out_certfile = opts.out_certfile |
---|
| 36 | |
---|
| 37 | msg = { } |
---|
| 38 | |
---|
[7206e5a] | 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 | |
---|
[d743d60] | 45 | if opts.exp_name: |
---|
| 46 | msg['experimentID'] = { 'localname': opts.exp_name } |
---|
| 47 | |
---|
[7206e5a] | 48 | if acerts: |
---|
| 49 | msg['credential'] = acerts |
---|
| 50 | |
---|
[d743d60] | 51 | if opts.debug > 1: print >>sys.stderr, msg |
---|
| 52 | |
---|
| 53 | try: |
---|
| 54 | resp_dict = do_rpc(msg, |
---|
[5d854e1] | 55 | url, opts.transport, cert, opts.trusted, |
---|
[d743d60] | 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: |
---|
[7206e5a] | 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 | |
---|
[d743d60] | 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 |
---|