Example #1
0
////////////////////////////////////////////////////////////////////////////////
//  Constructor for IP Route Info
////////////////////////////////////////////////////////////////////////////////
IPRouteInfo::IPRouteInfo(CIMClient &client, Boolean enableDebug,
                  ostream& outPrintWriter, ostream& errPrintWriter)
{
    _enableDebug = enableDebug;

    try
    {
        Boolean deepInheritance = true;
	Boolean localOnly = true;
	Boolean includeQualifiers = false;
	Boolean includeClassOrigin = false;
      
      	Array<CIMInstance> cimInstances = 
	    		client.enumerateInstances(NAMESPACE, CLASS_NAME,
			deepInheritance, localOnly, includeQualifiers,
			includeClassOrigin);

 
      	Uint32 numberInstances = cimInstances.size();

      	if (_enableDebug)
	{
		outPrintWriter << numberInstances << " instances of " <<
	             CLASS_NAME.getString() << endl;
	}

	if (numberInstances > 0)
	{
            _gatherProperties(cimInstances[0]);
	    _outputHeader(outPrintWriter);

	    for (Uint32 i = 0; i < numberInstances; i++)
	    {
	        _gatherProperties(cimInstances[i]);
	        _outputInstance(outPrintWriter);

	     }   // end for looping through instances
	}
        else
	{
	     outPrintWriter << "No instances of class " << CLASS_NAME.getString() << endl;
	}

    }  // end try 
   
    catch(Exception& e)
    {
        errPrintWriter << "Error getting instances of class " <<
             CLASS_NAME.getString() << endl;
    }

}
////////////////////////////////////////////////////////////////////////////////
//  Constructor for Next Hop IP Route Info
////////////////////////////////////////////////////////////////////////////////
NextHopIPRouteInfo::NextHopIPRouteInfo(
    CIMClient &client, 
    Boolean enableDebug,
    ostream& outPrintWriter, 
    ostream& errPrintWriter)
{
    _enableDebug = enableDebug;
    Array<CIMInstance> retInstances;

    try
    {
        Boolean deepInheritance = true;
        Boolean localOnly = true;
        Boolean includeQualifiers = false;
        Boolean includeClassOrigin = false;
          
        Array<CIMInstance> cimInstances = client.enumerateInstances(
            NAMESPACE, 
            CLASS_PG_NEXT_HOP_IP_ROUTE,
            deepInheritance,
            localOnly,
            includeQualifiers,
            includeClassOrigin);

        Array<CIMObjectPath> nhiprRefs = client.enumerateInstanceNames(
            NAMESPACE,
            CLASS_CIM_NEXT_HOP_ROUTE);

        for (Uint16 i = 0; i<nhiprRefs.size(); i++)
        {
            CIMName resultClass;
            String role;
            String resultRole;
            CIMObjectPath _nhrRef = nhiprRefs[i];
            _nhrRef.setClassName(CLASS_CIM_NEXT_HOP_ROUTE);

            // Get the association instance of CIM_RouteUsesEndpoint 
            // for each instance of CIM_NextHopRoute class
            Array<CIMObject> localRefs = client.associators(
                NAMESPACE,
                _nhrRef,
                CLASS_PG_ROUTE_USES_ENDPOINT,
                resultClass,
                role,
                resultRole);

            if (localRefs.size() == 1)
            {
                Uint32 index = localRefs[0].findProperty(PROPERTY_IPV4ADDRESS);
                if (index == PEG_NOT_FOUND)
                {
                    index = localRefs[0].findProperty(PROPERTY_IPV6ADDRESS);
                    if (index == PEG_NOT_FOUND)
                    {
                        errPrintWriter << 
                            "Error getting IPv4Address and IPv6Address " <<
                            "property: " << "not found!" << endl; 
                    }
                    else
                    {
                        CIMInstance _cimInstance = cimInstances[i];
                        String _nextHop;
                        localRefs[0].getProperty(index).getValue().get(
                            _nextHop);
                        CIMProperty _nhProperty(
                            PROPERTY_NEXT_HOP,
                             CIMValue(_nextHop));
                        _cimInstance.addProperty(_nhProperty);
                        retInstances.append(_cimInstance);
                    } 
                }
                else
                {
                    CIMInstance _cimInstance = cimInstances[i];
                    String _nextHop;
                    localRefs[0].getProperty(index).getValue().get(_nextHop);
                    CIMProperty _nhProperty(
                        PROPERTY_NEXT_HOP,
                         CIMValue(_nextHop));
                    _cimInstance.addProperty(_nhProperty);
                    retInstances.append(_cimInstance);
                }
            }
            else
            {
                // Get the association instance of CIM_AssociatedNextHop
                // for each instance of CIM_RemoteServiceAccessPoint class
                Array<CIMObject> remoteRefs = client.associators(
                    NAMESPACE,
                    _nhrRef,
                    CLASS_PG_ASSOCIATED_NEXT_HOP,
                    resultClass,
                    role,
                    resultRole);

                if (remoteRefs.size() == 1)
                {
                    Uint32 index = remoteRefs[0].findProperty(
                        PROPERTY_ACCESS_INFO);
                    if (index != PEG_NOT_FOUND)
                    {
                        CIMInstance _cimInstance = cimInstances[i];
                        String _accessInfo;
                        remoteRefs[0].getProperty(index).getValue().get(
                            _accessInfo);
                        Uint32 _sep = _accessInfo.find('/');
                        if (_sep != PEG_NOT_FOUND)
                        {
                            String _nextHop = _accessInfo.subString(0,_sep);
                            CIMProperty _nhProperty(
                                 PROPERTY_NEXT_HOP,
                                 CIMValue(_nextHop));
                            _cimInstance.addProperty(_nhProperty);
                            retInstances.append(_cimInstance);
                        } 
                    }
                    else
                    {
                        errPrintWriter << "Error getting AccessInfo property: "
                            << "not found! " << endl;
                    }
                }
                else
                {
                      outPrintWriter << "Unexpected number of references "
                          << "for this instance of class CIM_NextHopRoute :"
                          << remoteRefs.size() << endl;
                }
            } 
        }

        Uint32 numberInstances = retInstances.size();

        if (_enableDebug)
        {
            outPrintWriter << numberInstances << " instances of " <<
                CLASS_PG_NEXT_HOP_IP_ROUTE.getString() << endl;
        }

        if (numberInstances > 0)
        {
            _gatherProperties(retInstances[0]);
            _outputHeader(outPrintWriter);

            for (Uint32 i = 0; i < numberInstances; i++)
            {
                _gatherProperties(retInstances[i]);
                _outputInstance(outPrintWriter);

            }   // end for looping through instances.
        }
        else
        {
            outPrintWriter << "No instances of class " 
                << CLASS_PG_NEXT_HOP_IP_ROUTE.getString() << endl;
        }

    }  // end try .
    catch(Exception& e)
    {
        errPrintWriter << "Error getting instances of class " <<
            CLASS_PG_NEXT_HOP_IP_ROUTE.getString() << 
            " " << e.getMessage() << endl;
    }

}