Skip to content

Commit 68d7c68

Browse files
author
Pavan Kumar Aravapalli
committed
Vmware secure boot fixes
1 parent 51d0138 commit 68d7c68

7 files changed

Lines changed: 46 additions & 6 deletions

File tree

api/src/main/java/com/cloud/host/Host.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public static String[] toStrings(Host.Type... types) {
5252
return strs;
5353
}
5454
}
55-
public static final String HOST_UEFI_ENABLE = "Host.Uefi.Enable";
55+
public static final String HOST_UEFI_ENABLE = "host.uefi.enable";
5656

5757
/**
5858
* @return name of the machine.

engine/orchestration/src/main/java/org/apache/cloudstack/engine/cloud/entity/api/VMEntityManagerImpl.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.apache.cloudstack.engine.cloud.entity.api.db.dao.VMReservationDao;
3030
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
3131
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
32+
import org.apache.commons.collections.MapUtils;
3233
import org.apache.log4j.Logger;
3334
import org.springframework.stereotype.Component;
3435

@@ -148,11 +149,14 @@ public String reserveVirtualMachine(VMEntityVO vmEntityVO, DeploymentPlanner pla
148149
VMInstanceVO vm = _vmDao.findByUuid(vmEntityVO.getUuid());
149150
VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vm);
150151
vmProfile.setServiceOffering(_serviceOfferingDao.findByIdIncludingRemoved(vm.getId(), vm.getServiceOfferingId()));
151-
if (vmEntityVO.getDetails() != null) {
152+
if (MapUtils.isNotEmpty(vmEntityVO.getDetails()) &&
153+
vmEntityVO.getDetails().containsKey(VirtualMachineProfile.Param.UefiFlag.getName()) &&
154+
"yes".equalsIgnoreCase(vmEntityVO.getDetails().get(VirtualMachineProfile.Param.UefiFlag.getName())))
155+
{
152156
Map<String, String> details = vmEntityVO.getDetails();
153-
if (details.containsKey(VirtualMachineProfile.Param.BootType.getName())) {
154-
vmProfile.getParameters().put(VirtualMachineProfile.Param.BootType, details.get(VirtualMachineProfile.Param.BootType.getName()));
155-
}
157+
vmProfile.getParameters().put(VirtualMachineProfile.Param.BootType, details.get(VirtualMachineProfile.Param.BootType));
158+
vmProfile.getParameters().put(VirtualMachineProfile.Param.BootMode, details.get(VirtualMachineProfile.Param.BootMode));
159+
156160
}
157161
DataCenterDeployment plan = new DataCenterDeployment(vm.getDataCenterId(), vm.getPodIdToDeployIn(), null, null, null, null);
158162
if (planToDeploy != null && planToDeploy.getDataCenterId() != 0) {

plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/VmwareServerDiscoverer.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import com.cloud.exception.DiscoveryException;
4646
import com.cloud.exception.InvalidParameterValueException;
4747
import com.cloud.exception.ResourceInUseException;
48+
import com.cloud.host.Host;
4849
import com.cloud.host.HostVO;
4950
import com.cloud.hypervisor.Hypervisor;
5051
import com.cloud.hypervisor.Hypervisor.HypervisorType;
@@ -367,6 +368,10 @@ public VmwareServerDiscoverer() {
367368
details.put("url", hostMo.getHostName());
368369
details.put("username", username);
369370
details.put("password", password);
371+
boolean uefiLegacySupported = hostMo.isUefiLegacySupported();
372+
if (uefiLegacySupported) {
373+
details.put(Host.HOST_UEFI_ENABLE, "true");
374+
}
370375
String guid = morHost.getType() + ":" + morHost.getValue() + "@" + url.getHost();
371376
details.put("guid", guid);
372377

plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2764,6 +2764,9 @@ private static void configNvpExtraOption(List<OptionValue> extraOptions, Virtual
27642764
private static void configCustomExtraOption(List<OptionValue> extraOptions, VirtualMachineTO vmSpec) {
27652765
// we no longer to validation anymore
27662766
for (Map.Entry<String, String> entry : vmSpec.getDetails().entrySet()) {
2767+
if(entry.getKey().equalsIgnoreCase(VmDetailConstants.BOOT_MODE)) {
2768+
continue;
2769+
}
27672770
OptionValue newVal = new OptionValue();
27682771
newVal.setKey(entry.getKey());
27692772
newVal.setValue(entry.getValue());

server/src/main/java/com/cloud/vm/UserVmManagerImpl.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3910,6 +3910,11 @@ public UserVmVO doInTransaction(TransactionStatus status) throws InsufficientCap
39103910
} else {
39113911
vm.setDetail(key, customParameters.get(key));
39123912
}
3913+
3914+
if(key.equalsIgnoreCase("uefi")) {
3915+
vm.setDetail(key,customParameters.get(key));
3916+
continue;
3917+
}
39133918
}
39143919
vm.setDetail(VmDetailConstants.DEPLOY_VM, "true");
39153920

@@ -4212,13 +4217,21 @@ public UserVm startVirtualMachine(DeployVMCmd cmd) throws ResourceUnavailableExc
42124217
Long podId = null;
42134218
Long clusterId = null;
42144219
Long hostId = cmd.getHostId();
4220+
Map<VirtualMachineProfile.Param, Object> additonalParams = null;
42154221
Map<Long, DiskOffering> diskOfferingMap = cmd.getDataDiskTemplateToDiskOfferingMap();
42164222
if (cmd instanceof DeployVMCmdByAdmin) {
42174223
DeployVMCmdByAdmin adminCmd = (DeployVMCmdByAdmin)cmd;
42184224
podId = adminCmd.getPodId();
42194225
clusterId = adminCmd.getClusterId();
42204226
}
4221-
return startVirtualMachine(vmId, podId, clusterId, hostId, diskOfferingMap, null, cmd.getDeploymentPlanner());
4227+
if(MapUtils.isNotEmpty(cmd.getDetails()) && cmd.getDetails().containsKey("UEFI") ) {
4228+
additonalParams = new HashMap<VirtualMachineProfile.Param,Object>();
4229+
Map<String, String> map = cmd.getDetails();
4230+
additonalParams.put(VirtualMachineProfile.Param.UefiFlag, "Yes");
4231+
additonalParams.put(VirtualMachineProfile.Param.BootType, "UEFI");
4232+
additonalParams.put(VirtualMachineProfile.Param.BootMode, map.get("UEFI"));
4233+
}
4234+
return startVirtualMachine(vmId, podId, clusterId, hostId, diskOfferingMap, additonalParams, cmd.getDeploymentPlanner());
42224235
}
42234236

42244237
private UserVm startVirtualMachine(long vmId, Long podId, Long clusterId, Long hostId, Map<Long, DiskOffering> diskOfferingMap, Map<VirtualMachineProfile.Param, Object> additonalParams, String deploymentPlannerToUse)
@@ -4672,6 +4685,7 @@ public Pair<UserVmVO, Map<VirtualMachineProfile.Param, Object>> startVirtualMach
46724685
throw new InvalidParameterValueException("Can't find a planner by name " + deploymentPlannerToUse);
46734686
}
46744687
}
4688+
vmEntity.setParamsToEntity(additionalParams);
46754689

46764690
String reservationId = vmEntity.reserve(planner, plan, new ExcludeList(), Long.toString(callerUser.getId()));
46774691
vmEntity.deploy(reservationId, Long.toString(callerUser.getId()), params, deployOnGivenHost);

vmware-base/src/main/java/com/cloud/hypervisor/vmware/mo/HostMO.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,4 +1184,17 @@ public ManagedObjectReference waitForPortGroup(String networkName, long timeOutM
11841184
}
11851185
return morNetwork;
11861186
}
1187+
1188+
public String getProductVersion() throws Exception {
1189+
return getHostAboutInfo().getVersion();
1190+
}
1191+
1192+
public boolean isUefiLegacySupported() throws Exception {
1193+
String hostVersion = getProductVersion();
1194+
if (hostVersion.compareTo(VmwareHelper.MIN_VERSION_UEFI_LEGACY) >= 0) {
1195+
return true;
1196+
}
1197+
return false;
1198+
}
1199+
11871200
}

vmware-base/src/main/java/com/cloud/hypervisor/vmware/util/VmwareHelper.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ public class VmwareHelper {
9292
public static final int MAX_IDE_CONTROLLER_COUNT = 2;
9393
public static final int MAX_ALLOWED_DEVICES_IDE_CONTROLLER = 2;
9494
public static final int MAX_ALLOWED_DEVICES_SCSI_CONTROLLER = 15;
95+
public static final String MIN_VERSION_UEFI_LEGACY = "5.5";
9596

9697
public static boolean isReservedScsiDeviceNumber(int deviceNumber) {
9798
return deviceNumber == 7;

0 commit comments

Comments
 (0)