Search in sources :

Example 6 with CIMObject

use of org.sblim.wbem.cim.CIMObject in project opennms by OpenNMS.

the class VmwareViJavaAccess method queryCimObjects.

/**
 * Queries a host system for Cim data.
 *
 * @param hostSystem       the host system to query
 * @param cimClass         the class of Cim objects to retrieve
 * @param primaryIpAddress the Ip address to use
 * @return the list of Cim objects
 * @throws RemoteException
 * @throws CIMException
 */
public List<CIMObject> queryCimObjects(HostSystem hostSystem, String cimClass, String primaryIpAddress) throws ConnectException, RemoteException, CIMException {
    List<CIMObject> cimObjects = new ArrayList<>();
    if (!m_hostServiceTickets.containsKey(hostSystem)) {
        m_hostServiceTickets.put(hostSystem, hostSystem.acquireCimServicesTicket());
    }
    HostServiceTicket hostServiceTicket = m_hostServiceTickets.get(hostSystem);
    if (!m_hostSystemCimUrls.containsKey(hostSystem)) {
        String ipAddress = primaryIpAddress;
        if (ipAddress == null) {
            ipAddress = getPrimaryHostSystemIpAddress(hostSystem);
        }
        if (ipAddress == null) {
            logger.warn("Cannot determine ip address for host system '{}'", hostSystem.getMOR().getVal());
            return cimObjects;
        }
        m_hostSystemCimUrls.put(hostSystem, "https://" + ipAddress + ":5989");
    }
    String cimAgentAddress = m_hostSystemCimUrls.get(hostSystem);
    String namespace = "root/cimv2";
    UserPrincipal userPr = new UserPrincipal(hostServiceTicket.getSessionId());
    PasswordCredential pwCred = new PasswordCredential(hostServiceTicket.getSessionId().toCharArray());
    CIMNameSpace ns = new CIMNameSpace(cimAgentAddress, namespace);
    CIMClient cimClient = new CIMClient(ns, userPr, pwCred);
    cimClient.getSessionProperties().setHttpTimeOut(3000);
    // very important to query esx5 hosts
    cimClient.useMPost(false);
    CIMObjectPath rpCOP = new CIMObjectPath(cimClass);
    Enumeration<?> rpEnm = cimClient.enumerateInstances(rpCOP);
    while (rpEnm.hasMoreElements()) {
        CIMObject rp = (CIMObject) rpEnm.nextElement();
        cimObjects.add(rp);
    }
    return cimObjects;
}
Also used : CIMObject(org.sblim.wbem.cim.CIMObject) CIMClient(org.sblim.wbem.client.CIMClient) ArrayList(java.util.ArrayList) HostServiceTicket(com.vmware.vim25.HostServiceTicket) PasswordCredential(org.sblim.wbem.client.PasswordCredential) CIMObjectPath(org.sblim.wbem.cim.CIMObjectPath) CIMNameSpace(org.sblim.wbem.cim.CIMNameSpace) UserPrincipal(org.sblim.wbem.client.UserPrincipal)

Aggregations

CIMObject (org.sblim.wbem.cim.CIMObject)6 MalformedURLException (java.net.MalformedURLException)4 RemoteException (java.rmi.RemoteException)4 HostSystem (com.vmware.vim25.mo.HostSystem)3 HostRuntimeInfo (com.vmware.vim25.HostRuntimeInfo)2 HostSystemPowerState (com.vmware.vim25.HostSystemPowerState)2 Test (org.junit.Test)2 VmwareViJavaAccess (org.opennms.protocols.vmware.VmwareViJavaAccess)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 HostServiceTicket (com.vmware.vim25.HostServiceTicket)1 ManagedEntity (com.vmware.vim25.mo.ManagedEntity)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ParseException (org.apache.commons.cli.ParseException)1 TimeoutTracker (org.opennms.core.utils.TimeoutTracker)1 AttributeType (org.opennms.netmgt.collection.api.AttributeType)1 CollectionException (org.opennms.netmgt.collection.api.CollectionException)1 CollectionInitializationException (org.opennms.netmgt.collection.api.CollectionInitializationException)1 CollectionSetBuilder (org.opennms.netmgt.collection.support.builder.CollectionSetBuilder)1