Search in sources :

Example 1 with HostVirtualNic

use of com.vmware.vim25.HostVirtualNic in project opennms by OpenNMS.

the class VmwareViJavaAccessTest method setUp.

@Before
public void setUp() throws Exception {
    // setup required objects
    managedObjectReferenceManagedEntity = new ManagedObjectReference();
    managedObjectReferenceManagedEntity.setType("ManagedEntity");
    managedObjectReferenceManagedEntity.setVal("moIdMe");
    managedObjectReferenceVirtualMachine = new ManagedObjectReference();
    managedObjectReferenceVirtualMachine.setType("VirtualMachine");
    managedObjectReferenceVirtualMachine.setVal("moIdVm");
    managedObjectReferenceHostSystem = new ManagedObjectReference();
    managedObjectReferenceHostSystem.setType("HostSystem");
    managedObjectReferenceHostSystem.setVal("moIdHs");
    // setup VmwareViJavaAccess
    vmwareViJavaAccess = new VmwareViJavaAccess("hostname", "username", "password") {

        @Override
        protected void relax() {
        }
    };
    // setup PerformanceManager
    mockPerformanceManager = createMock(PerformanceManager.class);
    // setup ServiceInstance mock
    mockServiceInstance = createMock(ServiceInstance.class);
    // setup ServerConnection
    mockServerConnection = new ServerConnection(new URL("https://hostname/sdk"), new VimPortType(new WSClient("https://hostname/sdk") {

        @Override
        protected SSLSocketFactory getTrustAllSocketFactory(boolean ignoreCert) throws RemoteException {
            return null;
        }
    }), mockServiceInstance);
    // setup AboutInfo
    mockAboutInfo = createMock(AboutInfo.class);
    expectNew(ServiceInstance.class, new Class<?>[] { URL.class, String.class, String.class }, new URL("https://hostname/sdk"), "username", "password").andReturn(mockServiceInstance).anyTimes();
    expect(mockServiceInstance.getServerConnection()).andReturn(mockServerConnection).anyTimes();
    expect(mockServiceInstance.getPerformanceManager()).andReturn(mockPerformanceManager).anyTimes();
    expect(mockServiceInstance.getAboutInfo()).andReturn(mockAboutInfo).anyTimes();
    managedEntity = new ManagedEntity(null, managedObjectReferenceManagedEntity);
    virtualMachine = new VirtualMachine(null, managedObjectReferenceVirtualMachine);
    hostSystem = new HostSystem(null, managedObjectReferenceHostSystem);
    // setup MorUtil
    mockStatic(MorUtil.class);
    expect(MorUtil.createExactManagedEntity(mockServerConnection, managedObjectReferenceManagedEntity)).andReturn(managedEntity).anyTimes();
    expect(MorUtil.createExactManagedEntity(mockServerConnection, managedObjectReferenceVirtualMachine)).andReturn(virtualMachine).anyTimes();
    expect(MorUtil.createExactManagedEntity(mockServerConnection, managedObjectReferenceHostSystem)).andReturn(hostSystem).anyTimes();
    // setup about info
    expect(mockAboutInfo.getApiVersion()).andReturn("2.x");
    expect(mockAboutInfo.getApiVersion()).andReturn("3.x");
    expect(mockAboutInfo.getApiVersion()).andReturn("4.x");
    expect(mockAboutInfo.getApiVersion()).andReturn("5.x");
    expect(mockAboutInfo.getApiVersion()).andReturn("6.x");
    expect(mockAboutInfo.getApiVersion()).andReturn("x");
    // setup performance data
    int refreshRate = 100;
    int metricCount = 15;
    int instanceModifier = 5;
    perfQuerySpec = new PerfQuerySpec();
    perfQuerySpec.setEntity(managedEntity.getMOR());
    perfQuerySpec.setMaxSample(new Integer(1));
    perfQuerySpec.setIntervalId(refreshRate);
    perfEntityMetricBases = new PerfEntityMetricBase[metricCount];
    perfCounterInfos = new PerfCounterInfo[metricCount];
    for (int i = 0; i < metricCount; i++) {
        ElementDescription groupInfo = new ElementDescription();
        groupInfo.setKey("key" + i);
        ElementDescription nameInfo = new ElementDescription();
        nameInfo.setKey("name" + i);
        perfCounterInfos[i] = new PerfCounterInfo();
        perfCounterInfos[i].setKey(i);
        perfCounterInfos[i].setGroupInfo(groupInfo);
        perfCounterInfos[i].setNameInfo(nameInfo);
        perfCounterInfos[i].setRollupType(PerfSummaryType.average);
        perfEntityMetricBases[i] = new PerfEntityMetric();
        PerfMetricIntSeries[] perfMetricIntSeries;
        int instanceCount = (i % instanceModifier) + 1;
        perfMetricIntSeries = new PerfMetricIntSeries[instanceCount];
        for (int b = 0; b < instanceCount; b++) {
            PerfMetricId perfMetricId = new PerfMetricId();
            perfMetricId.setCounterId(i);
            if (instanceCount == 1) {
                perfMetricId.setInstance(null);
            } else {
                perfMetricId.setInstance("instance" + b);
            }
            perfMetricIntSeries[b] = new PerfMetricIntSeries();
            perfMetricIntSeries[b].setValue(new long[] { (long) 42 });
            perfMetricIntSeries[b].setId(perfMetricId);
        }
        ((PerfEntityMetric) perfEntityMetricBases[i]).setValue(perfMetricIntSeries);
    }
    // setup PerfProviderSummary
    mockPerfProviderSummary = createMock(PerfProviderSummary.class);
    expect(mockPerformanceManager.queryPerfProviderSummary(managedEntity)).andReturn(mockPerfProviderSummary).anyTimes();
    expect(mockPerfProviderSummary.getRefreshRate()).andReturn(refreshRate).anyTimes();
    expect(mockPerformanceManager.getPerfCounter()).andReturn(perfCounterInfos).anyTimes();
    expect(mockPerformanceManager.queryPerf(anyObject(PerfQuerySpec[].class))).andReturn(perfEntityMetricBases).anyTimes();
    // setup network info
    HostNetworkInfo hostNetworkInfo = new HostNetworkInfo();
    int numberOfVnics = 3;
    HostVirtualNic[] hostVirtualNics = new HostVirtualNic[numberOfVnics];
    for (int i = 0; i < numberOfVnics; i++) {
        HostVirtualNicSpec hostVirtualNicSpec = new HostVirtualNicSpec();
        HostIpConfig hostIpConfig = new HostIpConfig();
        hostIpConfig.setIpAddress("192.168.1." + (i + 1));
        hostVirtualNicSpec.setIp(hostIpConfig);
        hostVirtualNics[i] = new HostVirtualNic();
        hostVirtualNics[i].setSpec(hostVirtualNicSpec);
    }
    hostNetworkInfo.setVnic(hostVirtualNics);
    HostVirtualNic[] hostVirtualConsoleNics = new HostVirtualNic[numberOfVnics];
    for (int i = 0; i < numberOfVnics; i++) {
        HostVirtualNicSpec hostVirtualNicSpec = new HostVirtualNicSpec();
        HostIpConfig hostIpConfig = new HostIpConfig();
        hostIpConfig.setIpAddress("192.168.2." + (i + 1));
        hostVirtualNicSpec.setIp(hostIpConfig);
        hostVirtualConsoleNics[i] = new HostVirtualNic();
        hostVirtualConsoleNics[i].setSpec(hostVirtualNicSpec);
    }
    hostNetworkInfo.setConsoleVnic(hostVirtualConsoleNics);
    HostServiceTicket hostServiceTicket = new HostServiceTicket();
    hostServiceTicket.setSessionId("sessionId");
    // setup HostSystem
    mockHostSystem = createMock(HostSystem.class);
    // setup HostNetworkSystem
    mockHostNetworkSystem = createMock(HostNetworkSystem.class);
    // setup CIMClient
    mockCIMClient = createPartialMock(CIMClient.class, "enumerateInstances", "getSessionProperties");
    // setup the cim objects
    cimObjects = new ArrayList<>();
    int cimObjectCount = 5;
    for (int i = 0; i < cimObjectCount; i++) {
        CIMInstance cimInstance = new CIMInstance();
        cimInstance.setName("cimInstance" + i);
        cimObjects.add(cimInstance);
    }
    expect(mockHostSystem.getName()).andReturn("mockesxi01.local").anyTimes();
    expect(mockHostSystem.getHostNetworkSystem()).andReturn(mockHostNetworkSystem).anyTimes();
    expect(mockHostSystem.acquireCimServicesTicket()).andReturn(hostServiceTicket).anyTimes();
    expect(mockHostNetworkSystem.getNetworkInfo()).andReturn(hostNetworkInfo).anyTimes();
    expectNew(CIMClient.class, new Class<?>[] { CIMNameSpace.class, Principal.class, Object.class }, anyObject(), anyObject(), anyObject()).andReturn(mockCIMClient).anyTimes();
    suppress(method(CIMClient.class, "useMPost"));
    expect(mockCIMClient.enumerateInstances(new CIMObjectPath("cimClass"))).andReturn(Collections.enumeration(cimObjects)).anyTimes();
    SessionProperties sessionProperties = new SessionProperties();
    expect(mockCIMClient.getSessionProperties()).andReturn(sessionProperties).anyTimes();
}
Also used : HostVirtualNic(com.vmware.vim25.HostVirtualNic) PerfCounterInfo(com.vmware.vim25.PerfCounterInfo) CIMClient(org.sblim.wbem.client.CIMClient) HostIpConfig(com.vmware.vim25.HostIpConfig) HostVirtualNicSpec(com.vmware.vim25.HostVirtualNicSpec) ServiceInstance(com.vmware.vim25.mo.ServiceInstance) URL(java.net.URL) CIMInstance(org.sblim.wbem.cim.CIMInstance) PerfMetricIntSeries(com.vmware.vim25.PerfMetricIntSeries) PerformanceManager(com.vmware.vim25.mo.PerformanceManager) HostSystem(com.vmware.vim25.mo.HostSystem) HostServiceTicket(com.vmware.vim25.HostServiceTicket) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) VmwareViJavaAccess(org.opennms.protocols.vmware.VmwareViJavaAccess) ElementDescription(com.vmware.vim25.ElementDescription) HostNetworkSystem(com.vmware.vim25.mo.HostNetworkSystem) ManagedEntity(com.vmware.vim25.mo.ManagedEntity) HostNetworkInfo(com.vmware.vim25.HostNetworkInfo) WSClient(com.vmware.vim25.ws.WSClient) PerfMetricId(com.vmware.vim25.PerfMetricId) AboutInfo(com.vmware.vim25.AboutInfo) CIMObjectPath(org.sblim.wbem.cim.CIMObjectPath) ServerConnection(com.vmware.vim25.mo.ServerConnection) VimPortType(com.vmware.vim25.VimPortType) SessionProperties(org.sblim.wbem.util.SessionProperties) PerfProviderSummary(com.vmware.vim25.PerfProviderSummary) PerfQuerySpec(com.vmware.vim25.PerfQuerySpec) RemoteException(java.rmi.RemoteException) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) VirtualMachine(com.vmware.vim25.mo.VirtualMachine) PerfEntityMetric(com.vmware.vim25.PerfEntityMetric) Before(org.junit.Before)

Example 2 with HostVirtualNic

use of com.vmware.vim25.HostVirtualNic in project cloudstack by apache.

the class HostMO method getHostManagementIp.

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;
}
Also used : HostNetworkInfo(com.vmware.vim25.HostNetworkInfo) HostVirtualNic(com.vmware.vim25.HostVirtualNic) HostIpConfig(com.vmware.vim25.HostIpConfig)

Example 3 with HostVirtualNic

use of com.vmware.vim25.HostVirtualNic in project cloudstack by apache.

the class HostMO method getHyperHostNetworkSummary.

@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("Unable to find management port group " + managementPortGroup);
}
Also used : HostVirtualNic(com.vmware.vim25.HostVirtualNic) VirtualNicManagerNetConfig(com.vmware.vim25.VirtualNicManagerNetConfig)

Example 4 with HostVirtualNic

use of com.vmware.vim25.HostVirtualNic in project coprhd-controller by CoprHD.

the class EsxHostDiscoveryAdapter method discoverIp6Interface.

/**
 * Discovery of Ip interface
 *
 * @param host
 *            {@linkk Host}
 * @param ipInterface
 *            {@link IpInterface}
 * @param nic
 *            {@link HostVirtualNic}
 */
protected void discoverIp6Interface(Host host, IpInterface ipInterface, HostVirtualNic nic) {
    HostIpConfigIpV6Address config = getIp6Address(nic);
    setHostInterfaceRegistrationStatus(ipInterface, host);
    ipInterface.setHost(host.getId());
    ipInterface.setProtocol(Protocol.IPV6.name());
    ipInterface.setIpAddress(config.getIpAddress());
    ipInterface.setPrefixLength(config.getPrefixLength());
    ipInterface.setIsManualCreation(false);
    save(ipInterface);
}
Also used : HostIpConfigIpV6Address(com.vmware.vim25.HostIpConfigIpV6Address)

Example 5 with HostVirtualNic

use of com.vmware.vim25.HostVirtualNic in project coprhd-controller by CoprHD.

the class EsxHostDiscoveryAdapter method getNics.

/**
 * Fetch Nics for the hostsystem
 *
 * @param hostSystem
 *            - {@link HostSystem} vi sdk MO
 * @return
 */
protected List<HostVirtualNic> getNics(HostSystem hostSystem) {
    List<HostVirtualNic> nics = Lists.newArrayList();
    HostConfigInfo config = hostSystem.getConfig();
    if ((config != null) && (config.getNetwork() != null) && (config.getNetwork().getVnic() != null)) {
        for (HostVirtualNic nic : config.getNetwork().getVnic()) {
            nics.add(nic);
        }
    }
    return nics;
}
Also used : HostVirtualNic(com.vmware.vim25.HostVirtualNic) HostConfigInfo(com.vmware.vim25.HostConfigInfo)

Aggregations

HostVirtualNic (com.vmware.vim25.HostVirtualNic)9 HostNetworkInfo (com.vmware.vim25.HostNetworkInfo)5 VirtualNicManagerNetConfig (com.vmware.vim25.VirtualNicManagerNetConfig)4 HostIpConfig (com.vmware.vim25.HostIpConfig)2 HostNetworkSystem (com.vmware.vim25.mo.HostNetworkSystem)2 RemoteException (java.rmi.RemoteException)2 Initiator (com.emc.storageos.db.client.model.Initiator)1 IpInterface (com.emc.storageos.db.client.model.IpInterface)1 AboutInfo (com.vmware.vim25.AboutInfo)1 ElementDescription (com.vmware.vim25.ElementDescription)1 HostConfigInfo (com.vmware.vim25.HostConfigInfo)1 HostFibreChannelHba (com.vmware.vim25.HostFibreChannelHba)1 HostHostBusAdapter (com.vmware.vim25.HostHostBusAdapter)1 HostInternetScsiHba (com.vmware.vim25.HostInternetScsiHba)1 HostIpConfigIpV6Address (com.vmware.vim25.HostIpConfigIpV6Address)1 HostServiceTicket (com.vmware.vim25.HostServiceTicket)1 HostVirtualNicSpec (com.vmware.vim25.HostVirtualNicSpec)1 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)1 PerfCounterInfo (com.vmware.vim25.PerfCounterInfo)1 PerfEntityMetric (com.vmware.vim25.PerfEntityMetric)1