Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion api/src/main/java/com/cloud/vm/UserVmService.java
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ UserVm upgradeVirtualMachine(ScaleVMCmd cmd) throws ResourceUnavailableException
* @param userId user ID
* @param serviceOffering service offering for the imported VM
* @param sshPublicKey ssh key for the imported VM
* @param guestOsId guest OS ID for the imported VM (if not passed, then the guest OS of the template will be used)
* @param hostName the name for the imported VM
* @param hypervisorType hypervisor type for the imported VM
* @param customParameters details for the imported VM
Expand All @@ -533,7 +534,7 @@ UserVm upgradeVirtualMachine(ScaleVMCmd cmd) throws ResourceUnavailableException
* @throws InsufficientCapacityException in case of errors
*/
UserVm importVM(final DataCenter zone, final Host host, final VirtualMachineTemplate template, final String instanceNameInternal, final String displayName, final Account owner, final String userData, final Account caller, final Boolean isDisplayVm, final String keyboard,
final long accountId, final long userId, final ServiceOffering serviceOffering, final String sshPublicKey,
final long accountId, final long userId, final ServiceOffering serviceOffering, final String sshPublicKey, final Long guestOsId,
final String hostName, final HypervisorType hypervisorType, final Map<String, String> customParameters,
final VirtualMachine.PowerState powerState, final LinkedHashMap<String, List<NicProfile>> networkNicMap) throws InsufficientCapacityException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ public class ImportVmCmd extends ImportUnmanagedInstanceCmd {
description = "(only for importing VMs from VMware to KVM) optional - if true, forces virt-v2v conversions to write directly on the provided storage pool (avoid using temporary conversion pool).")
private Boolean forceConvertToPool;

@Parameter(name = ApiConstants.OS_ID,
type = CommandType.UUID,
since = "4.22.1",
description = "(only for importing VMs from VMware to KVM) optional - the ID of the guest OS for the imported VM.")
private Long guestOsId;

/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
Expand Down Expand Up @@ -268,6 +274,10 @@ public boolean getForceConvertToPool() {
return BooleanUtils.toBooleanDefaultIfNull(forceConvertToPool, false);
}

public Long getGuestOsId() {
return guestOsId;
}

@Override
public String getEventDescription() {
String vmName = getName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public class ListGuestOsCmd extends BaseListCmd {
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = GuestOSResponse.class, description = "List by OS type ID")
private Long id;

@Parameter(name = ApiConstants.IDS, type = CommandType.LIST, collectionType = CommandType.UUID,
entityType = GuestOSResponse.class, since = "4.22.1",
description = "Comma separated list of OS types")
private List<Long> ids;

@Parameter(name = ApiConstants.OS_CATEGORY_ID, type = CommandType.UUID, entityType = GuestOSCategoryResponse.class, description = "List by OS Category ID")
private Long osCategoryId;

Expand All @@ -63,6 +68,10 @@ public Long getId() {
return id;
}

public List<Long> getIds() {
return ids;
}

public Long getOsCategoryId() {
return osCategoryId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ public class UnmanagedInstanceResponse extends BaseResponse {
@Param(description = "The name of the host to which Instance belongs")
private String hostName;

@SerializedName(ApiConstants.HYPERVISOR)
@Param(description = "The hypervisor to which Instance belongs")
private String hypervisor;

@SerializedName(ApiConstants.HYPERVISOR_VERSION)
@Param(description = "The hypervisor version of the host to which Instance belongs")
private String hypervisorVersion;

@SerializedName(ApiConstants.POWER_STATE)
@Param(description = "The power state of the Instance")
private String powerState;
Expand Down Expand Up @@ -140,6 +148,22 @@ public void setHostName(String hostName) {
this.hostName = hostName;
}

public String getHypervisor() {
return hypervisor;
}

public void setHypervisor(String hypervisor) {
this.hypervisor = hypervisor;
}

public String getHypervisorVersion() {
return hypervisorVersion;
}

public void setHypervisorVersion(String hypervisorVersion) {
this.hypervisorVersion = hypervisorVersion;
}

public String getPowerState() {
return powerState;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public enum PowerState {

private String hostName;

private String hypervisorType;
private String hostHypervisorVersion;

private List<Disk> disks;

private List<Nic> nics;
Expand Down Expand Up @@ -168,6 +171,22 @@ public void setHostName(String hostName) {
this.hostName = hostName;
}

public String getHypervisorType() {
return hypervisorType;
}

public void setHypervisorType(String hypervisorType) {
this.hypervisorType = hypervisorType;
}

public String getHostHypervisorVersion() {
return hostHypervisorVersion;
}

public void setHostHypervisorVersion(String hostHypervisorVersion) {
this.hostHypervisorVersion = hostHypervisorVersion;
}

public List<Disk> getDisks() {
return disks;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public interface GuestOSDao extends GenericDao<GuestOSVO, Long> {

List<GuestOSVO> listByDisplayName(String displayName);

Pair<List<? extends GuestOS>, Integer> listGuestOSByCriteria(Long startIndex, Long pageSize, Long id, Long osCategoryId, String description, String keyword, Boolean forDisplay);
Pair<List<? extends GuestOS>, Integer> listGuestOSByCriteria(Long startIndex, Long pageSize, List<Long> ids, Long osCategoryId, String description, String keyword, Boolean forDisplay);

List<Long> listIdsByCategoryId(final long categoryId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ public List<GuestOSVO> listByDisplayName(String displayName) {
return listBy(sc);
}

public Pair<List<? extends GuestOS>, Integer> listGuestOSByCriteria(Long startIndex, Long pageSize, Long id, Long osCategoryId, String description, String keyword, Boolean forDisplay) {
public Pair<List<? extends GuestOS>, Integer> listGuestOSByCriteria(Long startIndex, Long pageSize, List<Long> ids, Long osCategoryId, String description, String keyword, Boolean forDisplay) {
final Filter searchFilter = new Filter(GuestOSVO.class, "displayName", true, startIndex, pageSize);
final SearchCriteria<GuestOSVO> sc = createSearchCriteria();

if (id != null) {
sc.addAnd("id", SearchCriteria.Op.EQ, id);
if (CollectionUtils.isNotEmpty(ids)) {
sc.addAnd("id", SearchCriteria.Op.IN, ids.toArray());
}

if (osCategoryId != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.GetRemoteVmsAnswer;
import com.cloud.agent.api.GetRemoteVmsCommand;
import com.cloud.hypervisor.Hypervisor;
import com.cloud.hypervisor.kvm.resource.LibvirtComputingResource;
import com.cloud.hypervisor.kvm.resource.LibvirtConnection;
import com.cloud.hypervisor.kvm.resource.LibvirtDomainXMLParser;
Expand Down Expand Up @@ -97,6 +98,7 @@ private UnmanagedInstanceTO getUnmanagedInstance(LibvirtComputingResource libvir
if (parser.getCpuTuneDef() !=null) {
instance.setCpuSpeed(parser.getCpuTuneDef().getShares());
}
instance.setHypervisorType(Hypervisor.HypervisorType.KVM.name());
instance.setPowerState(getPowerState(libvirtComputingResource.getVmState(conn,domain.getName())));
instance.setNics(getUnmanagedInstanceNics(parser.getInterfaces()));
instance.setDisks(getUnmanagedInstanceDisks(parser.getDisks(),libvirtComputingResource, domain));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import com.cloud.agent.api.GetUnmanagedInstancesAnswer;
import com.cloud.agent.api.GetUnmanagedInstancesCommand;
import com.cloud.hypervisor.Hypervisor;
import com.cloud.hypervisor.kvm.resource.LibvirtComputingResource;
import com.cloud.hypervisor.kvm.resource.LibvirtDomainXMLParser;
import com.cloud.hypervisor.kvm.resource.LibvirtVMDef;
Expand Down Expand Up @@ -130,6 +131,7 @@ private UnmanagedInstanceTO getUnmanagedInstance(LibvirtComputingResource libvir
if (parser.getCpuModeDef() != null) {
instance.setCpuCoresPerSocket(parser.getCpuModeDef().getCoresPerSocket());
}
instance.setHypervisorType(Hypervisor.HypervisorType.KVM.name());
instance.setPowerState(getPowerState(libvirtComputingResource.getVmState(conn,domain.getName())));
instance.setMemory((int) LibvirtComputingResource.getDomainMemory(domain) / 1024);
instance.setNics(getUnmanagedInstanceNics(libvirtComputingResource, parser.getInterfaces()));
Expand Down
17 changes: 15 additions & 2 deletions server/src/main/java/com/cloud/api/ApiResponseHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -5339,8 +5339,21 @@ public UnmanagedInstanceResponse createUnmanagedInstanceResponse(UnmanagedInstan
if (host != null) {
response.setHostId(host.getUuid());
response.setHostName(host.getName());
} else if (instance.getHostName() != null) {
response.setHostName(instance.getHostName());
if (host.getHypervisorType() != null) {
response.setHypervisor(host.getHypervisorType().name());
}
response.setHypervisorVersion(host.getHypervisorVersion());
} else {
// In case the unmanaged instance is on an external host
if (instance.getHostName() != null) {
response.setHostName(instance.getHostName());
}
if (instance.getHypervisorType() != null) {
response.setHypervisor(instance.getHypervisorType());
}
if (instance.getHostHypervisorVersion() != null) {
response.setHypervisorVersion(instance.getHostHypervisorVersion());
}
}
response.setPowerState((instance.getPowerState() != null)? instance.getPowerState().toString() : UnmanagedInstanceTO.PowerState.PowerUnknown.toString());
response.setCpuCores(instance.getCpuCores());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import javax.inject.Inject;
import javax.naming.ConfigurationException;

import com.cloud.api.query.MutualExclusiveIdsManagerBase;
import com.cloud.network.vpc.VpcVO;
import org.apache.cloudstack.acl.ControlledEntity;
import org.apache.cloudstack.acl.SecurityChecker;
Expand Down Expand Up @@ -832,7 +833,6 @@
import com.cloud.utils.PasswordGenerator;
import com.cloud.utils.Ternary;
import com.cloud.utils.component.ComponentLifecycle;
import com.cloud.utils.component.ManagerBase;
import com.cloud.utils.concurrency.NamedThreadFactory;
import com.cloud.utils.crypt.DBEncryptionUtil;
import com.cloud.utils.db.DB;
Expand Down Expand Up @@ -875,7 +875,7 @@
import com.cloud.vm.dao.VMInstanceDao;
import com.cloud.vm.dao.VMInstanceDetailsDao;

public class ManagementServerImpl extends ManagerBase implements ManagementServer, Configurable {
public class ManagementServerImpl extends MutualExclusiveIdsManagerBase implements ManagementServer, Configurable {
protected StateMachine2<State, VirtualMachine.Event, VirtualMachine> _stateMachine;

static final String FOR_SYSTEMVMS = "forsystemvms";
Expand Down Expand Up @@ -2898,15 +2898,15 @@ protected void setParameters(SearchCriteria<IPAddressVO> sc, final ListPublicIpA

@Override
public Pair<List<? extends GuestOS>, Integer> listGuestOSByCriteria(final ListGuestOsCmd cmd) {
final Long id = cmd.getId();
List<Long> ids = getIdsListFromCmd(cmd.getId(), cmd.getIds());
final Long osCategoryId = cmd.getOsCategoryId();
final String description = cmd.getDescription();
final String keyword = cmd.getKeyword();
final Long startIndex = cmd.getStartIndex();
final Long pageSize = cmd.getPageSizeVal();
Boolean forDisplay = cmd.getDisplay();

return _guestOSDao.listGuestOSByCriteria(startIndex, pageSize, id, osCategoryId, description, keyword, forDisplay);
return _guestOSDao.listGuestOSByCriteria(startIndex, pageSize, ids, osCategoryId, description, keyword, forDisplay);
}

@Override
Expand Down
14 changes: 7 additions & 7 deletions server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -4803,12 +4803,13 @@ private String generateHostName(String uuidName) {

private UserVmVO commitUserVm(final boolean isImport, final DataCenter zone, final Host host, final Host lastHost, final VirtualMachineTemplate template, final String hostName, final String displayName, final Account owner,
final Long diskOfferingId, final Long diskSize, final String userData, Long userDataId, String userDataDetails, final Boolean isDisplayVm, final String keyboard,
final long accountId, final long userId, final ServiceOffering offering, final boolean isIso, final String sshPublicKeys, final LinkedHashMap<String, List<NicProfile>> networkNicMap,
final long accountId, final long userId, final ServiceOffering offering, final boolean isIso, final Long guestOsId, final String sshPublicKeys, final LinkedHashMap<String, List<NicProfile>> networkNicMap,
final long id, final String instanceName, final String uuidName, final HypervisorType hypervisorType, final Map<String, String> customParameters,
final Map<String, Map<Integer, String>> extraDhcpOptionMap, final Map<Long, DiskOffering> dataDiskTemplateToDiskOfferingMap,
final Map<String, String> userVmOVFPropertiesMap, final VirtualMachine.PowerState powerState, final boolean dynamicScalingEnabled, String vmType, final Long rootDiskOfferingId, String sshkeypairs,
List<VmDiskInfo> dataDiskInfoList, Volume volume, Snapshot snapshot) throws InsufficientCapacityException {
UserVmVO vm = new UserVmVO(id, instanceName, displayName, template.getId(), hypervisorType, template.getGuestOSId(), offering.isOfferHA(),
Long selectedGuestOsId = guestOsId != null ? guestOsId : template.getGuestOSId();
UserVmVO vm = new UserVmVO(id, instanceName, displayName, template.getId(), hypervisorType, selectedGuestOsId, offering.isOfferHA(),
offering.getLimitCpuUse(), owner.getDomainId(), owner.getId(), userId, offering.getId(), userData, userDataId, userDataDetails, hostName);
vm.setUuid(uuidName);
vm.setDynamicallyScalable(dynamicScalingEnabled);
Expand All @@ -4834,8 +4835,7 @@ private UserVmVO commitUserVm(final boolean isImport, final DataCenter zone, fin
vm.setIsoId(template.getId());
}

long guestOSId = template.getGuestOSId();
GuestOSVO guestOS = _guestOSDao.findById(guestOSId);
GuestOSVO guestOS = _guestOSDao.findById(selectedGuestOsId);
long guestOSCategoryId = guestOS.getCategoryId();
GuestOSCategoryVO guestOSCategory = _guestOSCategoryDao.findById(guestOSCategoryId);
if (hypervisorType.equals(HypervisorType.VMware)) {
Expand Down Expand Up @@ -5093,7 +5093,7 @@ private UserVmVO commitUserVm(final DataCenter zone, final VirtualMachineTemplat
List<VmDiskInfo> dataDiskInfoList, Volume volume, Snapshot snapshot) throws InsufficientCapacityException {
return commitUserVm(false, zone, null, null, template, hostName, displayName, owner,
diskOfferingId, diskSize, userData, userDataId, userDataDetails, isDisplayVm, keyboard,
accountId, userId, offering, isIso, sshPublicKeys, networkNicMap,
accountId, userId, offering, isIso, null, sshPublicKeys, networkNicMap,
id, instanceName, uuidName, hypervisorType, customParameters,
extraDhcpOptionMap, dataDiskTemplateToDiskOfferingMap,
userVmOVFPropertiesMap, null, dynamicScalingEnabled, vmType, rootDiskOfferingId, sshkeypairs, dataDiskInfoList, volume, snapshot);
Expand Down Expand Up @@ -9498,7 +9498,7 @@ private String getInternalName(long accountId, long vmId) {
@Override
public UserVm importVM(final DataCenter zone, final Host host, final VirtualMachineTemplate template, final String instanceNameInternal, final String displayName,
final Account owner, final String userData, final Account caller, final Boolean isDisplayVm, final String keyboard,
final long accountId, final long userId, final ServiceOffering serviceOffering, final String sshPublicKeys,
final long accountId, final long userId, final ServiceOffering serviceOffering, final String sshPublicKeys, final Long guestOsId,
final String hostName, final HypervisorType hypervisorType, final Map<String, String> customParameters,
final VirtualMachine.PowerState powerState, final LinkedHashMap<String, List<NicProfile>> networkNicMap) throws InsufficientCapacityException {
return Transaction.execute((TransactionCallbackWithException<UserVm, InsufficientCapacityException>) status -> {
Expand All @@ -9524,7 +9524,7 @@ public UserVm importVM(final DataCenter zone, final Host host, final VirtualMach
final Boolean dynamicScalingEnabled = checkIfDynamicScalingCanBeEnabled(null, serviceOffering, template, zone.getId());
return commitUserVm(true, zone, host, lastHost, template, hostName, displayName, owner,
null, null, userData, null, null, isDisplayVm, keyboard,
accountId, userId, serviceOffering, template.getFormat().equals(ImageFormat.ISO), sshPublicKeys, networkNicMap,
accountId, userId, serviceOffering, template.getFormat().equals(ImageFormat.ISO), guestOsId, sshPublicKeys, networkNicMap,
id, instanceName, uuidName, hypervisorType, customParameters,
null, null, null, powerState, dynamicScalingEnabled, null, serviceOffering.getDiskOfferingId(), null, null, null, null);
});
Expand Down
Loading
Loading