mirror of
				https://github.com/apache/cloudstack.git
				synced 2025-10-26 08:42:29 +01:00 
			
		
		
		
	systemvmtemplate: new template for 4.15.1 (#4793)
Update new systemvmtemplate for 4.15.1.0; synced: http://download.cloudstack.org/systemvm/4.15/ A new template is necessary due to many security fixes over the last year, the 4.15.0 systemvmtemplate was created about a year ago. Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com> Co-authored-by: Pearl Dsilva <pearl.dsilva@shapeblue.com>
This commit is contained in:
		
							parent
							
								
									5df1337f27
								
							
						
					
					
						commit
						9b1d1e6de3
					
				| @ -23,19 +23,15 @@ import java.sql.PreparedStatement; | |||||||
| import java.sql.ResultSet; | import java.sql.ResultSet; | ||||||
| import java.sql.SQLException; | import java.sql.SQLException; | ||||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||||
| import java.util.HashMap; |  | ||||||
| import java.util.HashSet; |  | ||||||
| import java.util.LinkedHashMap; | import java.util.LinkedHashMap; | ||||||
| import java.util.List; | import java.util.List; | ||||||
| import java.util.Map; | import java.util.Map; | ||||||
| import java.util.Set; |  | ||||||
| 
 | 
 | ||||||
| import org.apache.log4j.Logger; | import org.apache.log4j.Logger; | ||||||
| 
 | 
 | ||||||
| import com.cloud.hypervisor.Hypervisor; |  | ||||||
| import com.cloud.utils.exception.CloudRuntimeException; | import com.cloud.utils.exception.CloudRuntimeException; | ||||||
| 
 | 
 | ||||||
| public class Upgrade41400to41500 implements DbUpgrade, DbUpgradeSystemVmTemplate { | public class Upgrade41400to41500 implements DbUpgrade { | ||||||
| 
 | 
 | ||||||
|     final static Logger LOG = Logger.getLogger(Upgrade41400to41500.class); |     final static Logger LOG = Logger.getLogger(Upgrade41400to41500.class); | ||||||
| 
 | 
 | ||||||
| @ -70,175 +66,6 @@ public class Upgrade41400to41500 implements DbUpgrade, DbUpgradeSystemVmTemplate | |||||||
|         addRolePermissionsForNewReadOnlyAndSupportRoles(conn); |         addRolePermissionsForNewReadOnlyAndSupportRoles(conn); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Override |  | ||||||
|     @SuppressWarnings("serial") |  | ||||||
|     public void updateSystemVmTemplates(final Connection conn) { |  | ||||||
|         LOG.debug("Updating System Vm template IDs"); |  | ||||||
|         final Set<Hypervisor.HypervisorType> hypervisorsListInUse = new HashSet<Hypervisor.HypervisorType>(); |  | ||||||
|         try (PreparedStatement pstmt = conn.prepareStatement("select distinct(hypervisor_type) from `cloud`.`cluster` where removed is null"); ResultSet rs = pstmt.executeQuery()) { |  | ||||||
|             while (rs.next()) { |  | ||||||
|                 switch (Hypervisor.HypervisorType.getType(rs.getString(1))) { |  | ||||||
|                     case XenServer: |  | ||||||
|                         hypervisorsListInUse.add(Hypervisor.HypervisorType.XenServer); |  | ||||||
|                         break; |  | ||||||
|                     case KVM: |  | ||||||
|                         hypervisorsListInUse.add(Hypervisor.HypervisorType.KVM); |  | ||||||
|                         break; |  | ||||||
|                     case VMware: |  | ||||||
|                         hypervisorsListInUse.add(Hypervisor.HypervisorType.VMware); |  | ||||||
|                         break; |  | ||||||
|                     case Hyperv: |  | ||||||
|                         hypervisorsListInUse.add(Hypervisor.HypervisorType.Hyperv); |  | ||||||
|                         break; |  | ||||||
|                     case LXC: |  | ||||||
|                         hypervisorsListInUse.add(Hypervisor.HypervisorType.LXC); |  | ||||||
|                         break; |  | ||||||
|                     case Ovm3: |  | ||||||
|                         hypervisorsListInUse.add(Hypervisor.HypervisorType.Ovm3); |  | ||||||
|                         break; |  | ||||||
|                     default: |  | ||||||
|                         break; |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|         } catch (final SQLException e) { |  | ||||||
|             LOG.error("updateSystemVmTemplates: Exception caught while getting hypervisor types from clusters: " + e.getMessage()); |  | ||||||
|             throw new CloudRuntimeException("updateSystemVmTemplates:Exception while getting hypervisor types from clusters", e); |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         final Map<Hypervisor.HypervisorType, String> NewTemplateNameList = new HashMap<Hypervisor.HypervisorType, String>() { |  | ||||||
|             { |  | ||||||
|                 put(Hypervisor.HypervisorType.KVM, "systemvm-kvm-4.15.0"); |  | ||||||
|                 put(Hypervisor.HypervisorType.VMware, "systemvm-vmware-4.15.0"); |  | ||||||
|                 put(Hypervisor.HypervisorType.XenServer, "systemvm-xenserver-4.15.0"); |  | ||||||
|                 put(Hypervisor.HypervisorType.Hyperv, "systemvm-hyperv-4.15.0"); |  | ||||||
|                 put(Hypervisor.HypervisorType.LXC, "systemvm-lxc-4.15.0"); |  | ||||||
|                 put(Hypervisor.HypervisorType.Ovm3, "systemvm-ovm3-4.15.0"); |  | ||||||
|             } |  | ||||||
|         }; |  | ||||||
| 
 |  | ||||||
|         final Map<Hypervisor.HypervisorType, String> routerTemplateConfigurationNames = new HashMap<Hypervisor.HypervisorType, String>() { |  | ||||||
|             { |  | ||||||
|                 put(Hypervisor.HypervisorType.KVM, "router.template.kvm"); |  | ||||||
|                 put(Hypervisor.HypervisorType.VMware, "router.template.vmware"); |  | ||||||
|                 put(Hypervisor.HypervisorType.XenServer, "router.template.xenserver"); |  | ||||||
|                 put(Hypervisor.HypervisorType.Hyperv, "router.template.hyperv"); |  | ||||||
|                 put(Hypervisor.HypervisorType.LXC, "router.template.lxc"); |  | ||||||
|                 put(Hypervisor.HypervisorType.Ovm3, "router.template.ovm3"); |  | ||||||
|             } |  | ||||||
|         }; |  | ||||||
| 
 |  | ||||||
|         final Map<Hypervisor.HypervisorType, String> newTemplateUrl = new HashMap<Hypervisor.HypervisorType, String>() { |  | ||||||
|             { |  | ||||||
|                 put(Hypervisor.HypervisorType.KVM, "https://download.cloudstack.org/systemvm/4.15/systemvmtemplate-4.15.0-kvm.qcow2.bz2"); |  | ||||||
|                 put(Hypervisor.HypervisorType.VMware, "https://download.cloudstack.org/systemvm/4.15/systemvmtemplate-4.15.0-vmware.ova"); |  | ||||||
|                 put(Hypervisor.HypervisorType.XenServer, "https://download.cloudstack.org/systemvm/4.15/systemvmtemplate-4.15.0-xen.vhd.bz2"); |  | ||||||
|                 put(Hypervisor.HypervisorType.Hyperv, "https://download.cloudstack.org/systemvm/4.15/systemvmtemplate-4.15.0-hyperv.vhd.zip"); |  | ||||||
|                 put(Hypervisor.HypervisorType.LXC, "https://download.cloudstack.org/systemvm/4.15/systemvmtemplate-4.15.0-kvm.qcow2.bz2"); |  | ||||||
|                 put(Hypervisor.HypervisorType.Ovm3, "https://download.cloudstack.org/systemvm/4.15/systemvmtemplate-4.15.0-ovm.raw.bz2"); |  | ||||||
|             } |  | ||||||
|         }; |  | ||||||
| 
 |  | ||||||
|         final Map<Hypervisor.HypervisorType, String> newTemplateChecksum = new HashMap<Hypervisor.HypervisorType, String>() { |  | ||||||
|             { |  | ||||||
|                 put(Hypervisor.HypervisorType.KVM, "81b3e48bb934784a13555a43c5ef5ffb"); |  | ||||||
|                 put(Hypervisor.HypervisorType.XenServer, "1b178a5dbdbe090555515340144c6017"); |  | ||||||
|                 put(Hypervisor.HypervisorType.VMware, "e6a88e518c57d6f36c096c4204c3417f"); |  | ||||||
|                 put(Hypervisor.HypervisorType.Hyperv, "5c94da45337cf3e1910dcbe084d4b9ad"); |  | ||||||
|                 put(Hypervisor.HypervisorType.LXC, "81b3e48bb934784a13555a43c5ef5ffb"); |  | ||||||
|                 put(Hypervisor.HypervisorType.Ovm3, "875c5c65455fc06c4a012394410db375"); |  | ||||||
|             } |  | ||||||
|         }; |  | ||||||
| 
 |  | ||||||
|         for (final Map.Entry<Hypervisor.HypervisorType, String> hypervisorAndTemplateName : NewTemplateNameList.entrySet()) { |  | ||||||
|             LOG.debug("Updating " + hypervisorAndTemplateName.getKey() + " System Vms"); |  | ||||||
|             try (PreparedStatement pstmt = conn.prepareStatement("select id from `cloud`.`vm_template` where name = ? and removed is null order by id desc limit 1")) { |  | ||||||
|                 // Get systemvm template id for corresponding hypervisor |  | ||||||
|                 long templateId = -1; |  | ||||||
|                 pstmt.setString(1, hypervisorAndTemplateName.getValue()); |  | ||||||
|                 try (ResultSet rs = pstmt.executeQuery()) { |  | ||||||
|                     if (rs.next()) { |  | ||||||
|                         templateId = rs.getLong(1); |  | ||||||
|                     } |  | ||||||
|                 } catch (final SQLException e) { |  | ||||||
|                     LOG.error("updateSystemVmTemplates: Exception caught while getting ids of templates: " + e.getMessage()); |  | ||||||
|                     throw new CloudRuntimeException("updateSystemVmTemplates: Exception caught while getting ids of templates", e); |  | ||||||
|                 } |  | ||||||
| 
 |  | ||||||
|                 // change template type to SYSTEM |  | ||||||
|                 if (templateId != -1) { |  | ||||||
|                     try (PreparedStatement templ_type_pstmt = conn.prepareStatement("update `cloud`.`vm_template` set type='SYSTEM' where id = ?");) { |  | ||||||
|                         templ_type_pstmt.setLong(1, templateId); |  | ||||||
|                         templ_type_pstmt.executeUpdate(); |  | ||||||
|                     } catch (final SQLException e) { |  | ||||||
|                         LOG.error("updateSystemVmTemplates:Exception while updating template with id " + templateId + " to be marked as 'system': " + e.getMessage()); |  | ||||||
|                         throw new CloudRuntimeException("updateSystemVmTemplates:Exception while updating template with id " + templateId + " to be marked as 'system'", e); |  | ||||||
|                     } |  | ||||||
|                     // update template ID of system Vms |  | ||||||
|                     try (PreparedStatement update_templ_id_pstmt = conn |  | ||||||
|                             .prepareStatement("update `cloud`.`vm_instance` set vm_template_id = ? where type <> 'User' and hypervisor_type = ? and removed is NULL");) { |  | ||||||
|                         update_templ_id_pstmt.setLong(1, templateId); |  | ||||||
|                         update_templ_id_pstmt.setString(2, hypervisorAndTemplateName.getKey().toString()); |  | ||||||
|                         update_templ_id_pstmt.executeUpdate(); |  | ||||||
|                     } catch (final Exception e) { |  | ||||||
|                         LOG.error("updateSystemVmTemplates:Exception while setting template for " + hypervisorAndTemplateName.getKey().toString() + " to " + templateId |  | ||||||
|                                 + ": " + e.getMessage()); |  | ||||||
|                         throw new CloudRuntimeException("updateSystemVmTemplates:Exception while setting template for " + hypervisorAndTemplateName.getKey().toString() + " to " |  | ||||||
|                                 + templateId, e); |  | ||||||
|                     } |  | ||||||
| 
 |  | ||||||
|                     // Change value of global configuration parameter |  | ||||||
|                     // router.template.* for the corresponding hypervisor |  | ||||||
|                     try (PreparedStatement update_pstmt = conn.prepareStatement("UPDATE `cloud`.`configuration` SET value = ? WHERE name = ?");) { |  | ||||||
|                         update_pstmt.setString(1, hypervisorAndTemplateName.getValue()); |  | ||||||
|                         update_pstmt.setString(2, routerTemplateConfigurationNames.get(hypervisorAndTemplateName.getKey())); |  | ||||||
|                         update_pstmt.executeUpdate(); |  | ||||||
|                     } catch (final SQLException e) { |  | ||||||
|                         LOG.error("updateSystemVmTemplates:Exception while setting " + routerTemplateConfigurationNames.get(hypervisorAndTemplateName.getKey()) + " to " |  | ||||||
|                                 + hypervisorAndTemplateName.getValue() + ": " + e.getMessage()); |  | ||||||
|                         throw new CloudRuntimeException("updateSystemVmTemplates:Exception while setting " |  | ||||||
|                                 + routerTemplateConfigurationNames.get(hypervisorAndTemplateName.getKey()) + " to " + hypervisorAndTemplateName.getValue(), e); |  | ||||||
|                     } |  | ||||||
| 
 |  | ||||||
|                     // Change value of global configuration parameter |  | ||||||
|                     // minreq.sysvmtemplate.version for the ACS version |  | ||||||
|                     try (PreparedStatement update_pstmt = conn.prepareStatement("UPDATE `cloud`.`configuration` SET value = ? WHERE name = ?");) { |  | ||||||
|                         update_pstmt.setString(1, "4.15.0"); |  | ||||||
|                         update_pstmt.setString(2, "minreq.sysvmtemplate.version"); |  | ||||||
|                         update_pstmt.executeUpdate(); |  | ||||||
|                     } catch (final SQLException e) { |  | ||||||
|                         LOG.error("updateSystemVmTemplates:Exception while setting 'minreq.sysvmtemplate.version' to 4.15.0: " + e.getMessage()); |  | ||||||
|                         throw new CloudRuntimeException("updateSystemVmTemplates:Exception while setting 'minreq.sysvmtemplate.version' to 4.15.0", e); |  | ||||||
|                     } |  | ||||||
|                 } else { |  | ||||||
|                     if (hypervisorsListInUse.contains(hypervisorAndTemplateName.getKey())) { |  | ||||||
|                         throw new CloudRuntimeException(getUpgradedVersion() + hypervisorAndTemplateName.getKey() + " SystemVm template not found. Cannot upgrade system Vms"); |  | ||||||
|                     } else { |  | ||||||
|                         LOG.warn(getUpgradedVersion() + hypervisorAndTemplateName.getKey() + " SystemVm template not found. " + hypervisorAndTemplateName.getKey() |  | ||||||
|                                 + " hypervisor is not used, so not failing upgrade"); |  | ||||||
|                         // Update the latest template URLs for corresponding |  | ||||||
|                         // hypervisor |  | ||||||
|                         try (PreparedStatement update_templ_url_pstmt = conn |  | ||||||
|                                 .prepareStatement("UPDATE `cloud`.`vm_template` SET url = ? , checksum = ? WHERE hypervisor_type = ? AND type = 'SYSTEM' AND removed is null order by id desc limit 1");) { |  | ||||||
|                             update_templ_url_pstmt.setString(1, newTemplateUrl.get(hypervisorAndTemplateName.getKey())); |  | ||||||
|                             update_templ_url_pstmt.setString(2, newTemplateChecksum.get(hypervisorAndTemplateName.getKey())); |  | ||||||
|                             update_templ_url_pstmt.setString(3, hypervisorAndTemplateName.getKey().toString()); |  | ||||||
|                             update_templ_url_pstmt.executeUpdate(); |  | ||||||
|                         } catch (final SQLException e) { |  | ||||||
|                             LOG.error("updateSystemVmTemplates:Exception while updating 'url' and 'checksum' for hypervisor type " |  | ||||||
|                                     + hypervisorAndTemplateName.getKey().toString() + ": " + e.getMessage()); |  | ||||||
|                             throw new CloudRuntimeException("updateSystemVmTemplates:Exception while updating 'url' and 'checksum' for hypervisor type " |  | ||||||
|                                     + hypervisorAndTemplateName.getKey().toString(), e); |  | ||||||
|                         } |  | ||||||
|                     } |  | ||||||
|                 } |  | ||||||
|             } catch (final SQLException e) { |  | ||||||
|                 LOG.error("updateSystemVmTemplates:Exception while getting ids of templates: " + e.getMessage()); |  | ||||||
|                 throw new CloudRuntimeException("updateSystemVmTemplates:Exception while getting ids of templates", e); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         LOG.debug("Updating System Vm Template IDs Complete"); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     private void addRolePermissionsForNewReadOnlyAndSupportRoles(final Connection conn) { |     private void addRolePermissionsForNewReadOnlyAndSupportRoles(final Connection conn) { | ||||||
|         addRolePermissionsForReadOnlyAdmin(conn); |         addRolePermissionsForReadOnlyAdmin(conn); | ||||||
|         addRolePermissionsForReadOnlyUser(conn); |         addRolePermissionsForReadOnlyUser(conn); | ||||||
|  | |||||||
| @ -19,12 +19,20 @@ package com.cloud.upgrade.dao; | |||||||
| 
 | 
 | ||||||
| import java.io.InputStream; | import java.io.InputStream; | ||||||
| import java.sql.Connection; | import java.sql.Connection; | ||||||
|  | import java.sql.PreparedStatement; | ||||||
|  | import java.sql.ResultSet; | ||||||
|  | import java.sql.SQLException; | ||||||
|  | import java.util.HashMap; | ||||||
|  | import java.util.HashSet; | ||||||
|  | import java.util.Map; | ||||||
|  | import java.util.Set; | ||||||
| 
 | 
 | ||||||
| import org.apache.log4j.Logger; | import org.apache.log4j.Logger; | ||||||
| 
 | 
 | ||||||
|  | import com.cloud.hypervisor.Hypervisor; | ||||||
| import com.cloud.utils.exception.CloudRuntimeException; | import com.cloud.utils.exception.CloudRuntimeException; | ||||||
| 
 | 
 | ||||||
| public class Upgrade41500to41510 implements DbUpgrade { | public class Upgrade41500to41510 implements DbUpgrade, DbUpgradeSystemVmTemplate { | ||||||
| 
 | 
 | ||||||
|     final static Logger LOG = Logger.getLogger(Upgrade41500to41510.class); |     final static Logger LOG = Logger.getLogger(Upgrade41500to41510.class); | ||||||
| 
 | 
 | ||||||
| @ -58,6 +66,175 @@ public class Upgrade41500to41510 implements DbUpgrade { | |||||||
|     public void performDataMigration(Connection conn) { |     public void performDataMigration(Connection conn) { | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     @Override | ||||||
|  |     @SuppressWarnings("serial") | ||||||
|  |     public void updateSystemVmTemplates(final Connection conn) { | ||||||
|  |         LOG.debug("Updating System Vm template IDs"); | ||||||
|  |         final Set<Hypervisor.HypervisorType> hypervisorsListInUse = new HashSet<Hypervisor.HypervisorType>(); | ||||||
|  |         try (PreparedStatement pstmt = conn.prepareStatement("select distinct(hypervisor_type) from `cloud`.`cluster` where removed is null"); ResultSet rs = pstmt.executeQuery()) { | ||||||
|  |             while (rs.next()) { | ||||||
|  |                 switch (Hypervisor.HypervisorType.getType(rs.getString(1))) { | ||||||
|  |                     case XenServer: | ||||||
|  |                         hypervisorsListInUse.add(Hypervisor.HypervisorType.XenServer); | ||||||
|  |                         break; | ||||||
|  |                     case KVM: | ||||||
|  |                         hypervisorsListInUse.add(Hypervisor.HypervisorType.KVM); | ||||||
|  |                         break; | ||||||
|  |                     case VMware: | ||||||
|  |                         hypervisorsListInUse.add(Hypervisor.HypervisorType.VMware); | ||||||
|  |                         break; | ||||||
|  |                     case Hyperv: | ||||||
|  |                         hypervisorsListInUse.add(Hypervisor.HypervisorType.Hyperv); | ||||||
|  |                         break; | ||||||
|  |                     case LXC: | ||||||
|  |                         hypervisorsListInUse.add(Hypervisor.HypervisorType.LXC); | ||||||
|  |                         break; | ||||||
|  |                     case Ovm3: | ||||||
|  |                         hypervisorsListInUse.add(Hypervisor.HypervisorType.Ovm3); | ||||||
|  |                         break; | ||||||
|  |                     default: | ||||||
|  |                         break; | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } catch (final SQLException e) { | ||||||
|  |             LOG.error("updateSystemVmTemplates: Exception caught while getting hypervisor types from clusters: " + e.getMessage()); | ||||||
|  |             throw new CloudRuntimeException("updateSystemVmTemplates:Exception while getting hypervisor types from clusters", e); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         final Map<Hypervisor.HypervisorType, String> NewTemplateNameList = new HashMap<Hypervisor.HypervisorType, String>() { | ||||||
|  |             { | ||||||
|  |                 put(Hypervisor.HypervisorType.KVM, "systemvm-kvm-4.15.1"); | ||||||
|  |                 put(Hypervisor.HypervisorType.VMware, "systemvm-vmware-4.15.1"); | ||||||
|  |                 put(Hypervisor.HypervisorType.XenServer, "systemvm-xenserver-4.15.1"); | ||||||
|  |                 put(Hypervisor.HypervisorType.Hyperv, "systemvm-hyperv-4.15.1"); | ||||||
|  |                 put(Hypervisor.HypervisorType.LXC, "systemvm-lxc-4.15.1"); | ||||||
|  |                 put(Hypervisor.HypervisorType.Ovm3, "systemvm-ovm3-4.15.1"); | ||||||
|  |             } | ||||||
|  |         }; | ||||||
|  | 
 | ||||||
|  |         final Map<Hypervisor.HypervisorType, String> routerTemplateConfigurationNames = new HashMap<Hypervisor.HypervisorType, String>() { | ||||||
|  |             { | ||||||
|  |                 put(Hypervisor.HypervisorType.KVM, "router.template.kvm"); | ||||||
|  |                 put(Hypervisor.HypervisorType.VMware, "router.template.vmware"); | ||||||
|  |                 put(Hypervisor.HypervisorType.XenServer, "router.template.xenserver"); | ||||||
|  |                 put(Hypervisor.HypervisorType.Hyperv, "router.template.hyperv"); | ||||||
|  |                 put(Hypervisor.HypervisorType.LXC, "router.template.lxc"); | ||||||
|  |                 put(Hypervisor.HypervisorType.Ovm3, "router.template.ovm3"); | ||||||
|  |             } | ||||||
|  |         }; | ||||||
|  | 
 | ||||||
|  |         final Map<Hypervisor.HypervisorType, String> newTemplateUrl = new HashMap<Hypervisor.HypervisorType, String>() { | ||||||
|  |             { | ||||||
|  |                 put(Hypervisor.HypervisorType.KVM, "https://download.cloudstack.org/systemvm/4.15/systemvmtemplate-4.15.1-kvm.qcow2.bz2"); | ||||||
|  |                 put(Hypervisor.HypervisorType.VMware, "https://download.cloudstack.org/systemvm/4.15/systemvmtemplate-4.15.1-vmware.ova"); | ||||||
|  |                 put(Hypervisor.HypervisorType.XenServer, "https://download.cloudstack.org/systemvm/4.15/systemvmtemplate-4.15.1-xen.vhd.bz2"); | ||||||
|  |                 put(Hypervisor.HypervisorType.Hyperv, "https://download.cloudstack.org/systemvm/4.15/systemvmtemplate-4.15.1-hyperv.vhd.zip"); | ||||||
|  |                 put(Hypervisor.HypervisorType.LXC, "https://download.cloudstack.org/systemvm/4.15/systemvmtemplate-4.15.1-kvm.qcow2.bz2"); | ||||||
|  |                 put(Hypervisor.HypervisorType.Ovm3, "https://download.cloudstack.org/systemvm/4.15/systemvmtemplate-4.15.1-ovm.raw.bz2"); | ||||||
|  |             } | ||||||
|  |         }; | ||||||
|  | 
 | ||||||
|  |         final Map<Hypervisor.HypervisorType, String> newTemplateChecksum = new HashMap<Hypervisor.HypervisorType, String>() { | ||||||
|  |             { | ||||||
|  |                 put(Hypervisor.HypervisorType.KVM, "0e9f9a7d0957c3e0a2088e41b2da2cec"); | ||||||
|  |                 put(Hypervisor.HypervisorType.XenServer, "86373992740b1eca8aff8b08ebf3aea5"); | ||||||
|  |                 put(Hypervisor.HypervisorType.VMware, "4006982765846d373eb3719b2fe4d720"); | ||||||
|  |                 put(Hypervisor.HypervisorType.Hyperv, "0b9514e4b6cba1f636fea2125f0f7a5f"); | ||||||
|  |                 put(Hypervisor.HypervisorType.LXC, "0e9f9a7d0957c3e0a2088e41b2da2cec"); | ||||||
|  |                 put(Hypervisor.HypervisorType.Ovm3, "ae3977e696b3e6c81bdcbb792d514d29"); | ||||||
|  |             } | ||||||
|  |         }; | ||||||
|  | 
 | ||||||
|  |         for (final Map.Entry<Hypervisor.HypervisorType, String> hypervisorAndTemplateName : NewTemplateNameList.entrySet()) { | ||||||
|  |             LOG.debug("Updating " + hypervisorAndTemplateName.getKey() + " System Vms"); | ||||||
|  |             try (PreparedStatement pstmt = conn.prepareStatement("select id from `cloud`.`vm_template` where name = ? and removed is null and account_id in (select id from account where type = 1 and removed is NULL) order by id desc limit 1")) { | ||||||
|  |                 // Get systemvm template id for corresponding hypervisor | ||||||
|  |                 long templateId = -1; | ||||||
|  |                 pstmt.setString(1, hypervisorAndTemplateName.getValue()); | ||||||
|  |                 try (ResultSet rs = pstmt.executeQuery()) { | ||||||
|  |                     if (rs.next()) { | ||||||
|  |                         templateId = rs.getLong(1); | ||||||
|  |                     } | ||||||
|  |                 } catch (final SQLException e) { | ||||||
|  |                     LOG.error("updateSystemVmTemplates: Exception caught while getting ids of templates: " + e.getMessage()); | ||||||
|  |                     throw new CloudRuntimeException("updateSystemVmTemplates: Exception caught while getting ids of templates", e); | ||||||
|  |                 } | ||||||
|  | 
 | ||||||
|  |                 // change template type to SYSTEM | ||||||
|  |                 if (templateId != -1) { | ||||||
|  |                     try (PreparedStatement templ_type_pstmt = conn.prepareStatement("update `cloud`.`vm_template` set type='SYSTEM' where id = ?");) { | ||||||
|  |                         templ_type_pstmt.setLong(1, templateId); | ||||||
|  |                         templ_type_pstmt.executeUpdate(); | ||||||
|  |                     } catch (final SQLException e) { | ||||||
|  |                         LOG.error("updateSystemVmTemplates:Exception while updating template with id " + templateId + " to be marked as 'system': " + e.getMessage()); | ||||||
|  |                         throw new CloudRuntimeException("updateSystemVmTemplates:Exception while updating template with id " + templateId + " to be marked as 'system'", e); | ||||||
|  |                     } | ||||||
|  |                     // update template ID of system Vms | ||||||
|  |                     try (PreparedStatement update_templ_id_pstmt = conn | ||||||
|  |                             .prepareStatement("update `cloud`.`vm_instance` set vm_template_id = ? where type <> 'User' and hypervisor_type = ? and removed is NULL");) { | ||||||
|  |                         update_templ_id_pstmt.setLong(1, templateId); | ||||||
|  |                         update_templ_id_pstmt.setString(2, hypervisorAndTemplateName.getKey().toString()); | ||||||
|  |                         update_templ_id_pstmt.executeUpdate(); | ||||||
|  |                     } catch (final Exception e) { | ||||||
|  |                         LOG.error("updateSystemVmTemplates:Exception while setting template for " + hypervisorAndTemplateName.getKey().toString() + " to " + templateId | ||||||
|  |                                 + ": " + e.getMessage()); | ||||||
|  |                         throw new CloudRuntimeException("updateSystemVmTemplates:Exception while setting template for " + hypervisorAndTemplateName.getKey().toString() + " to " | ||||||
|  |                                 + templateId, e); | ||||||
|  |                     } | ||||||
|  | 
 | ||||||
|  |                     // Change value of global configuration parameter | ||||||
|  |                     // router.template.* for the corresponding hypervisor | ||||||
|  |                     try (PreparedStatement update_pstmt = conn.prepareStatement("UPDATE `cloud`.`configuration` SET value = ? WHERE name = ?");) { | ||||||
|  |                         update_pstmt.setString(1, hypervisorAndTemplateName.getValue()); | ||||||
|  |                         update_pstmt.setString(2, routerTemplateConfigurationNames.get(hypervisorAndTemplateName.getKey())); | ||||||
|  |                         update_pstmt.executeUpdate(); | ||||||
|  |                     } catch (final SQLException e) { | ||||||
|  |                         LOG.error("updateSystemVmTemplates:Exception while setting " + routerTemplateConfigurationNames.get(hypervisorAndTemplateName.getKey()) + " to " | ||||||
|  |                                 + hypervisorAndTemplateName.getValue() + ": " + e.getMessage()); | ||||||
|  |                         throw new CloudRuntimeException("updateSystemVmTemplates:Exception while setting " | ||||||
|  |                                 + routerTemplateConfigurationNames.get(hypervisorAndTemplateName.getKey()) + " to " + hypervisorAndTemplateName.getValue(), e); | ||||||
|  |                     } | ||||||
|  | 
 | ||||||
|  |                     // Change value of global configuration parameter | ||||||
|  |                     // minreq.sysvmtemplate.version for the ACS version | ||||||
|  |                     try (PreparedStatement update_pstmt = conn.prepareStatement("UPDATE `cloud`.`configuration` SET value = ? WHERE name = ?");) { | ||||||
|  |                         update_pstmt.setString(1, "4.15.1"); | ||||||
|  |                         update_pstmt.setString(2, "minreq.sysvmtemplate.version"); | ||||||
|  |                         update_pstmt.executeUpdate(); | ||||||
|  |                     } catch (final SQLException e) { | ||||||
|  |                         LOG.error("updateSystemVmTemplates:Exception while setting 'minreq.sysvmtemplate.version' to 4.15.1: " + e.getMessage()); | ||||||
|  |                         throw new CloudRuntimeException("updateSystemVmTemplates:Exception while setting 'minreq.sysvmtemplate.version' to 4.15.1", e); | ||||||
|  |                     } | ||||||
|  |                 } else { | ||||||
|  |                     if (hypervisorsListInUse.contains(hypervisorAndTemplateName.getKey())) { | ||||||
|  |                         throw new CloudRuntimeException(getUpgradedVersion() + hypervisorAndTemplateName.getKey() + " SystemVm template not found. Cannot upgrade system Vms"); | ||||||
|  |                     } else { | ||||||
|  |                         LOG.warn(getUpgradedVersion() + hypervisorAndTemplateName.getKey() + " SystemVm template not found. " + hypervisorAndTemplateName.getKey() | ||||||
|  |                                 + " hypervisor is not used, so not failing upgrade"); | ||||||
|  |                         // Update the latest template URLs for corresponding | ||||||
|  |                         // hypervisor | ||||||
|  |                         try (PreparedStatement update_templ_url_pstmt = conn | ||||||
|  |                                 .prepareStatement("UPDATE `cloud`.`vm_template` SET url = ? , checksum = ? WHERE hypervisor_type = ? AND type = 'SYSTEM' AND removed is null order by id desc limit 1");) { | ||||||
|  |                             update_templ_url_pstmt.setString(1, newTemplateUrl.get(hypervisorAndTemplateName.getKey())); | ||||||
|  |                             update_templ_url_pstmt.setString(2, newTemplateChecksum.get(hypervisorAndTemplateName.getKey())); | ||||||
|  |                             update_templ_url_pstmt.setString(3, hypervisorAndTemplateName.getKey().toString()); | ||||||
|  |                             update_templ_url_pstmt.executeUpdate(); | ||||||
|  |                         } catch (final SQLException e) { | ||||||
|  |                             LOG.error("updateSystemVmTemplates:Exception while updating 'url' and 'checksum' for hypervisor type " | ||||||
|  |                                     + hypervisorAndTemplateName.getKey().toString() + ": " + e.getMessage()); | ||||||
|  |                             throw new CloudRuntimeException("updateSystemVmTemplates:Exception while updating 'url' and 'checksum' for hypervisor type " | ||||||
|  |                                     + hypervisorAndTemplateName.getKey().toString(), e); | ||||||
|  |                         } | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |             } catch (final SQLException e) { | ||||||
|  |                 LOG.error("updateSystemVmTemplates:Exception while getting ids of templates: " + e.getMessage()); | ||||||
|  |                 throw new CloudRuntimeException("updateSystemVmTemplates:Exception while getting ids of templates", e); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         LOG.debug("Updating System Vm Template IDs Complete"); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     @Override |     @Override | ||||||
|     public InputStream[] getCleanupScripts() { |     public InputStream[] getCleanupScripts() { | ||||||
|         final String scriptFile = "META-INF/db/schema-41500to41510-cleanup.sql"; |         final String scriptFile = "META-INF/db/schema-41500to41510-cleanup.sql"; | ||||||
|  | |||||||
| @ -19,7 +19,7 @@ | |||||||
| set -e | set -e | ||||||
| set -x | set -x | ||||||
| 
 | 
 | ||||||
| CLOUDSTACK_RELEASE=4.15.0 | CLOUDSTACK_RELEASE=4.15.1 | ||||||
| 
 | 
 | ||||||
| function configure_apache2() { | function configure_apache2() { | ||||||
|    # Enable ssl, rewrite and auth |    # Enable ssl, rewrite and auth | ||||||
|  | |||||||
| @ -36,8 +36,8 @@ | |||||||
|       "disk_size": 2500, |       "disk_size": 2500, | ||||||
|       "disk_interface": "virtio", |       "disk_interface": "virtio", | ||||||
|       "net_device": "virtio-net", |       "net_device": "virtio-net", | ||||||
|       "iso_url": "https://download.cloudstack.org/systemvm/debian/debian-10.5.0-amd64-netinst.iso", |       "iso_url": "https://cdimage.debian.org/debian-cd/10.8.0/amd64/iso-cd/debian-10.8.0-amd64-netinst.iso", | ||||||
|       "iso_checksum": "0a6aee1d9aafc1ed095105c052f9fdd65ed00ea9274188c9cd0072c8e6838ab40e246d45a1e6956d74ef1b04a1fc042151762f25412e9ff0cbf49418eef7992e", |       "iso_checksum": "934336d266535c91fcd12cd122c81f8261721efa117fdcb9a31615caa96c5c5ce3454ed5f28f1b25a7b1b5f44631fdfa78a93adb6445e2e2caaf6455ab344cf8", | ||||||
|       "iso_checksum_type": "sha512", |       "iso_checksum_type": "sha512", | ||||||
|       "output_directory": "../dist", |       "output_directory": "../dist", | ||||||
|       "http_directory": "http", |       "http_directory": "http", | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user