Search in sources :

Example 1 with CIMNameSpace

use of org.sblim.wbem.cim.CIMNameSpace 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<CIMObject>();
    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);
    // 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

HostServiceTicket (com.vmware.vim25.HostServiceTicket)1 ArrayList (java.util.ArrayList)1 CIMNameSpace (org.sblim.wbem.cim.CIMNameSpace)1 CIMObject (org.sblim.wbem.cim.CIMObject)1 CIMObjectPath (org.sblim.wbem.cim.CIMObjectPath)1 CIMClient (org.sblim.wbem.client.CIMClient)1 PasswordCredential (org.sblim.wbem.client.PasswordCredential)1 UserPrincipal (org.sblim.wbem.client.UserPrincipal)1