let PingTestCommand support host-ping in addition to ping user VM via VR. Reviewed-By: self
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/24e64ac6 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/24e64ac6 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/24e64ac6 Branch: refs/heads/rbac Commit: 24e64ac62a0e1d4011e03025a3170a3bb259cf2b Parents: 7c7bd09 Author: Kelven Yang <kelv...@gmail.com> Authored: Thu Feb 20 16:43:34 2014 -0800 Committer: Kelven Yang <kelv...@gmail.com> Committed: Fri Feb 28 15:35:59 2014 -0800 ---------------------------------------------------------------------- .../vmware/resource/VmwareResource.java | 49 ++++++++++++++++---- .../cloud/hypervisor/vmware/mo/ClusterMO.java | 12 ++--- .../com/cloud/hypervisor/vmware/mo/HostMO.java | 16 +++++++ 3 files changed, 60 insertions(+), 17 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/24e64ac6/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java ---------------------------------------------------------------------- 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 9e12105..89947df 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<Boolean, String> 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<Boolean, String> 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<Pair<ManagedObjectReference, String>> hosts = clusterMo.getClusterHosts(); + for (Pair<ManagedObjectReference, String> 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) { http://git-wip-us.apache.org/repos/asf/cloudstack/blob/24e64ac6/vmware-base/src/com/cloud/hypervisor/vmware/mo/ClusterMO.java ---------------------------------------------------------------------- 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 49ee7c4..1b72b73 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"); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/24e64ac6/vmware-base/src/com/cloud/hypervisor/vmware/mo/HostMO.java ---------------------------------------------------------------------- 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 a32992a..298f560 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<HostVirtualNic> nics = netInfo.getVnic(); + for (HostVirtualNic nic : nics) { + if (nic.getPortgroup().equals(managementPortGroup)) { + HostIpConfig ipConfig = nic.getSpec().getIp(); + + return ipConfig.getIpAddress(); + } + } + + return null; + } }