source: fedd/fedd_terminate.py @ a0c2866

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

Make sure there is an abac directory.

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