CS-16042: 3.0.x to 3.0.5 Upgrade: VMWare : Upgrade Procedure for using the new Burbank System Template in place of Acton System Template Required

Description:

    Updating system VM template for vmware for 3.0.5.
This commit is contained in:
Vijayendra Bhamidipati 2012-08-17 12:23:13 -07:00
parent 4b4d4555f3
commit 4d7c6f43ac
1 changed files with 50 additions and 1 deletions

View File

@ -60,6 +60,7 @@ public class Upgrade304to305 extends Upgrade30xBase implements DbUpgrade {
addVpcProvider(conn);
updateRouterNetworkRef(conn);
correctNetworkUsingExternalDevices(conn);
updateSystemVms(conn);
}
@Override
@ -71,7 +72,55 @@ public class Upgrade304to305 extends Upgrade30xBase implements DbUpgrade {
return new File[] { new File(script) };
}
private void updateSystemVms(Connection conn){
PreparedStatement pstmt = null;
ResultSet rs = null;
boolean VMware = false;
try {
pstmt = conn.prepareStatement("select distinct(hypervisor_type) from `cloud`.`cluster` where removed is null");
rs = pstmt.executeQuery();
while(rs.next()){
if("VMware".equals(rs.getString(1))){
VMware = true;
}
}
} catch (SQLException e) {
throw new CloudRuntimeException("Error while iterating through list of hypervisors in use", e);
}
// Just update the VMware system template. Other hypervisor templates are unchanged from previous 3.0.x versions.
s_logger.debug("Updating VMware System Vms");
try {
//Get 3.0.5 VMware system Vm template Id
pstmt = conn.prepareStatement("select id from `cloud`.`vm_template` where name = 'systemvm-vmware-3.0.5' and removed is null");
rs = pstmt.executeQuery();
if(rs.next()){
long templateId = rs.getLong(1);
rs.close();
pstmt.close();
// change template type to SYSTEM
pstmt = conn.prepareStatement("update `cloud`.`vm_template` set type='SYSTEM' where id = ?");
pstmt.setLong(1, templateId);
pstmt.executeUpdate();
pstmt.close();
// update templete ID of system Vms
pstmt = conn.prepareStatement("update `cloud`.`vm_instance` set vm_template_id = ? where type <> 'User' and hypervisor_type = 'VMware'");
pstmt.setLong(1, templateId);
pstmt.executeUpdate();
pstmt.close();
} else {
if (VMware){
throw new CloudRuntimeException("3.0.5 VMware SystemVm template not found. Cannot upgrade system Vms");
} else {
s_logger.warn("3.0.5 VMware SystemVm template not found. VMware hypervisor is not used, so not failing upgrade");
}
}
} catch (SQLException e) {
throw new CloudRuntimeException("Error while updating VMware systemVm template", e);
}
s_logger.debug("Updating System Vm Template IDs Complete");
}
private void addVpcProvider(Connection conn){
//Encrypt config params and change category to Hidden
s_logger.debug("Adding vpc provider to all physical networks in the system");