Skip to content

Commit 9b1d1e6

Browse files
yadvrPearl Dsilva
andauthored
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>
1 parent 5df1337 commit 9b1d1e6

4 files changed

Lines changed: 182 additions & 178 deletions

File tree

engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41400to41500.java

Lines changed: 1 addition & 174 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,15 @@
2323
import java.sql.ResultSet;
2424
import java.sql.SQLException;
2525
import java.util.ArrayList;
26-
import java.util.HashMap;
27-
import java.util.HashSet;
2826
import java.util.LinkedHashMap;
2927
import java.util.List;
3028
import java.util.Map;
31-
import java.util.Set;
3229

3330
import org.apache.log4j.Logger;
3431

35-
import com.cloud.hypervisor.Hypervisor;
3632
import com.cloud.utils.exception.CloudRuntimeException;
3733

38-
public class Upgrade41400to41500 implements DbUpgrade, DbUpgradeSystemVmTemplate {
34+
public class Upgrade41400to41500 implements DbUpgrade {
3935

4036
final static Logger LOG = Logger.getLogger(Upgrade41400to41500.class);
4137

@@ -70,175 +66,6 @@ public void performDataMigration(Connection conn) {
7066
addRolePermissionsForNewReadOnlyAndSupportRoles(conn);
7167
}
7268

73-
@Override
74-
@SuppressWarnings("serial")
75-
public void updateSystemVmTemplates(final Connection conn) {
76-
LOG.debug("Updating System Vm template IDs");
77-
final Set<Hypervisor.HypervisorType> hypervisorsListInUse = new HashSet<Hypervisor.HypervisorType>();
78-
try (PreparedStatement pstmt = conn.prepareStatement("select distinct(hypervisor_type) from `cloud`.`cluster` where removed is null"); ResultSet rs = pstmt.executeQuery()) {
79-
while (rs.next()) {
80-
switch (Hypervisor.HypervisorType.getType(rs.getString(1))) {
81-
case XenServer:
82-
hypervisorsListInUse.add(Hypervisor.HypervisorType.XenServer);
83-
break;
84-
case KVM:
85-
hypervisorsListInUse.add(Hypervisor.HypervisorType.KVM);
86-
break;
87-
case VMware:
88-
hypervisorsListInUse.add(Hypervisor.HypervisorType.VMware);
89-
break;
90-
case Hyperv:
91-
hypervisorsListInUse.add(Hypervisor.HypervisorType.Hyperv);
92-
break;
93-
case LXC:
94-
hypervisorsListInUse.add(Hypervisor.HypervisorType.LXC);
95-
break;
96-
case Ovm3:
97-
hypervisorsListInUse.add(Hypervisor.HypervisorType.Ovm3);
98-
break;
99-
default:
100-
break;
101-
}
102-
}
103-
} catch (final SQLException e) {
104-
LOG.error("updateSystemVmTemplates: Exception caught while getting hypervisor types from clusters: " + e.getMessage());
105-
throw new CloudRuntimeException("updateSystemVmTemplates:Exception while getting hypervisor types from clusters", e);
106-
}
107-
108-
final Map<Hypervisor.HypervisorType, String> NewTemplateNameList = new HashMap<Hypervisor.HypervisorType, String>() {
109-
{
110-
put(Hypervisor.HypervisorType.KVM, "systemvm-kvm-4.15.0");
111-
put(Hypervisor.HypervisorType.VMware, "systemvm-vmware-4.15.0");
112-
put(Hypervisor.HypervisorType.XenServer, "systemvm-xenserver-4.15.0");
113-
put(Hypervisor.HypervisorType.Hyperv, "systemvm-hyperv-4.15.0");
114-
put(Hypervisor.HypervisorType.LXC, "systemvm-lxc-4.15.0");
115-
put(Hypervisor.HypervisorType.Ovm3, "systemvm-ovm3-4.15.0");
116-
}
117-
};
118-
119-
final Map<Hypervisor.HypervisorType, String> routerTemplateConfigurationNames = new HashMap<Hypervisor.HypervisorType, String>() {
120-
{
121-
put(Hypervisor.HypervisorType.KVM, "router.template.kvm");
122-
put(Hypervisor.HypervisorType.VMware, "router.template.vmware");
123-
put(Hypervisor.HypervisorType.XenServer, "router.template.xenserver");
124-
put(Hypervisor.HypervisorType.Hyperv, "router.template.hyperv");
125-
put(Hypervisor.HypervisorType.LXC, "router.template.lxc");
126-
put(Hypervisor.HypervisorType.Ovm3, "router.template.ovm3");
127-
}
128-
};
129-
130-
final Map<Hypervisor.HypervisorType, String> newTemplateUrl = new HashMap<Hypervisor.HypervisorType, String>() {
131-
{
132-
put(Hypervisor.HypervisorType.KVM, "https://download.cloudstack.org/systemvm/4.15/systemvmtemplate-4.15.0-kvm.qcow2.bz2");
133-
put(Hypervisor.HypervisorType.VMware, "https://download.cloudstack.org/systemvm/4.15/systemvmtemplate-4.15.0-vmware.ova");
134-
put(Hypervisor.HypervisorType.XenServer, "https://download.cloudstack.org/systemvm/4.15/systemvmtemplate-4.15.0-xen.vhd.bz2");
135-
put(Hypervisor.HypervisorType.Hyperv, "https://download.cloudstack.org/systemvm/4.15/systemvmtemplate-4.15.0-hyperv.vhd.zip");
136-
put(Hypervisor.HypervisorType.LXC, "https://download.cloudstack.org/systemvm/4.15/systemvmtemplate-4.15.0-kvm.qcow2.bz2");
137-
put(Hypervisor.HypervisorType.Ovm3, "https://download.cloudstack.org/systemvm/4.15/systemvmtemplate-4.15.0-ovm.raw.bz2");
138-
}
139-
};
140-
141-
final Map<Hypervisor.HypervisorType, String> newTemplateChecksum = new HashMap<Hypervisor.HypervisorType, String>() {
142-
{
143-
put(Hypervisor.HypervisorType.KVM, "81b3e48bb934784a13555a43c5ef5ffb");
144-
put(Hypervisor.HypervisorType.XenServer, "1b178a5dbdbe090555515340144c6017");
145-
put(Hypervisor.HypervisorType.VMware, "e6a88e518c57d6f36c096c4204c3417f");
146-
put(Hypervisor.HypervisorType.Hyperv, "5c94da45337cf3e1910dcbe084d4b9ad");
147-
put(Hypervisor.HypervisorType.LXC, "81b3e48bb934784a13555a43c5ef5ffb");
148-
put(Hypervisor.HypervisorType.Ovm3, "875c5c65455fc06c4a012394410db375");
149-
}
150-
};
151-
152-
for (final Map.Entry<Hypervisor.HypervisorType, String> hypervisorAndTemplateName : NewTemplateNameList.entrySet()) {
153-
LOG.debug("Updating " + hypervisorAndTemplateName.getKey() + " System Vms");
154-
try (PreparedStatement pstmt = conn.prepareStatement("select id from `cloud`.`vm_template` where name = ? and removed is null order by id desc limit 1")) {
155-
// Get systemvm template id for corresponding hypervisor
156-
long templateId = -1;
157-
pstmt.setString(1, hypervisorAndTemplateName.getValue());
158-
try (ResultSet rs = pstmt.executeQuery()) {
159-
if (rs.next()) {
160-
templateId = rs.getLong(1);
161-
}
162-
} catch (final SQLException e) {
163-
LOG.error("updateSystemVmTemplates: Exception caught while getting ids of templates: " + e.getMessage());
164-
throw new CloudRuntimeException("updateSystemVmTemplates: Exception caught while getting ids of templates", e);
165-
}
166-
167-
// change template type to SYSTEM
168-
if (templateId != -1) {
169-
try (PreparedStatement templ_type_pstmt = conn.prepareStatement("update `cloud`.`vm_template` set type='SYSTEM' where id = ?");) {
170-
templ_type_pstmt.setLong(1, templateId);
171-
templ_type_pstmt.executeUpdate();
172-
} catch (final SQLException e) {
173-
LOG.error("updateSystemVmTemplates:Exception while updating template with id " + templateId + " to be marked as 'system': " + e.getMessage());
174-
throw new CloudRuntimeException("updateSystemVmTemplates:Exception while updating template with id " + templateId + " to be marked as 'system'", e);
175-
}
176-
// update template ID of system Vms
177-
try (PreparedStatement update_templ_id_pstmt = conn
178-
.prepareStatement("update `cloud`.`vm_instance` set vm_template_id = ? where type <> 'User' and hypervisor_type = ? and removed is NULL");) {
179-
update_templ_id_pstmt.setLong(1, templateId);
180-
update_templ_id_pstmt.setString(2, hypervisorAndTemplateName.getKey().toString());
181-
update_templ_id_pstmt.executeUpdate();
182-
} catch (final Exception e) {
183-
LOG.error("updateSystemVmTemplates:Exception while setting template for " + hypervisorAndTemplateName.getKey().toString() + " to " + templateId
184-
+ ": " + e.getMessage());
185-
throw new CloudRuntimeException("updateSystemVmTemplates:Exception while setting template for " + hypervisorAndTemplateName.getKey().toString() + " to "
186-
+ templateId, e);
187-
}
188-
189-
// Change value of global configuration parameter
190-
// router.template.* for the corresponding hypervisor
191-
try (PreparedStatement update_pstmt = conn.prepareStatement("UPDATE `cloud`.`configuration` SET value = ? WHERE name = ?");) {
192-
update_pstmt.setString(1, hypervisorAndTemplateName.getValue());
193-
update_pstmt.setString(2, routerTemplateConfigurationNames.get(hypervisorAndTemplateName.getKey()));
194-
update_pstmt.executeUpdate();
195-
} catch (final SQLException e) {
196-
LOG.error("updateSystemVmTemplates:Exception while setting " + routerTemplateConfigurationNames.get(hypervisorAndTemplateName.getKey()) + " to "
197-
+ hypervisorAndTemplateName.getValue() + ": " + e.getMessage());
198-
throw new CloudRuntimeException("updateSystemVmTemplates:Exception while setting "
199-
+ routerTemplateConfigurationNames.get(hypervisorAndTemplateName.getKey()) + " to " + hypervisorAndTemplateName.getValue(), e);
200-
}
201-
202-
// Change value of global configuration parameter
203-
// minreq.sysvmtemplate.version for the ACS version
204-
try (PreparedStatement update_pstmt = conn.prepareStatement("UPDATE `cloud`.`configuration` SET value = ? WHERE name = ?");) {
205-
update_pstmt.setString(1, "4.15.0");
206-
update_pstmt.setString(2, "minreq.sysvmtemplate.version");
207-
update_pstmt.executeUpdate();
208-
} catch (final SQLException e) {
209-
LOG.error("updateSystemVmTemplates:Exception while setting 'minreq.sysvmtemplate.version' to 4.15.0: " + e.getMessage());
210-
throw new CloudRuntimeException("updateSystemVmTemplates:Exception while setting 'minreq.sysvmtemplate.version' to 4.15.0", e);
211-
}
212-
} else {
213-
if (hypervisorsListInUse.contains(hypervisorAndTemplateName.getKey())) {
214-
throw new CloudRuntimeException(getUpgradedVersion() + hypervisorAndTemplateName.getKey() + " SystemVm template not found. Cannot upgrade system Vms");
215-
} else {
216-
LOG.warn(getUpgradedVersion() + hypervisorAndTemplateName.getKey() + " SystemVm template not found. " + hypervisorAndTemplateName.getKey()
217-
+ " hypervisor is not used, so not failing upgrade");
218-
// Update the latest template URLs for corresponding
219-
// hypervisor
220-
try (PreparedStatement update_templ_url_pstmt = conn
221-
.prepareStatement("UPDATE `cloud`.`vm_template` SET url = ? , checksum = ? WHERE hypervisor_type = ? AND type = 'SYSTEM' AND removed is null order by id desc limit 1");) {
222-
update_templ_url_pstmt.setString(1, newTemplateUrl.get(hypervisorAndTemplateName.getKey()));
223-
update_templ_url_pstmt.setString(2, newTemplateChecksum.get(hypervisorAndTemplateName.getKey()));
224-
update_templ_url_pstmt.setString(3, hypervisorAndTemplateName.getKey().toString());
225-
update_templ_url_pstmt.executeUpdate();
226-
} catch (final SQLException e) {
227-
LOG.error("updateSystemVmTemplates:Exception while updating 'url' and 'checksum' for hypervisor type "
228-
+ hypervisorAndTemplateName.getKey().toString() + ": " + e.getMessage());
229-
throw new CloudRuntimeException("updateSystemVmTemplates:Exception while updating 'url' and 'checksum' for hypervisor type "
230-
+ hypervisorAndTemplateName.getKey().toString(), e);
231-
}
232-
}
233-
}
234-
} catch (final SQLException e) {
235-
LOG.error("updateSystemVmTemplates:Exception while getting ids of templates: " + e.getMessage());
236-
throw new CloudRuntimeException("updateSystemVmTemplates:Exception while getting ids of templates", e);
237-
}
238-
}
239-
LOG.debug("Updating System Vm Template IDs Complete");
240-
}
241-
24269
private void addRolePermissionsForNewReadOnlyAndSupportRoles(final Connection conn) {
24370
addRolePermissionsForReadOnlyAdmin(conn);
24471
addRolePermissionsForReadOnlyUser(conn);

0 commit comments

Comments
 (0)