Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@
import com.vmware.vim25.VirtualEthernetCardNetworkBackingInfo;
import com.vmware.vim25.VirtualEthernetCardOpaqueNetworkBackingInfo;
import com.vmware.vim25.VirtualIDEController;
import com.vmware.vim25.VirtualMachineConfigSpec;
import com.vmware.vim25.VirtualMachineBootOptions;
import com.vmware.vim25.VirtualMachineConfigSpec;
import com.vmware.vim25.VirtualMachineFileInfo;
import com.vmware.vim25.VirtualMachineFileLayoutEx;
import com.vmware.vim25.VirtualMachineFileLayoutExFileInfo;
Expand Down Expand Up @@ -7069,7 +7069,7 @@ private Answer execute(GetUnmanagedInstancesCommand cmd) {
VmwareHypervisorHost hyperHost = getHyperHost(context);

String vmName = cmd.getInstanceName();
List<VirtualMachineMO> vmMos = hyperHost.listVmsOnHyperHost(vmName);
List<VirtualMachineMO> vmMos = hyperHost.listVmsOnHyperHostWithHypervisorName(vmName);

for (VirtualMachineMO vmMo : vmMos) {
if (vmMo == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.HashMap;
import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;

Expand Down Expand Up @@ -217,13 +218,13 @@ public ManagedObjectReference getHyperHostCluster() throws Exception {
}

@Override
public synchronized List<VirtualMachineMO> listVmsOnHyperHost(String vmName) throws Exception {
public synchronized List<VirtualMachineMO> listVmsOnHyperHostWithHypervisorName(String vmName) throws Exception {
List<VirtualMachineMO> vms = new ArrayList<>();
List<ManagedObjectReference> hosts = _context.getVimClient().getDynamicProperty(_mor, "host");
if (hosts != null && hosts.size() > 0) {
if (CollectionUtils.isNotEmpty(hosts)) {
for (ManagedObjectReference morHost : hosts) {
HostMO hostMo = new HostMO(_context, morHost);
vms.addAll(hostMo.listVmsOnHyperHost(vmName));
vms.addAll(hostMo.listVmsOnHyperHostWithHypervisorName(vmName));
}
}
return vms;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;

import com.google.gson.Gson;
Expand Down Expand Up @@ -497,10 +500,10 @@ public String getHostName() throws Exception {
}

@Override
public synchronized List<VirtualMachineMO> listVmsOnHyperHost(String vmName) throws Exception {
public synchronized List<VirtualMachineMO> listVmsOnHyperHostWithHypervisorName(String vmName) throws Exception {
List<VirtualMachineMO> vms = new ArrayList<>();
if (vmName != null && !vmName.isEmpty()) {
vms.add(findVmOnHyperHost(vmName));
if (StringUtils.isNotEmpty(vmName)) {
vms.add(findVmOnHyperHostWithHypervisorName(vmName));
} else {
loadVmCache();
vms.addAll(_vmCache.values());
Expand Down Expand Up @@ -1209,4 +1212,36 @@ public boolean isUefiLegacySupported() throws Exception {
return false;
}

private synchronized VirtualMachineMO findVmOnHyperHostWithHypervisorName(String vmName) throws Exception {
if (s_logger.isDebugEnabled())
s_logger.debug("find VM hypervisor name: " + vmName + " on host");

VirtualMachineMO vmMo = getVmWithHypervisorName(_vmCache.values(), vmName);
if (vmMo != null) {
if (s_logger.isDebugEnabled())
s_logger.debug("VM hypervisor name: " + vmName + " found in host cache");
return vmMo;
}

s_logger.info("VM hypervisor name: " + vmName + " not found in host cache");
loadVmCache();

return getVmWithHypervisorName(_vmCache.values(), vmName);
}

private VirtualMachineMO getVmWithHypervisorName(Collection<VirtualMachineMO> vmList, String vmName) {
if (CollectionUtils.isNotEmpty(vmList)) {
for (VirtualMachineMO vm : vmList) {
try {
if (StringUtils.isNotEmpty(vm.getVmName()) && vm.getVmName().equals(vmName)) {
return vm;
}
} catch (Exception e) {
s_logger.debug("Failed to get VM name, ignoring exception", e);
}
}
}
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public interface VmwareHypervisorHost {

String getHyperHostDefaultGateway() throws Exception;

List<VirtualMachineMO> listVmsOnHyperHost(String name) throws Exception;
List<VirtualMachineMO> listVmsOnHyperHostWithHypervisorName(String name) throws Exception;

VirtualMachineMO findVmOnHyperHost(String name) throws Exception;

Expand Down