mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
let PingTestCommand support host-ping in addition to ping user VM via VR. Reviewed-By: self
This commit is contained in:
parent
7c7bd0934a
commit
24e64ac62a
@ -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) {
|
||||
|
||||
@ -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");
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user