Skip to content

Commit 5378192

Browse files
committed
KVM: add admin-only VM setting GUEST.CPU.MODE and GUEST.CPU.MODEL
1 parent c9186a8 commit 5378192

File tree

5 files changed

+17
-2
lines changed

5 files changed

+17
-2
lines changed

api/src/main/java/com/cloud/vm/VmDetailConstants.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,8 @@ public interface VmDetailConstants {
106106
String VIRTUAL_TPM_ENABLED = "virtual.tpm.enabled";
107107
String VIRTUAL_TPM_MODEL = "virtual.tpm.model";
108108
String VIRTUAL_TPM_VERSION = "virtual.tpm.version";
109+
110+
// CPU mode and model, ADMIN only
111+
String GUEST_CPU_MODE = "guest.cpu.mode";
112+
String GUEST_CPU_MODEL = "guest.cpu.model";
109113
}

api/src/main/java/org/apache/cloudstack/query/QueryService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// under the License.
1717
package org.apache.cloudstack.query;
1818

19+
import java.util.Arrays;
1920
import java.util.List;
2021

2122
import org.apache.cloudstack.affinity.AffinityGroupResponse;
@@ -97,13 +98,16 @@
9798
import org.apache.cloudstack.framework.config.ConfigKey;
9899

99100
import com.cloud.exception.PermissionDeniedException;
101+
import com.cloud.vm.VmDetailConstants;
100102

101103
/**
102104
* Service used for list api query.
103105
*
104106
*/
105107
public interface QueryService {
106108

109+
List<String> RootAdminOnlyVmSettings = Arrays.asList(VmDetailConstants.GUEST_CPU_MODE, VmDetailConstants.GUEST_CPU_MODEL);
110+
107111
// Config keys
108112
ConfigKey<Boolean> AllowUserViewDestroyedVM = new ConfigKey<>("Advanced", Boolean.class, "allow.user.view.destroyed.vm", "false",
109113
"Determines whether users can view their destroyed or expunging vm ", true, ConfigKey.Scope.Account);

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2846,8 +2846,11 @@ public int calculateCpuShares(VirtualMachineTO vmTO) {
28462846

28472847
private CpuModeDef createCpuModeDef(VirtualMachineTO vmTO, int vcpus) {
28482848
final CpuModeDef cmd = new CpuModeDef();
2849-
cmd.setMode(guestCpuMode);
2850-
cmd.setModel(guestCpuModel);
2849+
Map<String, String> details = vmTO.getDetails();
2850+
String cpuMode = MapUtils.isNotEmpty(details) && details.get(VmDetailConstants.GUEST_CPU_MODE) != null ? details.get(VmDetailConstants.GUEST_CPU_MODE) : guestCpuMode;
2851+
String cpuModel = MapUtils.isNotEmpty(details) && details.get(VmDetailConstants.GUEST_CPU_MODEL) != null ? details.get(VmDetailConstants.GUEST_CPU_MODEL) : guestCpuModel;
2852+
cmd.setMode(cpuMode);
2853+
cmd.setModel(cpuModel);
28512854
if (VirtualMachine.Type.User.equals(vmTO.getType())) {
28522855
cmd.setFeatures(cpuFeatures);
28532856
}

server/src/main/java/com/cloud/api/query/QueryManagerImpl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5012,6 +5012,7 @@ public DetailOptionsResponse listDetailOptions(final ListDetailOptionsCmd cmd) {
50125012
final List<String> userDenyListedSettings = Stream.of(QueryService.UserVMDeniedDetails.value().split(","))
50135013
.map(item -> (item).trim())
50145014
.collect(Collectors.toList());
5015+
userDenyListedSettings.addAll(QueryService.RootAdminOnlyVmSettings);
50155016
for (final String detail : userDenyListedSettings) {
50165017
if (options.containsKey(detail)) {
50175018
options.remove(detail);
@@ -5064,6 +5065,8 @@ private void fillVMOrTemplateDetailOptions(final Map<String, List<String>> optio
50645065
options.put(VmDetailConstants.NIC_PACKED_VIRTQUEUES_ENABLED, Arrays.asList("true", "false"));
50655066
options.put(VmDetailConstants.VIRTUAL_TPM_MODEL, Arrays.asList("tpm-tis", "tpm-crb"));
50665067
options.put(VmDetailConstants.VIRTUAL_TPM_VERSION, Arrays.asList("1.2", "2.0"));
5068+
options.put(VmDetailConstants.GUEST_CPU_MODE, Arrays.asList("custom", "host-model", "host-passthrough"));
5069+
options.put(VmDetailConstants.GUEST_CPU_MODEL, Collections.emptyList());
50675070
}
50685071

50695072
if (HypervisorType.VMware.equals(hypervisorType)) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2840,6 +2840,7 @@ public UserVm updateVirtualMachine(UpdateVMCmd cmd) throws ResourceUnavailableEx
28402840
final List<String> userDenyListedSettings = Stream.of(QueryService.UserVMDeniedDetails.value().split(","))
28412841
.map(item -> (item).trim())
28422842
.collect(Collectors.toList());
2843+
userDenyListedSettings.addAll(QueryService.RootAdminOnlyVmSettings);
28432844
final List<String> userReadOnlySettings = Stream.of(QueryService.UserVMReadOnlyDetails.value().split(","))
28442845
.map(item -> (item).trim())
28452846
.collect(Collectors.toList());

0 commit comments

Comments
 (0)