@@ -3493,6 +3493,44 @@ public static DiskDef.DiskType getDiskType(KVMPhysicalDisk physicalDisk) {
34933493 return useBLOCKDiskType (physicalDisk ) ? DiskDef .DiskType .BLOCK : DiskDef .DiskType .FILE ;
34943494 }
34953495
3496+ /**
3497+ * Defines the disk configuration for the default pool type based on the provided parameters.
3498+ * It determines the appropriate disk settings depending on whether the disk is a data disk, whether
3499+ * it's a Windows template, whether UEFI is enabled, and whether secure boot is active.
3500+ *
3501+ * @param disk The disk definition object that will be configured with the disk settings.
3502+ * @param volume The volume (disk) object, containing information about the type of disk.
3503+ * @param isWindowsTemplate Flag indicating whether the template is a Windows template.
3504+ * @param isUefiEnabled Flag indicating whether UEFI is enabled.
3505+ * @param isSecureBoot Flag indicating whether secure boot is enabled.
3506+ * @param physicalDisk The physical disk object that contains the path to the disk.
3507+ * @param devId The device ID for the disk.
3508+ * @param diskBusType The disk bus type to use if not skipping force disk controller.
3509+ * @param diskBusTypeData The disk bus type to use for data disks, if applicable.
3510+ * @param details A map of VM details containing additional configuration values, such as whether to skip force
3511+ * disk controller.
3512+ */
3513+ protected void defineDiskForDefaultPoolType (DiskDef disk , DiskTO volume , boolean isWindowsTemplate ,
3514+ boolean isUefiEnabled , boolean isSecureBoot , KVMPhysicalDisk physicalDisk , int devId ,
3515+ DiskDef .DiskBus diskBusType , DiskDef .DiskBus diskBusTypeData , Map <String , String > details ) {
3516+ boolean skipForceDiskController = MapUtils .getBoolean (details , VmDetailConstants .KVM_SKIP_FORCE_DISK_CONTROLLER ,
3517+ false );
3518+ if (skipForceDiskController ) {
3519+ disk .defFileBasedDisk (physicalDisk .getPath (), devId , Volume .Type .DATADISK .equals (volume .getType ()) ?
3520+ diskBusTypeData : diskBusType , DiskDef .DiskFmtType .QCOW2 );
3521+ return ;
3522+ }
3523+ if (volume .getType () == Volume .Type .DATADISK && !(isWindowsTemplate && isUefiEnabled )) {
3524+ disk .defFileBasedDisk (physicalDisk .getPath (), devId , diskBusTypeData , DiskDef .DiskFmtType .QCOW2 );
3525+ } else {
3526+ if (isSecureBoot ) {
3527+ disk .defFileBasedDisk (physicalDisk .getPath (), devId , DiskDef .DiskFmtType .QCOW2 , isWindowsTemplate );
3528+ } else {
3529+ disk .defFileBasedDisk (physicalDisk .getPath (), devId , diskBusType , DiskDef .DiskFmtType .QCOW2 );
3530+ }
3531+ }
3532+ }
3533+
34963534 public void createVbd (final Connect conn , final VirtualMachineTO vmSpec , final String vmName , final LibvirtVMDef vm ) throws InternalErrorException , LibvirtException , URISyntaxException {
34973535 final Map <String , String > details = vmSpec .getDetails ();
34983536 final List <DiskTO > disks = Arrays .asList (vmSpec .getDisks ());
@@ -3654,15 +3692,8 @@ public int compare(final DiskTO arg0, final DiskTO arg1) {
36543692 disk .setDiscard (DiscardType .UNMAP );
36553693 }
36563694 } else {
3657- if (volume .getType () == Volume .Type .DATADISK && !(isWindowsTemplate && isUefiEnabled )) {
3658- disk .defFileBasedDisk (physicalDisk .getPath (), devId , diskBusTypeData , DiskDef .DiskFmtType .QCOW2 );
3659- } else {
3660- if (isSecureBoot ) {
3661- disk .defFileBasedDisk (physicalDisk .getPath (), devId , DiskDef .DiskFmtType .QCOW2 , isWindowsTemplate );
3662- } else {
3663- disk .defFileBasedDisk (physicalDisk .getPath (), devId , diskBusType , DiskDef .DiskFmtType .QCOW2 );
3664- }
3665- }
3695+ defineDiskForDefaultPoolType (disk , volume , isWindowsTemplate , isUefiEnabled , isSecureBoot ,
3696+ physicalDisk , devId , diskBusType , diskBusTypeData , details );
36663697 }
36673698 pool .customizeLibvirtDiskDef (disk );
36683699 }
0 commit comments