1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 import sys
17 from spacewalk.common.rhnLog import log_debug
18 from spacewalk.server import rhnSQL
19 from spacewalk.server.rhnLib import InvalidAction
20 from spacewalk.common.usix import raise_with_tb
21
22 __rhnexport__ = ['refresh',
23 'shutdown',
24 'reboot',
25 'resume',
26 'start',
27 'schedulePoller',
28 'suspend',
29 'destroy',
30 'setMemory',
31 'setVCPUs'
32 ]
33
34
35
36
37 _query_refresh = rhnSQL.Statement("""
38 select avf.action_id,
39 from rhnActionVirtRefresh
40 where avf.action_id = :action_id
41 """)
42
43 _query_shutdown = rhnSQL.Statement("""
44 select avs.action_id,
45 avs.uuid
46 from rhnActionVirtShutdown avs
47 where avs.action_id = :action_id
48 """)
49
50 _query_suspend = rhnSQL.Statement("""
51 select avs.action_id,
52 avs.uuid
53 from rhnActionVirtSuspend avs
54 where avs.action_id = :action_id
55 """)
56
57 _query_resume = rhnSQL.Statement("""
58 select avr.action_id,
59 avr.uuid
60 from rhnActionVirtResume avr
61 where avr.action_id = :action_id
62 """)
63
64 _query_reboot = rhnSQL.Statement("""
65 select avr.action_id,
66 avr.uuid
67 from rhnActionVirtReboot avr
68 where avr.action_id = :action_id
69
70 """)
71
72 _query_destroy = rhnSQL.Statement("""
73 select avd.action_id,
74 avd.uuid
75 from rhnActionVirtDestroy avd
76 where avd.action_id = :action_id
77 """)
78
79 _query_start = rhnSQL.Statement("""
80 select avs.action_id,
81 avs.uuid
82 from rhnActionVirtStart avs
83 where avs.action_id = :action_id
84 """)
85
86 _query_setMemory = rhnSQL.Statement("""
87 select asm.action_id,
88 asm.uuid,
89 asm.memory
90 from rhnActionVirtSetMemory asm
91 where asm.action_id = :action_id
92 """)
93
94 _query_getVCPUs = rhnSQL.Statement("""
95 select av.action_id,
96 av.uuid,
97 av.vcpu
98 from rhnActionVirtVCPU av
99 where av.action_id = :action_id
100 """)
101
102 _query_schedulePoller = rhnSQL.Statement("""
103 select asp.action_id,
104 asp.minute,
105 asp.hour,
106 asp.dom,
107 asp.month,
108 asp.dow
109 from rhnActionVirtSchedulePoller asp
110 where asp.action_id = :action_id
111 """)
112
113
114
115
116
117
118
123
124
129
130
146
147
148
149
150 -def refresh(server_id, action_id, dry_run=0):
165
166
167
168
169 -def action(action_name, query, server_id, action_id, dry_run=0):
179
180
181 -def start(server_id, action_id, dry_run=0):
183
184
185 -def shutdown(server_id, action_id, dry_run=0):
187
188
189 -def suspend(server_id, action_id, dry_run=0):
191
192
193 -def resume(server_id, action_id, dry_run=0):
195
196
197 -def reboot(server_id, action_id, dry_run=0):
199
200
201 -def destroy(server_id, action_id, dry_run=0):
203
204
205
206
207 -def setMemory(server_id, action_id, dry_run=0):
227
228
229
230
231 -def setVCPUs(server_id, action_id, dry_run=0):
242
243
244
246 log_debug(3, dry_run)
247
248 prepared_query = rhnSQL.prepare(_query_schedulePoller)
249 prepared_query.execute(action_id=action_id)
250 row = prepared_query.fetchone_dict()
251
252 if not row:
253 raise InvalidAction("No schedulePoller actions found.")
254
255 if 'minute' not in row:
256 raise InvalidAction("schedulePoller action %s has no minute associated with it." % str(action_id))
257
258 if 'hour' not in row:
259 raise InvalidAction("schedulePoller action %s has no hour associated with it." % str(action_id))
260
261 if 'dom' not in row:
262 raise InvalidAction("schedulePoller action %s has no day of the month associated with it." % str(action_id))
263
264 if 'month' not in row:
265 raise InvalidAction("schedulePoller action %s has no month associated with it." % str(action_id))
266
267 if 'dow' not in row:
268 raise InvalidAction("schedulePoller action %s has no day of the week associated with it." % str(action_id))
269
270 return (row['minute'], row['hour'], row['dom'], row['month'], row['dow'])
271