source: fedd/fedd_operation.py @ bea19b7

Last change on this file since bea19b7 was 6bedbdba, checked in by Ted Faber <faber@…>, 13 years ago

Split topdl and fedid out to different packages. Add differential
installs

  • Property mode set to 100755
File size: 2.6 KB
Line 
1#!/usr/bin/env python
2
3import sys
4
5from deter import topdl
6from deter import fedid
7
8from federation.proof import proof
9from federation.remote_service import service_caller
10from federation.client_lib import client_opts, exit_with_fault, RPCException,\
11        wrangle_standard_options, do_rpc, get_experiment_names, info_format, \
12        log_authentication
13
14class operation_opts(client_opts):
15    def __init__(self):
16        client_opts.__init__(self)
17        self.add_option("--experiment_cert", dest="exp_certfile",
18                action='callback', callback=self.expand_file, type='str',
19                help="experiment certificate file")
20        self.add_option("--experiment_name", dest="exp_name",
21                type="string", help="human readable experiment name")
22        self.add_option('--target', dest='targets', action='append',
23                help='targets of the operation')
24        self.add_option('--operation', dest='op', help='operation to carry out')
25        self.add_option('--param', dest='params', action='append',
26                help='parameters to the operation as name=value')
27
28parser = operation_opts()
29(opts, args) = parser.parse_args()
30try:
31    cert, fid, url = wrangle_standard_options(opts)
32except RuntimeError, e:
33    sys.exit("%s" % e)
34
35if opts.exp_name and opts.exp_certfile:
36    sys.exit("Only one of --experiment_cert and --experiment_name permitted")
37elif opts.exp_certfile:
38    exp_id = { 'fedid': fedid(file=opts.exp_certfile) }
39elif opts.exp_name:
40    exp_id = { 'localname' : opts.exp_name }
41else:
42    sys.exit("specify one of --experiment_cert and --experiment_name")
43
44if not opts.op: sys.exit('specifiy an --operation')
45if not opts.targets: sys.exit('specify one or more targets')
46
47req = { 'experiment': exp_id, 'operation': opts.op, 'target': opts.targets}
48if opts.params:
49    param = []
50    for p in opts.params:
51        try:
52            a, v = p.split('=')
53        except ValueError:
54            sys.exit('Parameters must be in name=value: %s' %p)
55        param.append({'attribute': a, 'value': v})
56    req['parameter'] = param
57
58try:
59    resp_dict = do_rpc(req,
60            url, opts.transport, cert, opts.trusted, 
61            serialize_only=opts.serialize_only,
62            tracefile=opts.tracefile,
63            caller=service_caller('Operation'), 
64            responseBody='OperationResponseBody')
65except RPCException, e:
66    exit_with_fault(e, 'Ftopo', opts)
67except RuntimeError, e:
68    sys.exit("Error processing RPC: %s" % e)
69
70for s in resp_dict.get('status', []):
71    print "Target: %s Message: %s (code: %d)" % \
72            (s.get('target', ''), s.get('description',''), s.get('code', -1))
73
74proof = proof.from_dict(resp_dict.get('proof', {}))
75if proof and opts.auth_log:
76    log_authentication(opts.auth_log, 'Operation', 'succeeded', proof)
Note: See TracBrowser for help on using the repository browser.