source: fedd/fedd_spewlog.py @ c6d6c43

axis_examplecompt_changesinfo-ops
Last change on this file since c6d6c43 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.8 KB
RevLine 
[2e46f35]1#!/usr/bin/env python
[d743d60]2
3import sys
4import time
5
[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, \
9        wrangle_standard_options, do_rpc, get_experiment_names, save_certfile
10
11class spew_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 name certificate file")
[d743d60]17        self.add_option("--experiment_name", dest="exp_name",
18                type="string", help="human readable experiment name")
19        self.add_option("--logfile", dest="logfile", default=None,
[62f3dd9]20                action='callback', callback=self.expand_file, type='str',
[d743d60]21                help="File to write log to")
22        self.add_option('--update_time', dest='update', type='int', default=10,
23                help='how often to update the printed log')
24
25# Keep requesting experiment status and printing updates to the log until the
26# experiment is done being created.
27parser = spew_opts()
28(opts, args) = parser.parse_args()
29
[a0c2866]30try:
31    cert, fid, url = wrangle_standard_options(opts)
32except RuntimeError, e:
33    sys.exit("%s" %e)
[d743d60]34
35if opts.exp_name and opts.exp_certfile:
36    sys.exit("Only one of --experiment_cert and --experiment_name permitted");
37elif opts.exp_certfile:
38    exp_id = { 'fedid': fedid(file=opts.exp_certfile) }
39elif opts.exp_name:
40    exp_id = { 'localname' : opts.exp_name }
41else:
42    sys.exit("specify one of --experiment_cert and --experiment_name")
43
44if opts.logfile:
45    try:
46        out = open(opts.logfile, "w")
47    except IOError,e:
48        sys.exit("Cannot open logfile: %s" %e)
49else:
50    out = sys.stdout
51
52req = { 'experiment': exp_id }
53
54status = "starting"
55log = ""
56log_offset = 0
57update = opts.update
58while status == 'starting':
59    try:
60        resp_dict = do_rpc(req,
[5d854e1]61                url, opts.transport, cert, opts.trusted, 
[d743d60]62                serialize_only=opts.serialize_only,
63                tracefile=opts.tracefile,
64                caller=service_caller('Info'), responseBody="InfoResponseBody")
65    except RPCException, e:
[e83f2f2]66        exit_with_fault(e, 'Info (spewlog)', opts)
[d743d60]67    except RuntimeError, e:
68        sys.exit("Error processing RPC: %s" % e)
69
[e83f2f2]70    proof = proof.from_dict(resp_dict.get('proof', {}))
71    if proof and opts.auth_log:
72        log_authentication(opts.auth_log, 'Info (spewlog)', 'succeeded', proof)
73
[d743d60]74    if not opts.serialize_only:
75        status = resp_dict.get('experimentStatus', None)
76    else:
77        status = "active"
78    log = resp_dict.get('allocationLog', None)
79    if not status:
80        sys.exit("No status in Info response??")
81    if log:
82        if len(log) > log_offset:
83            print >>out, log[log_offset:],
84            out.flush()
85            log_offset = len(log)
86    if status == 'starting': 
87        time.sleep(update)
88print >>out
89print >>out, status
90out.close()
Note: See TracBrowser for help on using the repository browser.