Package backend :: Package server :: Package rhnServer :: Module server_history
[hide private]
[frames] | no frames]

Source Code for Module backend.server.rhnServer.server_history

 1  # 
 2  # Copyright (c) 2008--2016 Red Hat, Inc. 
 3  # 
 4  # This software is licensed to you under the GNU General Public License, 
 5  # version 2 (GPLv2). There is NO WARRANTY for this software, express or 
 6  # implied, including the implied warranties of MERCHANTABILITY or FITNESS 
 7  # FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 
 8  # along with this software; if not, see 
 9  # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. 
10  # 
11  # Red Hat trademarks are not licensed under GPLv2. No permission is 
12  # granted to use or replicate Red Hat trademarks that are incorporated 
13  # in this software or its documentation. 
14  # 
15  # Class for handling and updating the server history. 
16  # 
17   
18  from spacewalk.common.rhnLog import log_debug 
19  from spacewalk.server import rhnSQL 
20   
21  # these are kind of out there... 
22  MAX_SUMMARY = 128 
23  MAX_DETAILS = 4000 
24   
25   
26 -class History:
27
28 - def __init__(self):
29 self.__h = []
30
31 - def add_history(self, summary, details=""):
32 """ Add a history event to the server. """ 33 log_debug(4, summary) 34 if details == '': 35 self.__h.append((summary[:MAX_SUMMARY], None)) 36 else: 37 self.__h.append((summary[:MAX_SUMMARY], details[:MAX_DETAILS]))
38
39 - def save_history_byid(self, server_id):
40 log_debug(3, server_id, "%d history events" % len(self.__h)) 41 if not self.__h: 42 return 0 43 hist = rhnSQL.prepare(""" 44 insert into rhnServerHistory 45 (id, 46 server_id, 47 summary, 48 details) 49 values 50 (sequence_nextval('rhn_event_id_seq'), 51 :server_id, 52 :summary, 53 :details) 54 """) 55 summaries = [x[0] for x in self.__h] 56 details = [x[1] for x in self.__h] 57 server_ids = [server_id] * len(self.__h) 58 hist.executemany(server_id=server_ids, summary=summaries, 59 details=details) 60 # Clear the history cache 61 self.__h = [] 62 return 0
63