Skip to content

Multiple CD-ROM / ISO Support Per VM#13101

Draft
Damans227 wants to merge 20 commits intoapache:mainfrom
Damans227:fr283-multi-cdrom
Draft

Multiple CD-ROM / ISO Support Per VM#13101
Damans227 wants to merge 20 commits intoapache:mainfrom
Damans227:fr283-multi-cdrom

Conversation

@Damans227
Copy link
Copy Markdown
Collaborator

@Damans227 Damans227 commented May 4, 2026

Description

Adds multiple CD-ROM support per VM on KVM. Today CloudStack allows only one ISO per VM, forcing a manual ISO-swap workflow to install Windows on KVM (Windows installer + VirtIO drivers). After this PR each VM can hold up to vm.cdrom.max.count ISOs simultaneously, each appearing as its own CD-ROM inside the guest.

What changes:

  • detachIso takes an optional id (required when multiple ISOs are attached).
  • listVirtualMachines returns isos[]; legacy isoid still reflects the bootable ISO.
  • New global config vm.cdrom.max.count (default 1), clamped by the hypervisor cap (KVM/IDE = 2).
  • New vm_iso_map table holds extra slots; user_vm.iso_id is kept as the bootable pointer for back-compat.

Scope: KVM only.

Design doc: https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=421957739

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • Build/CI
  • Test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Screenshots (if appropriate):

Screen.Recording.2026-05-04.at.5.20.18.PM.mov

How Has This Been Tested?

  • End-to-end on a KVM lab across cap=1/2/5, plus the UI manually.
  • Unit tests added in TemplateManagerImplTest for slot allocation, the duplicate-attach check, and the detach-id resolution helper.

How did you try to break this feature and the system with this change?

  • Set the global cap both lower and higher than the hypervisor's actual capacity to confirm clamping
  • Tried to re-attach an already-attached ISO
  • Detached the bootable and non-bootable ISO in turn to confirm user_vm.iso_id and vm_iso_map stay in sync
  • Stopped and restarted a multi-ISO VM to confirm boot-time persistence
  • Confirmed legacy single-ISO API consumers (isoid in listVirtualMachines) see no functional change

@codecov
Copy link
Copy Markdown

codecov Bot commented May 4, 2026

Codecov Report

❌ Patch coverage is 20.98765% with 192 lines in your changes missing coverage. Please review.
✅ Project coverage is 18.08%. Comparing base (1e512ab) to head (61396a1).

Files with missing lines Patch % Lines
...n/java/com/cloud/template/TemplateManagerImpl.java 27.20% 91 Missing and 8 partials ⚠️
...rc/main/java/com/cloud/vm/dao/VmIsoMapDaoImpl.java 0.00% 36 Missing ⚠️
...e/cloudstack/api/response/AttachedIsoResponse.java 0.00% 21 Missing ⚠️
.../schema/src/main/java/com/cloud/vm/VmIsoMapVO.java 37.50% 15 Missing ⚠️
...ava/com/cloud/api/query/dao/UserVmJoinDaoImpl.java 18.18% 7 Missing and 2 partials ⚠️
...ud/hypervisor/kvm/storage/KVMStorageProcessor.java 0.00% 7 Missing ⚠️
...apache/cloudstack/api/response/UserVmResponse.java 33.33% 4 Missing ⚠️
.../cloudstack/api/command/user/iso/DetachIsoCmd.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main   #13101      +/-   ##
============================================
- Coverage     18.08%   18.08%   -0.01%     
- Complexity    16706    16722      +16     
============================================
  Files          6037     6041       +4     
  Lines        542437   542707     +270     
  Branches      66420    66471      +51     
============================================
+ Hits          98088    98126      +38     
- Misses       433333   433554     +221     
- Partials      11016    11027      +11     
Flag Coverage Δ
uitests 3.52% <ø> (+<0.01%) ⬆️
unittests 19.24% <20.98%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Damans227
Copy link
Copy Markdown
Collaborator Author

@blueorangutan package

@blueorangutan
Copy link
Copy Markdown

@Damans227 a [SL] Jenkins job has been kicked to build packages. It will be bundled with no SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan
Copy link
Copy Markdown

Packaging result [SF]: ✖️ el8 ✖️ el9 ✖️ debian ✖️ suse15. SL-JID 17708

@Damans227
Copy link
Copy Markdown
Collaborator Author

@blueorangutan package

@blueorangutan
Copy link
Copy Markdown

@Damans227 a [SL] Jenkins job has been kicked to build packages. It will be bundled with no SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan
Copy link
Copy Markdown

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 17709

@sureshanaparti
Copy link
Copy Markdown
Contributor

@blueorangutan package

@sureshanaparti sureshanaparti added this to the 4.23.0 milestone May 5, 2026
@blueorangutan
Copy link
Copy Markdown

@sureshanaparti a [SL] Jenkins job has been kicked to build packages. It will be bundled with no SystemVM templates. I'll keep you posted as I make progress.

Copy link
Copy Markdown
Member

@harikrishna-patnala harikrishna-patnala left a comment

Choose a reason for hiding this comment

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

nice work @Damans227 I've added few comments, can you please check them

protected Boolean forced;

@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = TemplateResponse.class,
description = "The ID of the ISO to detach. Required when the Instance has more than one ISO attached.")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
description = "The ID of the ISO to detach. Required when the Instance has more than one ISO attached.")
description = "The ID of the ISO to detach. Required when the Instance has more than one ISO attached.", since = "4.23.0")

"vm.cdrom.max.count", "1",
"Maximum number of CD-ROM drives per VM.",
true,
ConfigKey.Scope.Global);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

as this is the hypervisor dependent, is it better to keep the scope as Cluster ?

If you are making this change, please update the getters of this config to read from clusterId

private int effectiveMaxCdroms(VirtualMachine vm) {
int globalCap = VmCdromMaxCount.value();
// hda is root on i440fx/IDE, leaving hdc/hdd available for cdroms.
int hypervisorCap = (vm.getHypervisorType() == HypervisorType.KVM) ? 2 : 1;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Instead of hardcoding these numbers, is there a way to fetch from the hypervisor ?

and I feel even if there is no way to fetch from hypervisor, we can still do a check if the config value is more than expected value (2 for KVM and 1 for others) and log an error message and let the operation fail.

I'm just thinking if in future if hypervisor increases the supported value we dont have do any code changes.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds support for attaching multiple ISOs (multiple CD-ROM devices) to a single VM on KVM, enabling workflows like Windows install + VirtIO drivers without ISO swapping, while keeping legacy single-ISO semantics (user_vm.iso_id, isoid) for backward compatibility.

Changes:

  • Introduces vm_iso_map to persist additional ISO slots per VM and adds global cap vm.cdrom.max.count (clamped by hypervisor).
  • Extends VM responses with isos[] (slot-aware) and updates UI to display/attach/detach multiple ISOs.
  • Updates KVM ISO attach/detach path to honor a target CD-ROM slot via diskSeq/deviceSeq, plus adds unit test coverage for new slot/validation helpers.

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
ui/src/views/compute/InstanceTab.vue Display all attached ISOs and show slot labels in the VM details view.
ui/src/views/compute/AttachIso.vue Allow multi-select attach, enforce slot cap in UI, and fan out attachIso calls.
ui/src/views/compute/DetachIso.vue New multi-select detach UI and fan out detachIso calls (with optional id).
ui/src/config/section/compute.js Update VM action availability logic for attach/detach ISO with multi-ISO awareness.
api/src/main/java/org/apache/cloudstack/api/command/user/iso/DetachIsoCmd.java Add optional id parameter to disambiguate detach when multiple ISOs are attached.
api/src/main/java/org/apache/cloudstack/api/response/UserVmResponse.java Add isos[] response field for all attached ISOs.
api/src/main/java/org/apache/cloudstack/api/response/AttachedIsoResponse.java New response object representing an attached ISO + slot (deviceseq).
server/src/main/java/com/cloud/api/query/dao/UserVmJoinDaoImpl.java Populate isos[] in VM responses using vm_iso_map.
server/src/main/java/com/cloud/template/TemplateManagerImpl.java Persist extra ISO slots, enforce caps/duplicate attach, pre-allocate CD-ROM drives at boot, and resolve detach id.
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java Pass CD-ROM slot down to libvirt ISO attach/detach operations.
engine/schema/src/main/resources/META-INF/db/schema-42210to42300.sql Add vm_iso_map table for extra ISO attachments.
engine/schema/src/main/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml Wire the new VmIsoMapDaoImpl bean.
engine/schema/src/main/java/com/cloud/vm/VmIsoMapVO.java New VO for vm_iso_map.
engine/schema/src/main/java/com/cloud/vm/dao/VmIsoMapDao.java New DAO interface for ISO map operations.
engine/schema/src/main/java/com/cloud/vm/dao/VmIsoMapDaoImpl.java DAO implementation with lookups by VM/ISO/slot.
engine/components-api/src/main/java/com/cloud/template/TemplateManager.java Add vm.cdrom.max.count config and CDROM_PRIMARY_DEVICE_SEQ constant.
server/src/test/java/com/cloud/template/TemplateManagerImplTest.java Add unit tests for slot allocation, detach-id resolution, and duplicate attach detection.
server/src/test/java/com/cloud/api/query/dao/UserVmJoinDaoImplTest.java Stub vmIsoMapDao for new isos[] response population path.
Comments suppressed due to low confidence (1)

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java:1221

  • When detaching an ISO, attachOrDetachISO currently calls cleanupDisk for all CDROM devices on the VM. With multi-ISO support, this risks disconnecting the backing storage for other still-attached ISOs when only one is being detached. Consider restricting cleanup to the CDROM matching the requested deviceSeq/disk label (similar to the filtering used in LibvirtComputingResource.attachOrDetachISO).
        final List<DiskDef> disks = resource.getDisks(conn, vmName);
        attachOrDetachDevice(conn, true, vmName, iso);
        if (!isAttach) {
            for (final DiskDef disk : disks) {
                if (disk.getDeviceType() == DiskDef.DeviceType.CDROM) {
                    resource.cleanupDisk(disk);
                }
            }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +687 to +688
Long poolId = singleStoragePoolId(dest);
Map<Integer, Long> slotToIsoId = loadAttachedIsoSlots(vm);
Comment on lines +1538 to +1546
private void enforceCdromAttachLimits(long vmId, UserVm vm, long isoId) {
Long primaryIsoId = vm.getIsoId();
if (isIsoAlreadyAttached(vmId, primaryIsoId, isoId)) {
throw new InvalidParameterValueException("The specified ISO is already attached to this Instance.");
}
int effectiveMax = effectiveMaxCdroms(vm);
int attached = (primaryIsoId != null ? 1 : 0) + _vmIsoMapDao.listByVmId(vmId).size();
if (attached >= effectiveMax) {
throw new InvalidParameterValueException(String.format(
Comment on lines +254 to +265
List<AttachedIsoResponse> attachedIsos = new ArrayList<>();
if (userVm.getIsoUuid() != null) {
attachedIsos.add(new AttachedIsoResponse(userVm.getIsoUuid(), userVm.getIsoName(),
userVm.getIsoDisplayText(), TemplateManager.CDROM_PRIMARY_DEVICE_SEQ));
}
for (VmIsoMapVO row : vmIsoMapDao.listByVmId(userVm.getId())) {
VMTemplateVO tmpl = vmTemplateDao.findById(row.getIsoId());
if (tmpl != null) {
attachedIsos.add(new AttachedIsoResponse(tmpl.getUuid(), tmpl.getName(),
tmpl.getDisplayText(), row.getDeviceSeq()));
}
}
@blueorangutan
Copy link
Copy Markdown

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 17713

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants