source: fedd/fedd_terminate.py @ d3c8759

axis_examplecompt_changesinfo-opsversion-3.01version-3.02
Last change on this file since d3c8759 was d743d60, checked in by Ted Faber <faber@…>, 14 years ago

Totally refactor fedd_client.py into component scripts. The previous layout
have become a twisty hell of misdirected OOP and learning python run amok.
This version is actually pretty readable and will be much easier to build on.

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