source: fedd/fedd_terminate.py @ 62f3dd9

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

allow command line progams to expand tildes. Added a class derived from OptionParser? to make that easily available.

  • 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
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()
31cert, fid, url = wrangle_standard_options(opts)
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("Must give one of --experiment_cert or --experiment_name");
41
42
43if opts.print_log and opts.logfile:
44    sys.exit("Only one of --logfile and --print_log is permitted")
45elif opts.print_log:
46    out = sys.stdout
47elif opts.logfile:
48    try:
49        out = open(opts.logfile, "w")
50    except EnvironmentError, e:
51        sys.exit("Cannot open logfile: %s" %e)
52else:
53    out = None
54
55req = { 'experiment': exp_id, 'force': opts.force }
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('Terminate'), 
62            responseBody='TerminateResponseBody')
63except RPCException, e:
64    exit_with_fault(e)
65except RuntimeError, e:
66    sys.exit("Error processing RPC: %s" % e)
67
68if out:
69    log = resp_dict.get('deallocationLog', None)
70    if log:
71        print >>out, log
72        out.close()
73    else:
74        out.close()
75        sys.exit("No log returned")
Note: See TracBrowser for help on using the repository browser.