1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 import base64
18
19 from spacewalk.common.rhnLog import log_debug
20 from spacewalk.server import rhnSQL
21
22
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
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
68
69
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