Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,14 @@
import com.cloud.dc.dao.DataCenterDaoImpl;
import com.cloud.hypervisor.Hypervisor;
import com.cloud.storage.DataStoreRole;
import com.cloud.storage.GuestOSVO;
import com.cloud.storage.Storage;
import com.cloud.storage.Storage.ImageFormat;
import com.cloud.storage.VMTemplateStorageResourceAssoc;
import com.cloud.storage.VMTemplateVO;
import com.cloud.storage.VMTemplateZoneVO;
import com.cloud.storage.dao.GuestOSDao;
import com.cloud.storage.dao.GuestOSDaoImpl;
import com.cloud.storage.dao.VMTemplateDao;
import com.cloud.storage.dao.VMTemplateDaoImpl;
import com.cloud.storage.dao.VMTemplateZoneDao;
Expand Down Expand Up @@ -102,15 +105,14 @@ public class SystemVmTemplateRegistration {
private static final String PARTIAL_TEMPLATE_FOLDER = String.format("/template/tmpl/%d/", Account.ACCOUNT_ID_SYSTEM);
private static final String storageScriptsDir = "scripts/storage/secondary";
private static final Integer OTHER_LINUX_ID = 99;
private static final Integer LINUX_5_ID = 15;
private static Integer LINUX_12_ID = 363;
private static final Integer LINUX_7_ID = 183;
private static final Integer SCRIPT_TIMEOUT = 1800000;
private static final Integer LOCK_WAIT_TIMEOUT = 1200;
protected static final List<CPU.CPUArch> DOWNLOADABLE_TEMPLATE_ARCH_TYPES = Arrays.asList(
CPU.CPUArch.arm64
);


public static String CS_MAJOR_VERSION = null;
public static String CS_TINY_VERSION = null;

Expand All @@ -132,6 +134,8 @@ public class SystemVmTemplateRegistration {
ClusterDao clusterDao;
@Inject
ConfigurationDao configurationDao;
@Inject
private GuestOSDao guestOSDao;

private String systemVmTemplateVersion;

Expand All @@ -147,6 +151,7 @@ public SystemVmTemplateRegistration() {
imageStoreDetailsDao = new ImageStoreDetailsDaoImpl();
clusterDao = new ClusterDaoImpl();
configurationDao = new ConfigurationDaoImpl();
guestOSDao = new GuestOSDaoImpl();
tempDownloadDir = new File(System.getProperty("java.io.tmpdir"));
}

Expand Down Expand Up @@ -331,13 +336,13 @@ public void setUpdated(Date updated) {
}
};

public static final Map<Hypervisor.HypervisorType, Integer> hypervisorGuestOsMap = new HashMap<Hypervisor.HypervisorType, Integer>() {
public static Map<Hypervisor.HypervisorType, Integer> hypervisorGuestOsMap = new HashMap<Hypervisor.HypervisorType, Integer>() {
{
put(Hypervisor.HypervisorType.KVM, LINUX_5_ID);
put(Hypervisor.HypervisorType.KVM, LINUX_12_ID);
put(Hypervisor.HypervisorType.XenServer, OTHER_LINUX_ID);
put(Hypervisor.HypervisorType.VMware, OTHER_LINUX_ID);
put(Hypervisor.HypervisorType.Hyperv, LINUX_5_ID);
put(Hypervisor.HypervisorType.LXC, LINUX_5_ID);
put(Hypervisor.HypervisorType.Hyperv, LINUX_12_ID);
put(Hypervisor.HypervisorType.LXC, LINUX_12_ID);
put(Hypervisor.HypervisorType.Ovm3, LINUX_7_ID);
}
};
Expand Down Expand Up @@ -595,6 +600,18 @@ public void updateSystemVMEntries(Long templateId, Hypervisor.HypervisorType hyp
vmInstanceDao.updateSystemVmTemplateId(templateId, hypervisorType);
}

public void updateSystemVmTemplateGuestOsId() {
String systemVmGuestOsName = "Debian GNU/Linux 12 (64-bit)";
GuestOSVO guestOS = guestOSDao.findOneByDisplayName(systemVmGuestOsName);
if (guestOS != null) {
LOGGER.debug("Updating SystemVM Template Guest OS [{}] id", systemVmGuestOsName);
SystemVmTemplateRegistration.LINUX_12_ID = Math.toIntExact(guestOS.getId());
hypervisorGuestOsMap.put(Hypervisor.HypervisorType.KVM, LINUX_12_ID);
hypervisorGuestOsMap.put(Hypervisor.HypervisorType.Hyperv, LINUX_12_ID);
hypervisorGuestOsMap.put(Hypervisor.HypervisorType.LXC, LINUX_12_ID);
}
}

public void updateConfigurationParams(Map<String, String> configParams) {
for (Map.Entry<String, String> config : configParams.entrySet()) {
boolean updated = configurationDao.update(config.getKey(), config.getValue());
Expand Down Expand Up @@ -731,6 +748,7 @@ public void registerTemplateForNonExistingEntries(Hypervisor.HypervisorType hype
Long templateId = null;
try {
MetadataTemplateDetails templateDetails = getMetadataTemplateDetails(hypervisor, arch);
updateSystemVmTemplateGuestOsId();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @sureshanaparti , could you please explain the reason for this? Wouldn't https://github.com/apache/cloudstack/pull/11291/files#diff-a9c9a38684718059c060de404bf9529de96e502f1e81b30793e6a32f725042a9R339 already handle it? I'm probably missing something.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

guest os id for debian 5 is hardcoded to 15 (very old entries), later user is allowed to add guest os and there are no hardcoded ids. if there are no user guest os added, the default id for debian 12 would be 363. this call will update the guest os id before registering the non existing systemvm templates. Moved this call to updateSystemVmTemplates().

update `cloud`.`guest_os` set display_name = 'Debian GNU/Linux 5.0 (32-bit)' where id=15;

INSERT INTO `cloud`.`vm_template` (id, unique_name, name, public, created, type, hvm, bits, account_id, url, checksum, enable_password, display_text, format, guest_os_id, featured, cross_zones, hypervisor_type)
VALUES (3, 'routing-3', 'SystemVM Template (KVM)', 0, now(), 'SYSTEM', 0, 64, 1, 'http://download.cloudstack.org/releases/2.2.0/systemvm.qcow2.bz2', 'ec463e677054f280f152fcc264255d2f', 0, 'SystemVM Template (KVM)', 'QCOW2', 15, 0, 1, 'KVM');

mysql> SELECT * FROM cloud.guest_os WHERE display_name = 'Debian GNU/Linux 12 (64-bit)';
+-----+-------------+------+--------------------------------------+------------------------------+---------------------+---------+-----------------+---------+
| id  | category_id | name | uuid                                 | display_name                 | created             | removed | is_user_defined | display |
+-----+-------------+------+--------------------------------------+------------------------------+---------------------+---------+-----------------+---------+
| 363 |           2 | NULL | 565d58aa-ade8-468d-a829-036e73f11961 | Debian GNU/Linux 12 (64-bit) | 2025-07-28 15:13:07 | NULL    |               0 |       1 |
+-----+-------------+------+--------------------------------------+------------------------------+---------------------+---------+-----------------+---------+
1 row in set (0.00 sec)

templateId = performTemplateRegistrationOperations(hypervisor, name,
templateDetails.getArch(), templateDetails.getUrl(),
templateDetails.getChecksum(), hypervisorImageFormat.get(hypervisor),
Expand Down
Loading