From 25d522fb3dc9257ebd2880cf54c305fac16628bf Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Mon, 27 Sep 2021 16:16:27 +0530 Subject: [PATCH] server: add vm boot details for start vm api (#5469) Add vm boot details for start vm api Fixes #5466 Signed-off-by: Abhishek Kumar --- .../resource/CitrixResourceBase.java | 3 ++ .../java/com/cloud/vm/UserVmManagerImpl.java | 38 ++++++++++++------- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java index b63480f5cf4..c69d2b5e4b2 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java @@ -1956,6 +1956,9 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe if (!ApiConstants.BootType.UEFI.toString().equals(bootType)) { bootType = ApiConstants.BootType.BIOS.toString(); } + if (s_logger.isDebugEnabled()) { + s_logger.debug(String.format("Setting boottype=%s and bootmode=%s for VM: %s", bootType, bootMode, vm.getUuid(conn))); + } Boolean isSecure = bootType.equals(ApiConstants.BootType.UEFI.toString()) && ApiConstants.BootMode.SECURE.toString().equals(bootMode); final Map bootParams = vm.getHVMBootParams(conn); diff --git a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java index 17832bb7673..9efad8afe6c 100644 --- a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java @@ -724,6 +724,20 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir } } + private void addVmUefiBootOptionsToParams(Map params, String bootType, String bootMode) { + if (s_logger.isTraceEnabled()) { + s_logger.trace(String.format("Adding boot options (%s, %s, %s) into the param map for VM start as UEFI detail(%s=%s) found for the VM", + VirtualMachineProfile.Param.UefiFlag.getName(), + VirtualMachineProfile.Param.BootType.getName(), + VirtualMachineProfile.Param.BootMode.getName(), + bootType, + bootMode)); + } + params.put(VirtualMachineProfile.Param.UefiFlag, "Yes"); + params.put(VirtualMachineProfile.Param.BootType, bootType); + params.put(VirtualMachineProfile.Param.BootMode, bootMode); + } + @Override @ActionEvent(eventType = EventTypes.EVENT_VM_RESETPASSWORD, eventDescription = "resetting Vm password", async = true) public UserVm resetVMPassword(ResetVMPasswordCmd cmd, String password) throws ResourceUnavailableException, InsufficientCapacityException { @@ -2882,17 +2896,17 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir @Override @ActionEvent(eventType = EventTypes.EVENT_VM_START, eventDescription = "starting Vm", async = true) public UserVm startVirtualMachine(StartVMCmd cmd) throws ExecutionException, ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException, ResourceAllocationException { - Map additonalParams = null; + Map additonalParams = new HashMap<>(); if (cmd.getBootIntoSetup() != null) { - if (additonalParams == null) { - additonalParams = new HashMap<>(); - } if (s_logger.isTraceEnabled()) { s_logger.trace(String.format("Adding %s into the param map", VirtualMachineProfile.Param.BootIntoSetup.getName())); } - additonalParams.put(VirtualMachineProfile.Param.BootIntoSetup, cmd.getBootIntoSetup()); } + UserVmDetailVO uefiDetail = userVmDetailsDao.findDetail(cmd.getId(), ApiConstants.BootType.UEFI.toString()); + if (uefiDetail != null) { + addVmUefiBootOptionsToParams(additonalParams, uefiDetail.getName(), uefiDetail.getValue()); + } return startVirtualMachine(cmd.getId(), cmd.getPodId(), cmd.getClusterId(), cmd.getHostId(), additonalParams, cmd.getDeploymentPlanner()).first(); } @@ -4434,23 +4448,21 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir Long podId = null; Long clusterId = null; Long hostId = cmd.getHostId(); - Map additonalParams = new HashMap<>(); + Map additionalParams = new HashMap<>(); Map diskOfferingMap = cmd.getDataDiskTemplateToDiskOfferingMap(); + Map details = cmd.getDetails(); if (cmd instanceof DeployVMCmdByAdmin) { DeployVMCmdByAdmin adminCmd = (DeployVMCmdByAdmin)cmd; podId = adminCmd.getPodId(); clusterId = adminCmd.getClusterId(); } - if (MapUtils.isNotEmpty(cmd.getDetails()) && cmd.getDetails().containsKey(ApiConstants.BootType.UEFI.toString())) { - Map map = cmd.getDetails(); - additonalParams.put(VirtualMachineProfile.Param.UefiFlag, "Yes"); - additonalParams.put(VirtualMachineProfile.Param.BootType, ApiConstants.BootType.UEFI.toString()); - additonalParams.put(VirtualMachineProfile.Param.BootMode, map.get(ApiConstants.BootType.UEFI.toString())); + if (MapUtils.isNotEmpty(details) && details.containsKey(ApiConstants.BootType.UEFI.toString())) { + addVmUefiBootOptionsToParams(additionalParams, ApiConstants.BootType.UEFI.toString(), details.get(ApiConstants.BootType.UEFI.toString())); } if (cmd.getBootIntoSetup() != null) { - additonalParams.put(VirtualMachineProfile.Param.BootIntoSetup, cmd.getBootIntoSetup()); + additionalParams.put(VirtualMachineProfile.Param.BootIntoSetup, cmd.getBootIntoSetup()); } - return startVirtualMachine(vmId, podId, clusterId, hostId, diskOfferingMap, additonalParams, cmd.getDeploymentPlanner()); + return startVirtualMachine(vmId, podId, clusterId, hostId, diskOfferingMap, additionalParams, cmd.getDeploymentPlanner()); } private UserVm startVirtualMachine(long vmId, Long podId, Long clusterId, Long hostId, Map diskOfferingMap