Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@
@Param(description = "the operating system of the virtual machine")
private String operatingSystem;

@SerializedName(ApiConstants.BOOT_MODE)
@Param(description = "indicates the boot mode")
private String bootMode;

@SerializedName(ApiConstants.BOOT_TYPE)
@Param(description = "indicates the boot type")
private String bootType;

@SerializedName(ApiConstants.DISK)
@Param(description = "the list of disks associated with the virtual machine", responseObject = UnmanagedInstanceDiskResponse.class)
private Set<UnmanagedInstanceDiskResponse> disks;
Expand Down Expand Up @@ -211,4 +219,20 @@
public void addNic(NicResponse nic) {
this.nics.add(nic);
}

public String getBootMode() {
return bootMode;
}

Check warning on line 225 in api/src/main/java/org/apache/cloudstack/api/response/UnmanagedInstanceResponse.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/apache/cloudstack/api/response/UnmanagedInstanceResponse.java#L223-L225

Added lines #L223 - L225 were not covered by tests

public void setBootMode(String bootMode) {

Check warning on line 227 in api/src/main/java/org/apache/cloudstack/api/response/UnmanagedInstanceResponse.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/apache/cloudstack/api/response/UnmanagedInstanceResponse.java#L227

Added line #L227 was not covered by tests
this.bootMode = bootMode;
}

public String getBootType() {
return bootType;
}

Check warning on line 233 in api/src/main/java/org/apache/cloudstack/api/response/UnmanagedInstanceResponse.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/apache/cloudstack/api/response/UnmanagedInstanceResponse.java#L231-L233

Added lines #L231 - L233 were not covered by tests

public void setBootType(String bootType) {

Check warning on line 235 in api/src/main/java/org/apache/cloudstack/api/response/UnmanagedInstanceResponse.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/apache/cloudstack/api/response/UnmanagedInstanceResponse.java#L235

Added line #L235 was not covered by tests
this.bootType = bootType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@

private String vncPassword;

private String bootType;
private String bootMode;

public String getName() {
return name;
}
Expand Down Expand Up @@ -189,6 +192,22 @@
this.vncPassword = vncPassword;
}

public String getBootType() {
return bootType;
}

Check warning on line 197 in api/src/main/java/org/apache/cloudstack/vm/UnmanagedInstanceTO.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/apache/cloudstack/vm/UnmanagedInstanceTO.java#L195-L197

Added lines #L195 - L197 were not covered by tests

public void setBootType(String bootType) {
this.bootType = bootType;
}

Check warning on line 201 in api/src/main/java/org/apache/cloudstack/vm/UnmanagedInstanceTO.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/apache/cloudstack/vm/UnmanagedInstanceTO.java#L199-L201

Added lines #L199 - L201 were not covered by tests

public String getBootMode() {
return bootMode;
}

Check warning on line 205 in api/src/main/java/org/apache/cloudstack/vm/UnmanagedInstanceTO.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/apache/cloudstack/vm/UnmanagedInstanceTO.java#L203-L205

Added lines #L203 - L205 were not covered by tests

public void setBootMode(String bootMode) {
this.bootMode = bootMode;
}

Check warning on line 209 in api/src/main/java/org/apache/cloudstack/vm/UnmanagedInstanceTO.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/apache/cloudstack/vm/UnmanagedInstanceTO.java#L207-L209

Added lines #L207 - L209 were not covered by tests

public static class Disk {
private String diskId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import javax.naming.ConfigurationException;
import javax.persistence.EntityExistsException;

import com.cloud.hypervisor.vmware.mo.VirtualMachineMO;
import com.cloud.hypervisor.vmware.util.VmwareClient;
import org.apache.cloudstack.api.command.admin.zone.AddVmwareDcCmd;
import org.apache.cloudstack.api.command.admin.zone.ImportVsphereStoragePoliciesCmd;
Expand Down Expand Up @@ -1587,14 +1588,26 @@
return compatiblePools;
}

@Override
public List<UnmanagedInstanceTO> listVMsInDatacenter(ListVmwareDcVmsCmd cmd) {
private static class VcenterData {
public final String vcenter;
public final String datacenterName;
public final String username;
public final String password;

public VcenterData(String vcenter, String datacenterName, String username, String password) {
this.vcenter = vcenter;
this.datacenterName = datacenterName;
this.username = username;
this.password = password;
}

Check warning on line 1602 in plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java#L1597-L1602

Added lines #L1597 - L1602 were not covered by tests
}

private VcenterData getVcenterData(ListVmwareDcVmsCmd cmd) {

Check warning on line 1605 in plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java#L1605

Added line #L1605 was not covered by tests
String vcenter = cmd.getVcenter();
String datacenterName = cmd.getDatacenterName();
String username = cmd.getUsername();
String password = cmd.getPassword();
Long existingVcenterId = cmd.getExistingVcenterId();
String keyword = cmd.getKeyword();

if ((existingVcenterId == null && StringUtils.isBlank(vcenter)) ||
(existingVcenterId != null && StringUtils.isNotBlank(vcenter))) {
Expand All @@ -1615,34 +1628,67 @@
username = vmwareDc.getUser();
password = vmwareDc.getPassword();
}
VcenterData vmwaredc = new VcenterData(vcenter, datacenterName, username, password);
return vmwaredc;
}

Check warning on line 1633 in plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java#L1631-L1633

Added lines #L1631 - L1633 were not covered by tests

private static VmwareContext getVmwareContext(String vcenter, String username, String password) throws Exception {
s_logger.debug(String.format("Connecting to the VMware vCenter %s", vcenter));
String serviceUrl = String.format("https://%s/sdk/vimService", vcenter);
VmwareClient vimClient = new VmwareClient(vcenter);
vimClient.connect(serviceUrl, username, password);
return new VmwareContext(vimClient, vcenter);
}

Check warning on line 1641 in plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java#L1635-L1641

Added lines #L1635 - L1641 were not covered by tests

@Override
public List<UnmanagedInstanceTO> listVMsInDatacenter(ListVmwareDcVmsCmd cmd) {
VcenterData vmwareDC = getVcenterData(cmd);
String vcenter = vmwareDC.vcenter;
String username = vmwareDC.username;
String password = vmwareDC.password;
String datacenterName = vmwareDC.datacenterName;
String keyword = cmd.getKeyword();
String esxiHostName = cmd.getHostName();
String virtualMachineName = cmd.getInstanceName();

Check warning on line 1652 in plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java#L1644-L1652

Added lines #L1644 - L1652 were not covered by tests

try {
s_logger.debug(String.format("Connecting to the VMware datacenter %s at vCenter %s to retrieve VMs",
datacenterName, vcenter));
String serviceUrl = String.format("https://%s/sdk/vimService", vcenter);
VmwareClient vimClient = new VmwareClient(vcenter);
vimClient.connect(serviceUrl, username, password);
VmwareContext context = new VmwareContext(vimClient, vcenter);

DatacenterMO dcMo = new DatacenterMO(context, datacenterName);
ManagedObjectReference dcMor = dcMo.getMor();
if (dcMor == null) {
String msg = String.format("Unable to find VMware datacenter %s in vCenter %s",
datacenterName, vcenter);
s_logger.error(msg);
throw new InvalidParameterValueException(msg);
VmwareContext context = getVmwareContext(vcenter, username, password);
DatacenterMO dcMo = getDatacenterMO(context, vcenter, datacenterName);

Check warning on line 1656 in plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java#L1655-L1656

Added lines #L1655 - L1656 were not covered by tests

List<UnmanagedInstanceTO> instances;

Check warning on line 1658 in plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java#L1658

Added line #L1658 was not covered by tests
if (StringUtils.isNotBlank(esxiHostName) && StringUtils.isNotBlank(virtualMachineName)) {
ManagedObjectReference hostMor = dcMo.findHost(esxiHostName);

Check warning on line 1660 in plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java#L1660

Added line #L1660 was not covered by tests
if (hostMor == null) {
String errorMsg = String.format("Cannot find a host with name %s on vcenter %s", esxiHostName, vcenter);
s_logger.error(errorMsg);
throw new CloudRuntimeException(errorMsg);

Check warning on line 1664 in plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java#L1662-L1664

Added lines #L1662 - L1664 were not covered by tests
}
HostMO hostMO = new HostMO(context, hostMor);
VirtualMachineMO vmMo = hostMO.findVmOnHyperHost(virtualMachineName);
instances = Collections.singletonList(VmwareHelper.getUnmanagedInstance(hostMO, vmMo));
} else {
instances = dcMo.getAllVmsOnDatacenter(keyword);

Check warning on line 1670 in plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java#L1666-L1670

Added lines #L1666 - L1670 were not covered by tests
}
List<UnmanagedInstanceTO> instances = dcMo.getAllVmsOnDatacenter();
return StringUtils.isBlank(keyword) ? instances :
instances.stream().filter(x -> x.getName().toLowerCase().contains(keyword.toLowerCase())).collect(Collectors.toList());
return instances;

Check warning on line 1672 in plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java#L1672

Added line #L1672 was not covered by tests
} catch (Exception e) {
String errorMsg = String.format("Error retrieving stopped VMs from the VMware VC %s datacenter %s: %s",
String errorMsg = String.format("Error retrieving VMs from the VMware VC %s datacenter %s: %s",

Check warning on line 1674 in plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java#L1674

Added line #L1674 was not covered by tests
vcenter, datacenterName, e.getMessage());
s_logger.error(errorMsg, e);
throw new CloudRuntimeException(errorMsg);
}
}

private static DatacenterMO getDatacenterMO(VmwareContext context, String vcenter, String datacenterName) throws Exception {
DatacenterMO dcMo = new DatacenterMO(context, datacenterName);
ManagedObjectReference dcMor = dcMo.getMor();

Check warning on line 1683 in plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java#L1681-L1683

Added lines #L1681 - L1683 were not covered by tests
if (dcMor == null) {
String msg = String.format("Unable to find VMware datacenter %s in vCenter %s", datacenterName, vcenter);
s_logger.error(msg);
throw new InvalidParameterValueException(msg);

Check warning on line 1687 in plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java#L1685-L1687

Added lines #L1685 - L1687 were not covered by tests
}
return dcMo;
}

Check warning on line 1690 in plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java#L1689-L1690

Added lines #L1689 - L1690 were not covered by tests

@Override
public boolean hasNexusVSM(Long clusterId) {
ClusterVSMMapVO vsmMapVo = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@
@Parameter(name = ApiConstants.PASSWORD, type = CommandType.STRING, description = "The password for specified username.")
private String password;

@Parameter(name = ApiConstants.HOST_NAME, type = CommandType.STRING, description = "Name of the host on vCenter. Must be set along with the instancename parameter")
private String hostName;

@Parameter(name = ApiConstants.INSTANCE_NAME, type = CommandType.STRING, description = "Name of the VM on vCenter. Must be set along with the hostname parameter")
private String instanceName;

public String getVcenter() {
return vcenter;
}
Expand All @@ -86,10 +92,18 @@
return datacenterName;
}

public String getHostName() {
return hostName;
}

Check warning on line 97 in plugins/hypervisors/vmware/src/main/java/org/apache/cloudstack/api/command/admin/zone/ListVmwareDcVmsCmd.java

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/vmware/src/main/java/org/apache/cloudstack/api/command/admin/zone/ListVmwareDcVmsCmd.java#L95-L97

Added lines #L95 - L97 were not covered by tests

public Long getExistingVcenterId() {
return existingVcenterId;
}

public String getInstanceName() {
return instanceName;
}

Check warning on line 105 in plugins/hypervisors/vmware/src/main/java/org/apache/cloudstack/api/command/admin/zone/ListVmwareDcVmsCmd.java

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/vmware/src/main/java/org/apache/cloudstack/api/command/admin/zone/ListVmwareDcVmsCmd.java#L103-L105

Added lines #L103 - L105 were not covered by tests

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
checkParameters();
Expand Down Expand Up @@ -125,6 +139,11 @@
throw new ServerApiException(ApiErrorCode.PARAM_ERROR,
"Please set all the information for a vCenter IP/Name, datacenter, username and password");
}
if ((StringUtils.isNotBlank(instanceName) && StringUtils.isBlank(hostName)) ||
(StringUtils.isBlank(instanceName) && StringUtils.isNotBlank(hostName))) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR,

Check warning on line 144 in plugins/hypervisors/vmware/src/main/java/org/apache/cloudstack/api/command/admin/zone/ListVmwareDcVmsCmd.java

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/vmware/src/main/java/org/apache/cloudstack/api/command/admin/zone/ListVmwareDcVmsCmd.java#L144

Added line #L144 was not covered by tests
"Please set the hostname parameter along with the instancename parameter");
}
}

@Override
Expand Down
2 changes: 2 additions & 0 deletions server/src/main/java/com/cloud/api/ApiResponseHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -5145,6 +5145,8 @@ public UnmanagedInstanceResponse createUnmanagedInstanceResponse(UnmanagedInstan
response.setMemory(instance.getMemory());
response.setOperatingSystemId(instance.getOperatingSystemId());
response.setOperatingSystem(instance.getOperatingSystem());
response.setBootMode(instance.getBootMode());
response.setBootType(instance.getBootType());
response.setObjectName("unmanagedinstance");

if (instance.getDisks() != null) {
Expand Down
28 changes: 28 additions & 0 deletions ui/src/views/tools/ManageInstances.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1302,6 +1302,31 @@ export default {
this.fetchInstances()
}
},
fetchVmwareInstanceForKVMMigration (vmname, hostname) {
const params = {}
if (this.isMigrateFromVmware && this.selectedVmwareVcenter) {
if (this.selectedVmwareVcenter.vcenter) {
params.datacentername = this.selectedVmwareVcenter.datacentername
params.vcenter = this.selectedVmwareVcenter.vcenter
params.username = this.selectedVmwareVcenter.username
params.password = this.selectedVmwareVcenter.password
} else {
params.existingvcenterid = this.selectedVmwareVcenter.existingvcenterid
}
params.instancename = vmname
params.hostname = hostname
}
api('listVmwareDcVms', params).then(json => {
const response = json.listvmwaredcvmsresponse
this.selectedUnmanagedInstance = response.unmanagedinstance[0]
this.selectedUnmanagedInstance.ostypename = this.selectedUnmanagedInstance.osdisplayname
this.selectedUnmanagedInstance.state = this.selectedUnmanagedInstance.powerstate
}).catch(error => {
this.$notifyError(error)
}).finally(() => {
this.loading = false
})
},
onManageInstanceAction () {
this.selectedUnmanagedInstance = {}
if (this.unmanagedInstances.length > 0 &&
Expand All @@ -1319,6 +1344,9 @@ export default {
}
})
this.showUnmanageForm = false
} else if (this.isMigrateFromVmware) {
this.fetchVmwareInstanceForKVMMigration(this.selectedUnmanagedInstance.name, this.selectedUnmanagedInstance.hostname)
this.showUnmanageForm = true
} else {
this.showUnmanageForm = true
}
Expand Down
7 changes: 7 additions & 0 deletions ui/src/views/tools/SelectVmwareVcenter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ export default {
} else {
params.existingvcenterid = this.selectedExistingVcenterId
}
params.page = 1
params.pagesize = 10
api('listVmwareDcVms', params).then(json => {
const obj = {
params: params,
Expand Down Expand Up @@ -265,6 +267,11 @@ export default {
this.loading = false
})
},
onSelectExternalVmwareDatacenter (value) {
if (this.vcenterSelectedOption === 'new' && !(this.vcenter === '' || this.datacentername === '' || this.username === '' || this.password === '')) {
this.listVmwareDatacenterVms()
}
},
onSelectExistingVmwareDatacenter (value) {
this.selectedExistingVcenterId = value
},
Expand Down
Loading
Loading