Skip to content

Commit 73cabcd

Browse files
authored
xcp-ng: allow passing vm boot options (#5335)
* xenserver: honor vm boot details Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * ui: allow boot option selection for xenserver Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * fix Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * fix case Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * fix Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * host uefi capability Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * change Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * add detail only if uefi supported Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * update host detail Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * fix version comparison Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
1 parent 961e85e commit 73cabcd

File tree

6 files changed

+68
-3
lines changed

6 files changed

+68
-3
lines changed

plugins/hypervisors/xenserver/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,10 @@
4848
<artifactId>xen-api</artifactId>
4949
<version>${cs.xapi.version}</version>
5050
</dependency>
51+
<dependency>
52+
<groupId>org.apache.maven</groupId>
53+
<artifactId>maven-artifact</artifactId>
54+
<version>3.6.3</version>
55+
</dependency>
5156
</dependencies>
5257
</project>

plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/discoverer/XcpServerDiscoverer.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131
import javax.persistence.EntityExistsException;
3232

3333
import org.apache.cloudstack.hypervisor.xenserver.XenserverConfigs;
34+
import org.apache.commons.lang3.StringUtils;
3435
import org.apache.log4j.Logger;
36+
import org.apache.maven.artifact.versioning.ComparableVersion;
3537
import org.apache.xmlrpc.XmlRpcException;
3638

3739
import com.cloud.agent.AgentManager;
@@ -122,6 +124,16 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, L
122124
private String xenServerIsoName = TemplateManager.XS_TOOLS_ISO;
123125
private String xenServerIsoDisplayText = "XenServer Tools Installer ISO (xen-pv-drv-iso)";
124126

127+
public final static String MIN_UEFI_SUPPORTED_VERSION = "8.2";
128+
129+
public static boolean isUefiSupported(String hostProductVersion) {
130+
if (StringUtils.isEmpty(hostProductVersion)) {
131+
return false;
132+
}
133+
ComparableVersion version = new ComparableVersion(hostProductVersion);
134+
return version.compareTo(new ComparableVersion(MIN_UEFI_SUPPORTED_VERSION)) >= 0;
135+
}
136+
125137
protected XcpServerDiscoverer() {
126138
}
127139

@@ -309,6 +321,9 @@ protected boolean poolHasHotFix(Connection conn, String hostIp, String hotFixUui
309321
details.put("username", username);
310322
params.put("username", username);
311323
details.put("password", password);
324+
if (isUefiSupported(prodVersion)) {
325+
details.put(com.cloud.host.Host.HOST_UEFI_ENABLE, Boolean.TRUE.toString());
326+
}
312327
params.put("password", password);
313328
params.put("zone", Long.toString(dcId));
314329
params.put("guid", record.uuid);

plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// under the License.
1717
package com.cloud.hypervisor.xenserver.resource;
1818

19+
import static com.cloud.hypervisor.xenserver.discoverer.XcpServerDiscoverer.isUefiSupported;
1920
import static com.cloud.utils.NumbersUtil.toHumanReadableSize;
2021

2122
import java.io.BufferedReader;
@@ -51,6 +52,7 @@
5152
import javax.xml.parsers.DocumentBuilderFactory;
5253
import javax.xml.parsers.ParserConfigurationException;
5354

55+
import org.apache.cloudstack.api.ApiConstants;
5456
import org.apache.cloudstack.diagnostics.CopyToSecondaryStorageAnswer;
5557
import org.apache.cloudstack.diagnostics.CopyToSecondaryStorageCommand;
5658
import org.apache.cloudstack.diagnostics.DiagnosticsService;
@@ -1438,6 +1440,11 @@ public VM createVmFromTemplate(final Connection conn, final VirtualMachineTO vmS
14381440
} catch (final Exception e) {
14391441
throw new CloudRuntimeException("Unable to finalize VM MetaData: " + vmSpec);
14401442
}
1443+
try {
1444+
setVmBootDetails(vm, conn, vmSpec.getBootType(), vmSpec.getBootMode());
1445+
} catch (final XenAPIException | XmlRpcException e) {
1446+
throw new CloudRuntimeException(String.format("Unable to handle VM boot options: %s", vmSpec), e);
1447+
}
14411448
return vm;
14421449
}
14431450

@@ -1784,6 +1791,9 @@ protected void fillHostInfo(final Connection conn, final StartupRoutingCommand c
17841791
}
17851792
details.put("product_brand", productBrand);
17861793
details.put("product_version", _host.getProductVersion());
1794+
if (isUefiSupported(_host.getProductVersion())) {
1795+
details.put(com.cloud.host.Host.HOST_UEFI_ENABLE, Boolean.TRUE.toString());
1796+
}
17871797
if (hr.softwareVersion.get("product_version_text_short") != null) {
17881798
details.put("product_version_text_short", hr.softwareVersion.get("product_version_text_short"));
17891799
cmd.setHypervisorVersion(hr.softwareVersion.get("product_version_text_short"));
@@ -1942,6 +1952,20 @@ protected void finalizeVmMetaData(final VM vm, final VM.Record vmr, final Connec
19421952
}
19431953
}
19441954

1955+
protected void setVmBootDetails(final VM vm, final Connection conn, String bootType, String bootMode) throws XenAPIException, XmlRpcException {
1956+
if (!ApiConstants.BootType.UEFI.toString().equals(bootType)) {
1957+
bootType = ApiConstants.BootType.BIOS.toString();
1958+
}
1959+
Boolean isSecure = bootType.equals(ApiConstants.BootType.UEFI.toString()) &&
1960+
ApiConstants.BootMode.SECURE.toString().equals(bootMode);
1961+
final Map<String, String> bootParams = vm.getHVMBootParams(conn);
1962+
bootParams.replace("firmware", bootType.toLowerCase());
1963+
vm.setHVMBootParams(conn, bootParams);
1964+
final Map<String, String> platform = vm.getPlatform(conn);
1965+
platform.put("secureboot", isSecure.toString());
1966+
vm.setPlatform(conn, platform);
1967+
}
1968+
19451969
/**
19461970
* This method just creates a XenServer network following the tunnel network
19471971
* naming convention

plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/xenserver/discoverer/XcpServerDiscovererTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package com.cloud.hypervisor.xenserver.discoverer;
1919

20+
import org.junit.Assert;
2021
import org.junit.Test;
2122
import org.junit.runner.RunWith;
2223
import org.mockito.InOrder;
@@ -70,4 +71,25 @@ public void createXenServerToolsIsoEntryInDatabaseTestEntryAlreadyExist() {
7071
inOrder.verify(vmTemplateVOMock).setDisplayText("XenServer Tools Installer ISO (xen-pv-drv-iso)");
7172
inOrder.verify(vmTemplateDao).update(1L, vmTemplateVOMock);
7273
}
74+
75+
@Test
76+
public void uefiSupportedVersionTest() {
77+
Assert.assertTrue(XcpServerDiscoverer.isUefiSupported("8.2"));
78+
Assert.assertTrue(XcpServerDiscoverer.isUefiSupported("8.2.0"));
79+
Assert.assertTrue(XcpServerDiscoverer.isUefiSupported("8.2.1"));
80+
Assert.assertTrue(XcpServerDiscoverer.isUefiSupported("9"));
81+
Assert.assertTrue(XcpServerDiscoverer.isUefiSupported("9.1"));
82+
Assert.assertTrue(XcpServerDiscoverer.isUefiSupported("9.1.0"));
83+
Assert.assertTrue(XcpServerDiscoverer.isUefiSupported("10"));
84+
Assert.assertTrue(XcpServerDiscoverer.isUefiSupported("10.1"));
85+
Assert.assertTrue(XcpServerDiscoverer.isUefiSupported("10.1.0"));
86+
Assert.assertFalse(XcpServerDiscoverer.isUefiSupported(null));
87+
Assert.assertFalse(XcpServerDiscoverer.isUefiSupported(""));
88+
Assert.assertFalse(XcpServerDiscoverer.isUefiSupported("abc"));
89+
Assert.assertFalse(XcpServerDiscoverer.isUefiSupported("0"));
90+
Assert.assertFalse(XcpServerDiscoverer.isUefiSupported("7.4"));
91+
Assert.assertFalse(XcpServerDiscoverer.isUefiSupported("8"));
92+
Assert.assertFalse(XcpServerDiscoverer.isUefiSupported("8.1"));
93+
Assert.assertFalse(XcpServerDiscoverer.isUefiSupported("8.1.0"));
94+
}
7395
}

server/src/main/java/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public List<Host> allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan pla
123123
isVMDeployedWithUefi = true;
124124
}
125125
}
126-
s_logger.info(" Guest VM is requested with Cusotm[UEFI] Boot Type "+ isVMDeployedWithUefi);
126+
s_logger.info(" Guest VM is requested with Custom[UEFI] Boot Type "+ isVMDeployedWithUefi);
127127

128128

129129
if (type == Host.Type.Storage) {

ui/src/views/compute/DeployVM.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,10 +491,9 @@
491491
</span>
492492
<div style="margin-top: 15px" v-show="this.showDetails">
493493
<div
494-
v-if="vm.templateid && ['KVM', 'VMware'].includes(hypervisor) && !template.deployasis">
494+
v-if="vm.templateid && ['KVM', 'VMware', 'XenServer'].includes(hypervisor) && !template.deployasis">
495495
<a-form-item :label="$t('label.boottype')">
496496
<a-select
497-
:autoFocus="vm.templateid && ['KVM', 'VMware'].includes(hypervisor) && !template.deployasis"
498497
v-decorator="['boottype']"
499498
@change="fetchBootModes"
500499
>

0 commit comments

Comments
 (0)