Search in sources :

Example 1 with VmwareHypervisorHostNetworkSummary

use of com.cloud.hypervisor.vmware.mo.VmwareHypervisorHostNetworkSummary in project cloudstack by apache.

the class VmwareResource method fillHostNetworkInfo.

private void fillHostNetworkInfo(VmwareContext serviceContext, StartupRoutingCommand cmd) throws RuntimeFaultFaultMsg, RemoteException {
    try {
        VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());
        assert (hyperHost instanceof HostMO);
        VmwareManager mgr = hyperHost.getContext().getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
        VmwareHypervisorHostNetworkSummary summary = hyperHost.getHyperHostNetworkSummary(mgr.getManagementPortGroupByHost((HostMO) hyperHost));
        if (summary == null) {
            throw new Exception("No ESX(i) host found");
        }
        if (s_logger.isInfoEnabled()) {
            s_logger.info("Startup report on host network info. " + _gson.toJson(summary));
        }
        cmd.setPrivateIpAddress(summary.getHostIp());
        cmd.setPrivateNetmask(summary.getHostNetmask());
        cmd.setPrivateMacAddress(summary.getHostMacAddress());
        cmd.setStorageIpAddress(summary.getHostIp());
        cmd.setStorageNetmask(summary.getHostNetmask());
        cmd.setStorageMacAddress(summary.getHostMacAddress());
    } catch (Throwable e) {
        String msg = "querying host network info failed due to " + VmwareHelper.getExceptionMessage(e);
        s_logger.error(msg, e);
        throw new CloudRuntimeException(msg);
    }
}
Also used : HostMO(com.cloud.hypervisor.vmware.mo.HostMO) VmwareManager(com.cloud.hypervisor.vmware.manager.VmwareManager) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VmwareHypervisorHostNetworkSummary(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHostNetworkSummary) VmwareHypervisorHost(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost) ConnectException(java.net.ConnectException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) InternalErrorException(com.cloud.exception.InternalErrorException) CloudException(com.cloud.exception.CloudException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(javax.naming.ConfigurationException)

Example 2 with VmwareHypervisorHostNetworkSummary

use of com.cloud.hypervisor.vmware.mo.VmwareHypervisorHostNetworkSummary in project cloudstack by apache.

the class VmwareResource method getTargetHyperHost.

private VmwareHypervisorHost getTargetHyperHost(DatacenterMO dcMo, String destIp) throws Exception {
    VmwareManager mgr = dcMo.getContext().getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
    List<ObjectContent> ocs = dcMo.getHostPropertiesOnDatacenterHostFolder(new String[] { "name", "parent" });
    if (ocs != null && ocs.size() > 0) {
        for (ObjectContent oc : ocs) {
            HostMO hostMo = new HostMO(dcMo.getContext(), oc.getObj());
            VmwareHypervisorHostNetworkSummary netSummary = hostMo.getHyperHostNetworkSummary(mgr.getManagementPortGroupByHost(hostMo));
            if (destIp.equalsIgnoreCase(netSummary.getHostIp())) {
                return new HostMO(dcMo.getContext(), oc.getObj());
            }
        }
    }
    throw new Exception("Unable to locate dest host by " + destIp);
}
Also used : ObjectContent(com.vmware.vim25.ObjectContent) VmwareManager(com.cloud.hypervisor.vmware.manager.VmwareManager) HostMO(com.cloud.hypervisor.vmware.mo.HostMO) VmwareHypervisorHostNetworkSummary(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHostNetworkSummary) ConnectException(java.net.ConnectException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) InternalErrorException(com.cloud.exception.InternalErrorException) CloudException(com.cloud.exception.CloudException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(javax.naming.ConfigurationException)

Example 3 with VmwareHypervisorHostNetworkSummary

use of com.cloud.hypervisor.vmware.mo.VmwareHypervisorHostNetworkSummary in project cloudstack by apache.

the class VmwareSecondaryStorageResourceHandler method getHyperHost.

@Override
public VmwareHypervisorHost getHyperHost(VmwareContext context, Command cmd) {
    String guid = cmd.getContextParam("guid");
    assert (guid != null);
    String[] tokens = guid.split("@");
    assert (tokens != null && tokens.length == 2);
    ManagedObjectReference morHyperHost = new ManagedObjectReference();
    String[] hostTokens = tokens[0].split(":");
    if (hostTokens == null || hostTokens.length != 2) {
        s_logger.error("Invalid content in command context parameter guid");
        return null;
    }
    morHyperHost.setType(hostTokens[0]);
    morHyperHost.setValue(hostTokens[1]);
    if (morHyperHost.getType().equalsIgnoreCase("HostSystem")) {
        HostMO hostMo = new HostMO(context, morHyperHost);
        try {
            ManagedObjectReference mor = hostMo.getHyperHostCluster();
            ClusterMO clusterMo = new ClusterMO(hostMo.getContext(), mor);
            List<Pair<ManagedObjectReference, String>> hostsInCluster = clusterMo.getClusterHosts();
            for (Pair<ManagedObjectReference, String> hostPair : hostsInCluster) {
                HostMO hostIteratorMo = new HostMO(hostMo.getContext(), hostPair.first());
                VmwareHypervisorHostNetworkSummary netSummary = hostIteratorMo.getHyperHostNetworkSummary(hostIteratorMo.getHostType() == VmwareHostType.ESXi ? cmd.getContextParam("manageportgroup") : cmd.getContextParam("serviceconsole"));
                _resource.ensureOutgoingRuleForAddress(netSummary.getHostIp());
                s_logger.info("Setup firewall rule for host: " + netSummary.getHostIp());
            }
        } catch (Throwable e) {
            s_logger.warn("Unable to retrive host network information due to exception " + e.toString() + ", host: " + hostTokens[0] + "-" + hostTokens[1]);
        }
        return hostMo;
    }
    assert (false);
    return new ClusterMO(context, morHyperHost);
}
Also used : HostMO(com.cloud.hypervisor.vmware.mo.HostMO) VmwareHypervisorHostNetworkSummary(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHostNetworkSummary) ClusterMO(com.cloud.hypervisor.vmware.mo.ClusterMO) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) Pair(com.cloud.utils.Pair)

Aggregations

HostMO (com.cloud.hypervisor.vmware.mo.HostMO)3 VmwareHypervisorHostNetworkSummary (com.cloud.hypervisor.vmware.mo.VmwareHypervisorHostNetworkSummary)3 CloudException (com.cloud.exception.CloudException)2 InternalErrorException (com.cloud.exception.InternalErrorException)2 VmwareManager (com.cloud.hypervisor.vmware.manager.VmwareManager)2 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ConnectException (java.net.ConnectException)2 RemoteException (java.rmi.RemoteException)2 ConfigurationException (javax.naming.ConfigurationException)2 ClusterMO (com.cloud.hypervisor.vmware.mo.ClusterMO)1 VmwareHypervisorHost (com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost)1 Pair (com.cloud.utils.Pair)1 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)1 ObjectContent (com.vmware.vim25.ObjectContent)1