From 4d7c6f43ac66f0b9c8acf6a273b647152983ce61 Mon Sep 17 00:00:00 2001 From: Vijayendra Bhamidipati Date: Fri, 17 Aug 2012 12:23:13 -0700 Subject: [PATCH] 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. --- .../cloud/upgrade/dao/Upgrade304to305.java | 51 ++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/server/src/com/cloud/upgrade/dao/Upgrade304to305.java b/server/src/com/cloud/upgrade/dao/Upgrade304to305.java index bba46ed7fbd..3cb02ac33a9 100644 --- a/server/src/com/cloud/upgrade/dao/Upgrade304to305.java +++ b/server/src/com/cloud/upgrade/dao/Upgrade304to305.java @@ -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");