Package backend :: Package server :: Package action_extra_data :: Module script
[hide private]
[frames] | no frames]

Source Code for Module backend.server.action_extra_data.script

 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  # 
16   
17  import base64 
18   
19  from spacewalk.common.rhnLog import log_debug 
20  from spacewalk.server import rhnSQL 
21   
22  # the "exposed" functions 
23  __rhnexport__ = ['run'] 
24   
25  _query_clear_output = rhnSQL.Statement(""" 
26  delete from rhnServerActionScriptResult 
27   where server_id = :server_id 
28     and action_script_id = ( 
29       select id from rhnActionScript where action_id = :action_id 
30     ) 
31  """) 
32   
33  _query_initial_store = rhnSQL.Statement(""" 
34  insert into rhnServerActionScriptResult ( 
35      server_id, 
36      action_script_id, 
37      output, 
38      start_date, 
39      stop_date, 
40      return_code 
41    ) 
42  values ( 
43         :server_id, 
44         (select ascript.id 
45            from rhnActionScript ascript 
46           where ascript.action_id = :action_id), 
47         :output, 
48         TO_TIMESTAMP(:process_start, 'YYYY-MM-DD HH24:MI:SS'), 
49         TO_TIMESTAMP(:process_end, 'YYYY-MM-DD HH24:MI:SS'), 
50         :return_code) 
51  """) 
52   
53   
54 -def run(server_id, action_id, data={}):
55 log_debug(3) 56 57 # clear any previously received output 58 h = rhnSQL.prepare(_query_clear_output) 59 h.execute(server_id=server_id, action_id=action_id) 60 61 if not data: 62 log_debug(4, "No data sent by client") 63 return 64 65 output = data.get('output') 66 67 # newer clients should always be setting 68 # this flag and encoding the results, 69 # otherwise xmlrpc isn't very happy on certain characters 70 if 'base64enc' in data: 71 output = base64.decodestring(output) 72 73 return_code = data.get('return_code') 74 process_end = data.get('process_end') 75 process_start = data.get('process_start') 76 77 log_debug(4, "script output", output) 78 79 h = rhnSQL.prepare(_query_initial_store, blob_map={'output': 'output'}) 80 h.execute(server_id=server_id, 81 action_id=action_id, 82 process_start=process_start, 83 process_end=process_end, 84 return_code=return_code, 85 output=output 86 )
87