You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
s_logger.debug("Updating System Vm template IDs");
124
+
try{
125
+
//Get all hypervisors in use
126
+
try {
127
+
pstmt = conn.prepareStatement("select distinct(hypervisor_type) from `cloud`.`cluster` where removed is null");
128
+
rs = pstmt.executeQuery();
129
+
while(rs.next()){
130
+
if("XenServer".equals(rs.getString(1))){
131
+
xenserver = true;
132
+
} elseif("KVM".equals(rs.getString(1))){
133
+
kvm = true;
134
+
} elseif("VMware".equals(rs.getString(1))){
135
+
VMware = true;
136
+
} elseif("Hyperv".equals(rs.getString(1))) {
137
+
Hyperv = true;
138
+
} elseif("LXC".equals(rs.getString(1))) {
139
+
LXC = true;
140
+
}
141
+
}
142
+
} catch (SQLExceptione) {
143
+
thrownewCloudRuntimeException("Error while listing hypervisors in use", e);
144
+
}
145
+
146
+
s_logger.debug("Updating XenSever System Vms");
147
+
//XenServer
148
+
try {
149
+
//Get 4.2.0 xenserer system Vm template Id
150
+
pstmt = conn.prepareStatement("select id from `cloud`.`vm_template` where name like 'systemvm-xenserver-4.2' and removed is null order by id desc limit 1");
151
+
rs = pstmt.executeQuery();
152
+
if(rs.next()){
153
+
longtemplateId = rs.getLong(1);
154
+
rs.close();
155
+
pstmt.close();
156
+
// change template type to SYSTEM
157
+
pstmt = conn.prepareStatement("update `cloud`.`vm_template` set type='SYSTEM' where id = ?");
158
+
pstmt.setLong(1, templateId);
159
+
pstmt.executeUpdate();
160
+
pstmt.close();
161
+
// update templete ID of system Vms
162
+
pstmt = conn.prepareStatement("update `cloud`.`vm_instance` set vm_template_id = ? where type <> 'User' and hypervisor_type = 'XenServer'");
163
+
pstmt.setLong(1, templateId);
164
+
pstmt.executeUpdate();
165
+
pstmt.close();
166
+
} else {
167
+
if (xenserver){
168
+
thrownewCloudRuntimeException("4.2.0 XenServer SystemVm template not found. Cannot upgrade system Vms");
169
+
} else {
170
+
s_logger.warn("4.2.0 XenServer SystemVm template not found. XenServer hypervisor is not used, so not failing upgrade");
171
+
}
172
+
}
173
+
} catch (SQLExceptione) {
174
+
thrownewCloudRuntimeException("Error while updating XenServer systemVm template", e);
175
+
}
176
+
177
+
//KVM
178
+
s_logger.debug("Updating KVM System Vms");
179
+
try {
180
+
//Get 4.2.0 KVM system Vm template Id
181
+
pstmt = conn.prepareStatement("select id from `cloud`.`vm_template` where name = 'systemvm-kvm-4.2' and removed is null order by id desc limit 1");
182
+
rs = pstmt.executeQuery();
183
+
if(rs.next()){
184
+
longtemplateId = rs.getLong(1);
185
+
rs.close();
186
+
pstmt.close();
187
+
// change template type to SYSTEM
188
+
pstmt = conn.prepareStatement("update `cloud`.`vm_template` set type='SYSTEM' where id = ?");
189
+
pstmt.setLong(1, templateId);
190
+
pstmt.executeUpdate();
191
+
pstmt.close();
192
+
// update templete ID of system Vms
193
+
pstmt = conn.prepareStatement("update `cloud`.`vm_instance` set vm_template_id = ? where type <> 'User' and hypervisor_type = 'KVM'");
194
+
pstmt.setLong(1, templateId);
195
+
pstmt.executeUpdate();
196
+
pstmt.close();
197
+
} else {
198
+
if (kvm){
199
+
thrownewCloudRuntimeException("4.2.0 KVM SystemVm template not found. Cannot upgrade system Vms");
200
+
} else {
201
+
s_logger.warn("4.2.0 KVM SystemVm template not found. KVM hypervisor is not used, so not failing upgrade");
202
+
}
203
+
}
204
+
} catch (SQLExceptione) {
205
+
thrownewCloudRuntimeException("Error while updating KVM systemVm template", e);
206
+
}
207
+
208
+
//VMware
209
+
s_logger.debug("Updating VMware System Vms");
210
+
try {
211
+
//Get 4.2.0 VMware system Vm template Id
212
+
pstmt = conn.prepareStatement("select id from `cloud`.`vm_template` where name = 'systemvm-vmware-4.2' and removed is null order by id desc limit 1");
213
+
rs = pstmt.executeQuery();
214
+
if(rs.next()){
215
+
longtemplateId = rs.getLong(1);
216
+
rs.close();
217
+
pstmt.close();
218
+
// change template type to SYSTEM
219
+
pstmt = conn.prepareStatement("update `cloud`.`vm_template` set type='SYSTEM' where id = ?");
220
+
pstmt.setLong(1, templateId);
221
+
pstmt.executeUpdate();
222
+
pstmt.close();
223
+
// update templete ID of system Vms
224
+
pstmt = conn.prepareStatement("update `cloud`.`vm_instance` set vm_template_id = ? where type <> 'User' and hypervisor_type = 'VMware'");
225
+
pstmt.setLong(1, templateId);
226
+
pstmt.executeUpdate();
227
+
pstmt.close();
228
+
} else {
229
+
if (VMware){
230
+
thrownewCloudRuntimeException("4.2.0 VMware SystemVm template not found. Cannot upgrade system Vms");
231
+
} else {
232
+
s_logger.warn("4.2.0 VMware SystemVm template not found. VMware hypervisor is not used, so not failing upgrade");
233
+
}
234
+
}
235
+
} catch (SQLExceptione) {
236
+
thrownewCloudRuntimeException("Error while updating VMware systemVm template", e);
237
+
}
238
+
239
+
//Hyperv
240
+
s_logger.debug("Updating Hyperv System Vms");
241
+
try {
242
+
//Get 4.2.0 Hyperv system Vm template Id
243
+
pstmt = conn.prepareStatement("select id from `cloud`.`vm_template` where name = 'systemvm-hyperv-4.2' and removed is null order by id desc limit 1");
244
+
rs = pstmt.executeQuery();
245
+
if(rs.next()){
246
+
longtemplateId = rs.getLong(1);
247
+
rs.close();
248
+
pstmt.close();
249
+
// change template type to SYSTEM
250
+
pstmt = conn.prepareStatement("update `cloud`.`vm_template` set type='SYSTEM' where id = ?");
251
+
pstmt.setLong(1, templateId);
252
+
pstmt.executeUpdate();
253
+
pstmt.close();
254
+
// update templete ID of system Vms
255
+
pstmt = conn.prepareStatement("update `cloud`.`vm_instance` set vm_template_id = ? where type <> 'User' and hypervisor_type = 'Hyperv'");
256
+
pstmt.setLong(1, templateId);
257
+
pstmt.executeUpdate();
258
+
pstmt.close();
259
+
} else {
260
+
if (Hyperv){
261
+
thrownewCloudRuntimeException("4.2.0 HyperV SystemVm template not found. Cannot upgrade system Vms");
262
+
} else {
263
+
s_logger.warn("4.2.0 Hyperv SystemVm template not found. Hyperv hypervisor is not used, so not failing upgrade");
264
+
}
265
+
}
266
+
} catch (SQLExceptione) {
267
+
thrownewCloudRuntimeException("Error while updating Hyperv systemVm template", e);
268
+
}
269
+
270
+
//LXC
271
+
s_logger.debug("Updating LXC System Vms");
272
+
try {
273
+
//Get 4.2.0 LXC system Vm template Id
274
+
pstmt = conn.prepareStatement("select id from `cloud`.`vm_template` where name = 'systemvm-lxc-4.2' and removed is null order by id desc limit 1");
275
+
rs = pstmt.executeQuery();
276
+
if(rs.next()){
277
+
longtemplateId = rs.getLong(1);
278
+
rs.close();
279
+
pstmt.close();
280
+
// change template type to SYSTEM
281
+
pstmt = conn.prepareStatement("update `cloud`.`vm_template` set type='SYSTEM' where id = ?");
282
+
pstmt.setLong(1, templateId);
283
+
pstmt.executeUpdate();
284
+
pstmt.close();
285
+
// update templete ID of system Vms
286
+
pstmt = conn.prepareStatement("update `cloud`.`vm_instance` set vm_template_id = ? where type <> 'User' and hypervisor_type = 'LXC'");
287
+
pstmt.setLong(1, templateId);
288
+
pstmt.executeUpdate();
289
+
pstmt.close();
290
+
} else {
291
+
if (LXC){
292
+
thrownewCloudRuntimeException("4.2.0 LXC SystemVm template not found. Cannot upgrade system Vms");
293
+
} else {
294
+
s_logger.warn("4.2.0 LXC SystemVm template not found. LXC hypervisor is not used, so not failing upgrade");
295
+
}
296
+
}
297
+
} catch (SQLExceptione) {
298
+
thrownewCloudRuntimeException("Error while updating LXC systemVm template", e);
299
+
}
300
+
s_logger.debug("Updating System Vm Template IDs Complete");
301
+
}
302
+
finally {
303
+
try {
304
+
if (rs != null) {
305
+
rs.close();
306
+
}
307
+
308
+
if (pstmt != null) {
309
+
pstmt.close();
310
+
}
311
+
} catch (SQLExceptione) {
312
+
}
313
+
}
314
+
pstmt = null;
116
315
try {
117
-
sql = conn.prepareStatement("update vm_template set image_data_store_id = 1 where type = 'SYSTEM' or type = 'BUILTIN'");
118
-
sql.executeUpdate();
316
+
pstmt = conn.prepareStatement("update vm_template set image_data_store_id = 1 where type = 'SYSTEM' or type = 'BUILTIN'");
317
+
pstmt.executeUpdate();
119
318
} catch (SQLExceptione) {
120
319
thrownewCloudRuntimeException("Failed to upgrade vm template data store uuid: " + e.toString());
0 commit comments