Skip to content
47 changes: 37 additions & 10 deletions api/src/main/java/com/cloud/vm/VmDetailConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,41 @@
package com.cloud.vm;

public interface VmDetailConstants {
public static final String KEYBOARD = "keyboard";
public static final String NIC_ADAPTER = "nicAdapter";
public static final String ROOT_DISK_CONTROLLER = "rootDiskController";
public static final String NESTED_VIRTUALIZATION_FLAG = "nestedVirtualizationFlag";
public static final String HYPERVISOR_TOOLS_VERSION = "hypervisortoolsversion";
public static final String DATA_DISK_CONTROLLER = "dataDiskController";
public static final String SVGA_VRAM_SIZE = "svga.vramSize";
public static final String CPU_NUMBER = "cpuNumber";
public static final String CPU_SPEED = "cpuSpeed";
public static final String MEMORY = "memory";
String KEYBOARD = "keyboard";
String CPU_CORE_PER_SOCKET = "cpu.corespersocket";

// VMware specific
String NIC_ADAPTER = "nicAdapter";
String ROOT_DISK_CONTROLLER = "rootDiskController";
String DATA_DISK_CONTROLLER = "dataDiskController";
String SVGA_VRAM_SIZE = "svga.vramSize";
String NESTED_VIRTUALIZATION_FLAG = "nestedVirtualizationFlag";

// XenServer specific (internal)
String HYPERVISOR_TOOLS_VERSION = "hypervisortoolsversion";
String PLATFORM = "platform";
String TIME_OFFSET = "timeoffset";

// KVM specific (internal)
String KVM_VNC_PORT = "kvm.vnc.port";
String KVM_VNC_ADDRESS = "kvm.vnc.address";

// Mac OSX guest specific (internal)
String SMC_PRESENT = "smc.present";
String FIRMWARE = "firmware";

// VM deployment with custom compute offering params
String CPU_NUMBER = "cpuNumber";
String CPU_SPEED = "cpuSpeed";
String MEMORY = "memory";

// Misc details for internal usage (not to be set/changed by user or admin)
String CPU_OVER_COMMIT_RATIO = "cpuOvercommitRatio";
String MEMORY_OVER_COMMIT_RATIO = "memoryOvercommitRatio";
String MESSAGE_RESERVED_CAPACITY_FREED_FLAG = "Message.ReservedCapacityFreed.Flag";
String DEPLOY_VM = "deployvm";
String ROOT_DISK_SIZE = "rootdisksize";
String SSH_PUBLIC_KEY = "SSH.PublicKey";
String PASSWORD = "password";
String ENCRYPTED_PASSWORD = "Encrypted.Password";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.apache.cloudstack.api.command.user.resource;

import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiArgValidator;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.response.DetailOptionsResponse;
import org.apache.cloudstack.context.CallContext;

import com.cloud.server.ResourceTag;
import com.google.common.base.Strings;

@APICommand(name = ListDetailOptionsCmd.APINAME,
description = "Lists all possible details and their options for a resource type such as a VM or a template",
responseObject = DetailOptionsResponse.class,
since = "4.13",
requestHasSensitiveInfo = false,
responseHasSensitiveInfo = false)
public class ListDetailOptionsCmd extends BaseCmd {
public final static String APINAME = "listDetailOptions";

/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////

@Parameter(name = ApiConstants.RESOURCE_TYPE, type = CommandType.STRING, required = true,
description = "the resource type such as UserVm, Template etc.",
validations = {ApiArgValidator.NotNullOrEmpty}
)
private String resourceType;

@Parameter(name = ApiConstants.RESOURCE_ID, type = CommandType.STRING,
description = "the UUID of the resource (optional)")
private String resourceId;

/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////

public ResourceTag.ResourceObjectType getResourceType() {
return _taggedResourceService.getResourceType(resourceType);
}

public String getResourceId() {
if (!Strings.isNullOrEmpty(resourceId)) {
return _taggedResourceService.getUuid(resourceId, getResourceType());
}
return null;
}

/////////////////////////////////////////////////////
/////////////////// Implementation //////////////////
/////////////////////////////////////////////////////

@Override
public String getCommandName() {
return APINAME.toLowerCase() + BaseCmd.RESPONSE_SUFFIX;
}

@Override
public long getEntityOwnerId() {
return CallContext.current().getCallingAccountId();
}

@Override
public void execute() {
final DetailOptionsResponse response = _queryService.listDetailOptions(this);
response.setResponseName(getCommandName());
response.setObjectName("detailoptions");
setResponseObject(response);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.apache.cloudstack.api.response;

import java.util.List;
import java.util.Map;

import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseResponse;

import com.cloud.serializer.Param;
import com.google.gson.annotations.SerializedName;

public class DetailOptionsResponse extends BaseResponse {
@SerializedName(ApiConstants.DETAILS)
@Param(description = "Map of all possible details and their possible list of values")
private Map<String, List<String>> details;

public DetailOptionsResponse(Map<String, List<String>> details) {
this.details = details;
}

public void setDetails(Map<String, List<String>> details) {
this.details = details;
}

public Map<String, List<String>> getDetails() {
return details;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

import org.apache.cloudstack.affinity.AffinityGroupResponse;
import org.apache.cloudstack.api.command.admin.domain.ListDomainsCmd;
import org.apache.cloudstack.api.command.admin.host.ListHostsCmd;
import org.apache.cloudstack.api.command.admin.host.ListHostTagsCmd;
import org.apache.cloudstack.api.command.admin.host.ListHostsCmd;
import org.apache.cloudstack.api.command.admin.internallb.ListInternalLBVMsCmd;
import org.apache.cloudstack.api.command.admin.management.ListMgmtsCmd;
import org.apache.cloudstack.api.command.admin.router.ListRoutersCmd;
Expand All @@ -40,6 +40,7 @@
import org.apache.cloudstack.api.command.user.offering.ListServiceOfferingsCmd;
import org.apache.cloudstack.api.command.user.project.ListProjectInvitationsCmd;
import org.apache.cloudstack.api.command.user.project.ListProjectsCmd;
import org.apache.cloudstack.api.command.user.resource.ListDetailOptionsCmd;
import org.apache.cloudstack.api.command.user.securitygroup.ListSecurityGroupsCmd;
import org.apache.cloudstack.api.command.user.tag.ListTagsCmd;
import org.apache.cloudstack.api.command.user.template.ListTemplatesCmd;
Expand All @@ -50,6 +51,7 @@
import org.apache.cloudstack.api.command.user.zone.ListZonesCmd;
import org.apache.cloudstack.api.response.AccountResponse;
import org.apache.cloudstack.api.response.AsyncJobResponse;
import org.apache.cloudstack.api.response.DetailOptionsResponse;
import org.apache.cloudstack.api.response.DiskOfferingResponse;
import org.apache.cloudstack.api.response.DomainResponse;
import org.apache.cloudstack.api.response.DomainRouterResponse;
Expand Down Expand Up @@ -134,6 +136,8 @@ public interface QueryService {

ListResponse<TemplateResponse> listIsos(ListIsosCmd cmd);

DetailOptionsResponse listDetailOptions(ListDetailOptionsCmd cmd);

ListResponse<AffinityGroupResponse> searchForAffinityGroups(ListAffinityGroupsCmd cmd);

List<ResourceDetailResponse> listResourceDetails(ListResourceDetailsCmd cmd);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1071,16 +1071,16 @@ public void orchestrateStart(final String vmUuid, final Map<VirtualMachineProfil
long destHostId = dest.getHost().getId();
vm.setPodIdToDeployIn(dest.getPod().getId());
final Long cluster_id = dest.getCluster().getId();
final ClusterDetailsVO cluster_detail_cpu = _clusterDetailsDao.findDetail(cluster_id, "cpuOvercommitRatio");
final ClusterDetailsVO cluster_detail_ram = _clusterDetailsDao.findDetail(cluster_id, "memoryOvercommitRatio");
//storing the value of overcommit in the vm_details table for doing a capacity check in case the cluster overcommit ratio is changed.
if (userVmDetailsDao.findDetail(vm.getId(), "cpuOvercommitRatio") == null &&
final ClusterDetailsVO cluster_detail_cpu = _clusterDetailsDao.findDetail(cluster_id, VmDetailConstants.CPU_OVER_COMMIT_RATIO);
final ClusterDetailsVO cluster_detail_ram = _clusterDetailsDao.findDetail(cluster_id, VmDetailConstants.MEMORY_OVER_COMMIT_RATIO);
//storing the value of overcommit in the user_vm_details table for doing a capacity check in case the cluster overcommit ratio is changed.
if (userVmDetailsDao.findDetail(vm.getId(), VmDetailConstants.CPU_OVER_COMMIT_RATIO) == null &&
(Float.parseFloat(cluster_detail_cpu.getValue()) > 1f || Float.parseFloat(cluster_detail_ram.getValue()) > 1f)) {
userVmDetailsDao.addDetail(vm.getId(), "cpuOvercommitRatio", cluster_detail_cpu.getValue(), true);
userVmDetailsDao.addDetail(vm.getId(), "memoryOvercommitRatio", cluster_detail_ram.getValue(), true);
} else if (userVmDetailsDao.findDetail(vm.getId(), "cpuOvercommitRatio") != null) {
userVmDetailsDao.addDetail(vm.getId(), "cpuOvercommitRatio", cluster_detail_cpu.getValue(), true);
userVmDetailsDao.addDetail(vm.getId(), "memoryOvercommitRatio", cluster_detail_ram.getValue(), true);
userVmDetailsDao.addDetail(vm.getId(), VmDetailConstants.CPU_OVER_COMMIT_RATIO, cluster_detail_cpu.getValue(), true);
userVmDetailsDao.addDetail(vm.getId(), VmDetailConstants.MEMORY_OVER_COMMIT_RATIO, cluster_detail_ram.getValue(), true);
} else if (userVmDetailsDao.findDetail(vm.getId(), VmDetailConstants.CPU_OVER_COMMIT_RATIO) != null) {
userVmDetailsDao.addDetail(vm.getId(), VmDetailConstants.CPU_OVER_COMMIT_RATIO, cluster_detail_cpu.getValue(), true);
userVmDetailsDao.addDetail(vm.getId(), VmDetailConstants.MEMORY_OVER_COMMIT_RATIO, cluster_detail_ram.getValue(), true);
}

vmProfile.setCpuOvercommitRatio(Float.parseFloat(cluster_detail_cpu.getValue()));
Expand Down Expand Up @@ -1162,8 +1162,8 @@ public void orchestrateStart(final String vmUuid, final Map<VirtualMachineProfil
// Remove the information on whether it was a deploy vm request.The deployvm=true information
// is set only when the vm is being deployed. When a vm is started from a stop state the
// information isn't set,
if (userVmDetailsDao.findDetail(vm.getId(), "deployvm") != null) {
userVmDetailsDao.removeDetail(vm.getId(), "deployvm");
if (userVmDetailsDao.findDetail(vm.getId(), VmDetailConstants.DEPLOY_VM) != null) {
userVmDetailsDao.removeDetail(vm.getId(), VmDetailConstants.DEPLOY_VM);
}

startedVm = vm;
Expand Down Expand Up @@ -1466,7 +1466,7 @@ protected boolean sendStop(final VirtualMachineGuru guru, final VirtualMachinePr
if (platform != null) {
final UserVmVO userVm = _userVmDao.findById(vm.getId());
_userVmDao.loadDetails(userVm);
userVm.setDetail("platform", platform);
userVm.setDetail(VmDetailConstants.PLATFORM, platform);
_userVmDao.saveDetails(userVm);
}
}
Expand Down Expand Up @@ -1742,7 +1742,7 @@ private void advanceStop(final VMInstanceVO vm, final boolean cleanUpEvenIfUnabl
if (platform != null) {
final UserVmVO userVm = _userVmDao.findById(vm.getId());
_userVmDao.loadDetails(userVm);
userVm.setDetail("platform", platform);
userVm.setDetail(VmDetailConstants.PLATFORM, platform);
_userVmDao.saveDetails(userVm);
}
}
Expand Down Expand Up @@ -3179,16 +3179,16 @@ public void syncVMMetaData(final Map<String, String> vmMetadatum) {
private void updateVmMetaData(Long vmId, String platform) {
UserVmVO userVm = _userVmDao.findById(vmId);
_userVmDao.loadDetails(userVm);
if ( userVm.details.containsKey("timeoffset")) {
userVm.details.remove("timeoffset");
if ( userVm.details.containsKey(VmDetailConstants.TIME_OFFSET)) {
userVm.details.remove(VmDetailConstants.TIME_OFFSET);
}
userVm.setDetail("platform", platform);
userVm.setDetail(VmDetailConstants.PLATFORM, platform);
String pvdriver = "xenserver56";
if ( platform.contains("device_id")) {
pvdriver = "xenserver61";
}
if (!userVm.details.containsKey("hypervisortoolsversion") || !userVm.details.get("hypervisortoolsversion").equals(pvdriver)) {
userVm.setDetail("hypervisortoolsversion", pvdriver);
if (!userVm.details.containsKey(VmDetailConstants.HYPERVISOR_TOOLS_VERSION) || !userVm.details.get(VmDetailConstants.HYPERVISOR_TOOLS_VERSION).equals(pvdriver)) {
userVm.setDetail(VmDetailConstants.HYPERVISOR_TOOLS_VERSION, pvdriver);
}
_userVmDao.saveDetails(userVm);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1876,7 +1876,7 @@ protected StartAnswer execute(StartCommand cmd) {

// Check for multi-cores per socket settings
int numCoresPerSocket = 1;
String coresPerSocket = vmSpec.getDetails().get("cpu.corespersocket");
String coresPerSocket = vmSpec.getDetails().get(VmDetailConstants.CPU_CORE_PER_SOCKET);
if (coresPerSocket != null) {
String apiVersion = HypervisorHostHelper.getVcenterApiVersion(vmMo.getContext());
// Property 'numCoresPerSocket' is supported since vSphere API 5.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
import com.cloud.utils.ssh.SshHelper;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachine.PowerState;
import com.cloud.vm.VmDetailConstants;
import com.trilead.ssh2.SCPClient;
import com.xensource.xenapi.Bond;
import com.xensource.xenapi.Connection;
Expand Down Expand Up @@ -1870,26 +1871,26 @@ protected void finalizeVmMetaData(final VM vm, final Connection conn, final Virt

final Map<String, String> details = vmSpec.getDetails();
if (details != null) {
final String platformstring = details.get("platform");
final String platformstring = details.get(VmDetailConstants.PLATFORM);
if (platformstring != null && !platformstring.isEmpty()) {
final Map<String, String> platform = StringUtils.stringToMap(platformstring);
vm.setPlatform(conn, platform);
} else {
final String timeoffset = details.get("timeoffset");
final String timeoffset = details.get(VmDetailConstants.TIME_OFFSET);
if (timeoffset != null) {
final Map<String, String> platform = vm.getPlatform(conn);
platform.put("timeoffset", timeoffset);
platform.put(VmDetailConstants.TIME_OFFSET, timeoffset);
vm.setPlatform(conn, platform);
}
final String coresPerSocket = details.get("cpu.corespersocket");
final String coresPerSocket = details.get(VmDetailConstants.CPU_CORE_PER_SOCKET);
if (coresPerSocket != null) {
final Map<String, String> platform = vm.getPlatform(conn);
platform.put("cores-per-socket", coresPerSocket);
vm.setPlatform(conn, platform);
}
}
if (!BootloaderType.CD.equals(vmSpec.getBootloader())) {
final String xenservertoolsversion = details.get("hypervisortoolsversion");
final String xenservertoolsversion = details.get(VmDetailConstants.HYPERVISOR_TOOLS_VERSION);
if ((xenservertoolsversion == null || !xenservertoolsversion.equalsIgnoreCase("xenserver61")) && vmSpec.getGpuDevice() == null) {
final Map<String, String> platform = vm.getPlatform(conn);
platform.remove("device_id");
Expand Down
3 changes: 2 additions & 1 deletion server/src/main/java/com/cloud/api/ApiDBUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@
import com.cloud.vm.UserVmVO;
import com.cloud.vm.VMInstanceVO;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VmDetailConstants;
import com.cloud.vm.VmStats;
import com.cloud.vm.dao.ConsoleProxyDao;
import com.cloud.vm.dao.DomainRouterDao;
Expand Down Expand Up @@ -1454,7 +1455,7 @@ public static String getKeyPairName(String sshPublicKey) {
}

public static UserVmDetailVO findPublicKeyByVmId(long vmId) {
return s_userVmDetailsDao.findDetail(vmId, "SSH.PublicKey");
return s_userVmDetailsDao.findDetail(vmId, VmDetailConstants.SSH_PUBLIC_KEY);
}

public static void getAutoScaleVmGroupPolicies(long vmGroupId, List<AutoScalePolicy> scaleUpPolicies, List<AutoScalePolicy> scaleDownPolicies) {
Expand Down
Loading