source: fedd/fedd_terminate.py @ 1294d29

axis_examplecompt_changesinfo-ops
Last change on this file since 1294d29 was 2e46f35, checked in by mikeryan <mikeryan@…>, 14 years ago

switch to /usr/bin/env python to run python

  • Property mode set to 100755
File size: 2.7 KB
RevLine 
[2e46f35]1#!/usr/bin/env python
[d743d60]2
3import sys
4
5from federation.fedid import fedid
[e83f2f2]6from federation.proof import proof
[d743d60]7from federation.remote_service import service_caller
8from federation.client_lib import client_opts, exit_with_fault, RPCException, \
[e83f2f2]9        wrangle_standard_options, do_rpc, log_authentication
[d743d60]10
11class terminate_opts(client_opts):
12    def __init__(self):
13        client_opts.__init__(self)
14        self.add_option("--experiment_cert", dest="exp_certfile",
[62f3dd9]15                action='callback', callback=self.expand_file, type='str',
16                help="experiment certificate file")
[d743d60]17        self.add_option("--experiment_name", dest="exp_name",
18                type="string", help="human readable experiment name")
19        self.add_option("--force", dest="force",
20                action="store_true", default=False,
21                help="Force termination if experiment is in strange state")
22        self.add_option("--logfile", dest="logfile", default=None,
[62f3dd9]23                action='callback', callback=self.expand_file, type='str',
[d743d60]24                help="File to write log to")
25        self.add_option("--print_log", dest="print_log", default=False,
26                action="store_true",
27                help="Print deallocation log to standard output")
28
29# Main line
30parser = terminate_opts()
31(opts, args) = parser.parse_args()
[a0c2866]32
33try:
34    cert, fid, url = wrangle_standard_options(opts)
35except RuntimeError, e:
36    sys.exit("%s" %e)
[d743d60]37
38if opts.exp_name and opts.exp_certfile:
39    sys.exit("Only one of --experiment_cert and --experiment_name permitted")
40elif opts.exp_certfile:
41    exp_id = { 'fedid': fedid(file=opts.exp_certfile) }
42elif opts.exp_name:
43    exp_id = { 'localname' : opts.exp_name }
44else:
45    sys.exit("Must give one of --experiment_cert or --experiment_name");
46
47
48if opts.print_log and opts.logfile:
49    sys.exit("Only one of --logfile and --print_log is permitted")
50elif opts.print_log:
51    out = sys.stdout
52elif opts.logfile:
53    try:
54        out = open(opts.logfile, "w")
55    except EnvironmentError, e:
56        sys.exit("Cannot open logfile: %s" %e)
57else:
58    out = None
59
60req = { 'experiment': exp_id, 'force': opts.force }
61try:
62    resp_dict = do_rpc(req,
[5d854e1]63            url, opts.transport, cert, opts.trusted, 
[d743d60]64            serialize_only=opts.serialize_only,
65            tracefile=opts.tracefile,
66            caller=service_caller('Terminate'), 
67            responseBody='TerminateResponseBody')
68except RPCException, e:
[e83f2f2]69    exit_with_fault(e, 'Terminate', opts)
[d743d60]70except RuntimeError, e:
71    sys.exit("Error processing RPC: %s" % e)
72
73if out:
74    log = resp_dict.get('deallocationLog', None)
75    if log:
76        print >>out, log
77        out.close()
78    else:
79        out.close()
80        sys.exit("No log returned")
[e83f2f2]81proof = proof.from_dict(resp_dict.get('proof', {}))
82if proof and opts.auth_log:
83    log_authentication(opts.auth_log, 'Terminate', 'succeeded', proof)
Note: See TracBrowser for help on using the repository browser.