source: fedd/fedd_terminate.py @ 187a8f9

Last change on this file since 187a8f9 was 6bedbdba, checked in by Ted Faber <faber@…>, 13 years ago

Split topdl and fedid out to different packages. Add differential
installs

  • Property mode set to 100755
File size: 2.7 KB
Line 
1#!/usr/bin/env python
2
3import sys
4
5from deter import fedid
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, log_authentication
10
11class terminate_opts(client_opts):
12    def __init__(self):
13        client_opts.__init__(self)
14        self.add_option("--experiment_cert", dest="exp_certfile",
15                action='callback', callback=self.expand_file, type='str',
16                help="experiment certificate file")
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,
23                action='callback', callback=self.expand_file, type='str',
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()
32
33try:
34    cert, fid, url = wrangle_standard_options(opts)
35except RuntimeError, e:
36    sys.exit("%s" %e)
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,
63            url, opts.transport, cert, opts.trusted, 
64            serialize_only=opts.serialize_only,
65            tracefile=opts.tracefile,
66            caller=service_caller('Terminate'), 
67            responseBody='TerminateResponseBody')
68except RPCException, e:
69    exit_with_fault(e, 'Terminate', opts)
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")
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.