source: fedd/fedd_new.py @ a96d946

axis_examplecompt_changesinfo-ops
Last change on this file since a96d946 was a0c2866, checked in by Ted Faber <faber@…>, 14 years ago

Make sure there is an abac directory.

  • Property mode set to 100755
File size: 2.4 KB
Line 
1#!/usr/local/bin/python
2
3import sys
4
5from federation.fedid import fedid, generate_fedid
6from federation.remote_service import service_caller
7from 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
12class 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
24parser = new_opts()
25(opts, args) = parser.parse_args()
26
27try:
28    cert, fid, url = wrangle_standard_options(opts)
29    acerts = get_abac_certs(opts.abac_dir)
30except EnvironmentError, e:
31    sys.exit('%s: %s' % (e.filename, e.strerror))
32except RuntimeError, e:
33    sys.exit("%s" %e)
34
35out_certfile = opts.out_certfile
36
37msg = { }
38
39if opts.gen_cert:
40    expid, expcert = generate_fedid(opts.exp_name or 'dummy')
41    msg['experimentAccess'] = { 'X509': expcert }
42else:
43    expcert = None
44
45if opts.exp_name:
46    msg['experimentID'] = { 'localname': opts.exp_name }
47
48if acerts:
49    msg['credential'] = acerts
50
51if opts.debug > 1: print >>sys.stderr, msg
52
53try:
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')
59except RPCException, e:
60    exit_with_fault(e)
61except RuntimeError, e:
62    sys.exit("Error processing RPC: %s" % e)
63
64if opts.debug > 1: print >>sys.stderr, resp_dict
65
66try:
67    save_certfile(opts.out_certfile, resp_dict.get('experimentAccess', None), 
68            expcert)
69except EnvironmentError, e:
70    sys.exit('Could not write to %s:' %  (e.strerror, e.filename))
71except CertificateMismatchError:
72    printf >>sys.stderr, "Fedid of created experiment does not match generated"
73
74
75e_fedid, e_local = get_experiment_names(resp_dict.get('experimentID', None))
76st = resp_dict.get('experimentStatus', None)
77
78if e_local: print "localname: %s" % e_local
79if e_fedid: print "fedid: %s" % e_fedid
80if st: print "status: %s" % st
Note: See TracBrowser for help on using the repository browser.