diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java index 9e1210515df..89947df4a8e 100755 --- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java +++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java @@ -4097,18 +4097,47 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa if (s_logger.isInfoEnabled()) { s_logger.info("Executing resource PingTestCommand: " + _gson.toJson(cmd)); } + String controlIp = cmd.getRouterIp(); - String args = " -c 1 -n -q " + cmd.getPrivateIp(); - try { - VmwareManager mgr = getServiceContext().getStockObject(VmwareManager.CONTEXT_STOCK_NAME); - Pair result = SshHelper.sshExecute(controlIp, DefaultDomRSshPort, "root", mgr.getSystemVMKeyFile(), null, "/bin/ping" + args); - if (result.first()) - return new Answer(cmd); - } catch (Exception e) { - s_logger.error( - "Unable to execute ping command on DomR (" + controlIp + "), domR may not be ready yet. failure due to " + VmwareHelper.getExceptionMessage(e), e); + if (controlIp != null) { + String args = " -c 1 -n -q " + cmd.getPrivateIp(); + try { + VmwareManager mgr = getServiceContext().getStockObject(VmwareManager.CONTEXT_STOCK_NAME); + Pair result = SshHelper.sshExecute(controlIp, DefaultDomRSshPort, "root", mgr.getSystemVMKeyFile(), null, "/bin/ping" + args); + if (result.first()) + return new Answer(cmd); + } catch (Exception e) { + s_logger.error("Unable to execute ping command on DomR (" + controlIp + "), domR may not be ready yet. failure due to " + + VmwareHelper.getExceptionMessage(e), e); + } + return new Answer(cmd, false, "PingTestCommand failed"); + } else { + VmwareContext context = getServiceContext(); + VmwareHypervisorHost hyperHost = getHyperHost(context); + + try { + HostMO hostMo = (HostMO)hyperHost; + ClusterMO clusterMo = new ClusterMO(context, hostMo.getHyperHostCluster()); + VmwareManager mgr = context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME); + + List> hosts = clusterMo.getClusterHosts(); + for (Pair entry : hosts) { + HostMO hostInCluster = new HostMO(context, entry.first()); + String hostIp = hostInCluster.getHostManagementIp(mgr.getManagementPortGroupName()); + if (hostIp != null && hostIp.equals(cmd.getComputingHostIp())) { + if (hostInCluster.isHyperHostConnected()) + return new Answer(cmd); + else + new Answer(cmd, false, "PingTestCommand failed"); + } + } + } catch (Exception e) { + s_logger.error("Unable to execute ping command on host (" + cmd.getComputingHostIp() + "). failure due to " + + VmwareHelper.getExceptionMessage(e), e); + } + + return new Answer(cmd, false, "PingTestCommand failed"); } - return new Answer(cmd, false, "PingTestCommand failed"); } protected Answer execute(CheckOnHostCommand cmd) { diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/mo/ClusterMO.java b/vmware-base/src/com/cloud/hypervisor/vmware/mo/ClusterMO.java index 49ee7c4ec51..1b72b73bd88 100755 --- a/vmware-base/src/com/cloud/hypervisor/vmware/mo/ClusterMO.java +++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/ClusterMO.java @@ -57,6 +57,7 @@ import com.cloud.utils.exception.CloudRuntimeException; // public class ClusterMO extends BaseMO implements VmwareHypervisorHost { private static final Logger s_logger = Logger.getLogger(ClusterMO.class); + private ManagedObjectReference _environmentBrowser = null; public ClusterMO(VmwareContext context, ManagedObjectReference morCluster) { super(context, morCluster); @@ -124,8 +125,7 @@ public class ClusterMO extends BaseMO implements VmwareHypervisorHost { @Override public ObjectContent[] getVmPropertiesOnHyperHost(String[] propertyPaths) throws Exception { if (s_logger.isTraceEnabled()) - s_logger.trace("vCenter API trace - retrieveProperties() for VM properties. target MOR: " + _mor.getValue() + ", properties: " + - new Gson().toJson(propertyPaths)); + s_logger.trace("vCenter API trace - retrieveProperties() for VM properties. target MOR: " + _mor.getValue() + ", properties: " + new Gson().toJson(propertyPaths)); PropertySpec pSpec = new PropertySpec(); pSpec.setType("VirtualMachine"); @@ -163,8 +163,7 @@ public class ClusterMO extends BaseMO implements VmwareHypervisorHost { @Override public ObjectContent[] getDatastorePropertiesOnHyperHost(String[] propertyPaths) throws Exception { if (s_logger.isTraceEnabled()) - s_logger.trace("vCenter API trace - retrieveProperties() on Datastore properties. target MOR: " + _mor.getValue() + ", properties: " + - new Gson().toJson(propertyPaths)); + s_logger.trace("vCenter API trace - retrieveProperties() on Datastore properties. target MOR: " + _mor.getValue() + ", properties: " + new Gson().toJson(propertyPaths)); PropertySpec pSpec = new PropertySpec(); pSpec.setType("Datastore"); @@ -193,10 +192,9 @@ public class ClusterMO extends BaseMO implements VmwareHypervisorHost { return properties.toArray(new ObjectContent[properties.size()]); } - private ObjectContent[] getHostPropertiesOnCluster(String[] propertyPaths) throws Exception { + public ObjectContent[] getHostPropertiesOnCluster(String[] propertyPaths) throws Exception { if (s_logger.isTraceEnabled()) - s_logger.trace("vCenter API trace - retrieveProperties() on Host properties. target MOR: " + _mor.getValue() + ", properties: " + - new Gson().toJson(propertyPaths)); + s_logger.trace("vCenter API trace - retrieveProperties() on Host properties. target MOR: " + _mor.getValue() + ", properties: " + new Gson().toJson(propertyPaths)); PropertySpec pSpec = new PropertySpec(); pSpec.setType("HostSystem"); diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/mo/HostMO.java b/vmware-base/src/com/cloud/hypervisor/vmware/mo/HostMO.java index a32992aeb33..298f560388c 100755 --- a/vmware-base/src/com/cloud/hypervisor/vmware/mo/HostMO.java +++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/HostMO.java @@ -39,6 +39,7 @@ import com.vmware.vim25.HostFirewallInfo; import com.vmware.vim25.HostFirewallRuleset; import com.vmware.vim25.HostHardwareSummary; import com.vmware.vim25.HostHyperThreadScheduleInfo; +import com.vmware.vim25.HostIpConfig; import com.vmware.vim25.HostIpRouteEntry; import com.vmware.vim25.HostListSummaryQuickStats; import com.vmware.vim25.HostNetworkInfo; @@ -1043,4 +1044,19 @@ public class HostMO extends BaseMO implements VmwareHypervisorHost { firewallMo.refreshFirewall(); } } + + public String getHostManagementIp(String managementPortGroup) throws Exception { + HostNetworkInfo netInfo = getHostNetworkInfo(); + + List nics = netInfo.getVnic(); + for (HostVirtualNic nic : nics) { + if (nic.getPortgroup().equals(managementPortGroup)) { + HostIpConfig ipConfig = nic.getSpec().getIp(); + + return ipConfig.getIpAddress(); + } + } + + return null; + } }