source: fedd/fedd_operation.py @ 6886c5a

compt_changesinfo-ops
Last change on this file since 6886c5a was 1ae1aa2, checked in by Ted Faber <faber@…>, 13 years ago

Reload interface works

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