Java 类com.vmware.vim25.HostVirtualNic 实例源码

项目:cloudstack    文件:HostMO.java   
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;
}
项目:cloudstack    文件:HostMO.java   
@Override
public VmwareHypervisorHostNetworkSummary getHyperHostNetworkSummary(String managementPortGroup) throws Exception {
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - getHyperHostNetworkSummary(). target MOR: " + _mor.getValue() + ", mgmtPortgroup: " + managementPortGroup);

    VmwareHypervisorHostNetworkSummary summary = new VmwareHypervisorHostNetworkSummary();

    if (getHostType() == VmwareHostType.ESXi) {
        List<VirtualNicManagerNetConfig> netConfigs =
                _context.getVimClient().getDynamicProperty(_mor, "config.virtualNicManagerInfo.netConfig");
        assert (netConfigs != null);

        String dvPortGroupKey;
        String portGroup;
        for (VirtualNicManagerNetConfig netConfig : netConfigs) {
            if (netConfig.getNicType().equals("management")) {
                for (HostVirtualNic nic : netConfig.getCandidateVnic()) {
                    portGroup = nic.getPortgroup();
                    if (portGroup == null || portGroup.isEmpty()) {
                        dvPortGroupKey = nic.getSpec().getDistributedVirtualPort().getPortgroupKey();
                        portGroup = getNetworkName(dvPortGroupKey);
                    }
                    if (portGroup.equalsIgnoreCase(managementPortGroup)) {
                        summary.setHostIp(nic.getSpec().getIp().getIpAddress());
                        summary.setHostNetmask(nic.getSpec().getIp().getSubnetMask());
                        summary.setHostMacAddress(nic.getSpec().getMac());

                        if (s_logger.isTraceEnabled())
                            s_logger.trace("vCenter API trace - getHyperHostNetworkSummary() done(successfully)");
                        return summary;
                    }
                }
            }
        }
    } else {
        // try with ESX path
        List<HostVirtualNic> hostVNics = _context.getVimClient().getDynamicProperty(_mor, "config.network.consoleVnic");

        if (hostVNics != null) {
            for (HostVirtualNic vnic : hostVNics) {
                if (vnic.getPortgroup().equals(managementPortGroup)) {
                    summary.setHostIp(vnic.getSpec().getIp().getIpAddress());
                    summary.setHostNetmask(vnic.getSpec().getIp().getSubnetMask());
                    summary.setHostMacAddress(vnic.getSpec().getMac());

                    if (s_logger.isTraceEnabled())
                        s_logger.trace("vCenter API trace - getHyperHostNetworkSummary() done(successfully)");
                    return summary;
                }
            }
        }
    }

    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - getHyperHostNetworkSummary() done(failed)");
    throw new Exception("Uanble to find management port group " + managementPortGroup);
}