⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cliclientlib.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/****    Array<CIMObject> associators(        const CIMNamespaceName& nameSpace,        const CIMObjectPath& objectName,        const CIMName& assocClass = CIMName(),        const CIMName& resultClass = CIMName(),        const String& role = String::EMPTY,        const String& resultRole = String::EMPTY,        Boolean includeQualifiers = false,        Boolean includeClassOrigin = false,        const CIMPropertyList& propertyList = CIMPropertyList()    ); */int associators(CIMClient& client, Options& opts){    if (opts.verboseTest)    {        cout << "Associators "            << "Namespace= " << opts.nameSpace            << ", Object= " << opts.objectName            << ", assocClass= " << opts.assocClass            << ", resultClass= " << opts.resultClass            << ", role= " << opts.role            << ", resultRole= " << opts.resultRole            << ", includeQualifiers= " << _toString(opts.includeQualifiers)            << ", includeClassOrigin= " << _toString(opts.includeClassOrigin)            << ", propertyList= " << buildPropertyListString(opts.propertyList)            << endl;    }    // do conditional select of instance if params properly set.    CIMObjectPath thisObjectPath(opts.objectName);    if(!_conditionalSelectInstance(client, opts, thisObjectPath))        return(0);    if (opts.time)    {        opts.elapsedTime.reset();        opts.elapsedTime.start();    }    Array<CIMObject> objects =    client.associators( opts.nameSpace,                        thisObjectPath,                        opts.assocClass,                        opts.resultClass,                        opts.role,                        opts.resultRole,                        opts.includeQualifiers,                        opts.includeClassOrigin,                        opts.propertyList);    if (opts.time)    {        opts.elapsedTime.stop();        opts.saveElapsedTime = opts.elapsedTime.getElapsed();    }    if (opts.summary)    {      String s = "associators";        _displaySummary(objects.size(), s, opts.objectName,opts);    }    else    {        // Output the returned instances        for (Uint32 i = 0; i < objects.size(); i++)            outputFormatObject(opts.outputType, objects[i]);    }    return(0);}/*    CIMValue invokeMethod(        const CIMNamespaceName& nameSpace,        const CIMObjectPath& instanceName,        const CIMName& methodName,        const Array<CIMParamValue>& inParameters,        Array<CIMParamValue>& outParameters*/ int invokeMethod(CIMClient& client, Options& opts) {     {         // Display the parameter set if verbose requested.         if (opts.verboseTest)         {             cout << "invokeMethod"                 << " Namespace= " << opts.nameSpace                 << ", ObjectName= " << opts.objectName                 << ", methodName= " << opts.methodName                 << ", inParams Count= " << opts.inParams.size()                 << endl;             for (Uint32 i=0; i< opts.inParams.size(); i++)                 outputFormatParamValue(opts.outputType, opts.inParams[i]);        }         // Create array for output parameters        CIMValue retValue;        Array<CIMParamValue> outParams;        if (opts.time)        {            opts.elapsedTime.reset();            opts.elapsedTime.start();        }        // Call invoke method with the parameters        retValue = client.invokeMethod(opts.nameSpace, opts.objectName,            opts.methodName, opts.inParams, outParams);        if (opts.time)        {            opts.elapsedTime.stop();            opts.saveElapsedTime = opts.elapsedTime.getElapsed();        }        // Display the return value CIMValue        cout << "Return Value= ";        if (opts.outputType == OUTPUT_XML)            XmlWriter::printValueElement(retValue, cout);        else            cout << retValue.toString() << endl;        // Display any outparms        for (Uint32 i = 0; i < outParams.size() ; i++)            outputFormatParamValue(opts.outputType, outParams[i]);     }     return(0); } /* Enumerate the Namespaces.  This function is based on using the __Namespace class    and either returns all namespaces or simply the ones starting at the namespace input    as the namespace variable.    It assumes that the input classname is __Namespace. */int enumerateNamespaces_Namespace(CIMClient& client, Options& opts){    if (opts.verboseTest)    {        cout << "EnumerateNamespaces "            << "Namespace= " << opts.nameSpace            << ", Class= " << opts.className            << endl;    }    Boolean usingPegasus = true;    Array<CIMInstance> instances;    try    {        instances = client.enumerateInstances((CIMNamespaceName)(opts.nameSpace),opts.className);    }    catch(CIMException &)    {        /*if an exception was caught here then we assume we are not useing        the open pegasus CIMOM. There for we should only check the        __namespaces class. (Which may only retrun a subset of all namspaces        */        usingPegasus = false;        opts.className = CIMName("__namespace");        opts.nameSpace = PEGASUS_NAMESPACENAME_INTEROP.getString();    }    if (usingPegasus)    {        for (Uint32 i = 0 ; i < instances.size(); i++)        {            Uint32 pos;            // if we find the property and it is a string, use it.            if ((pos = instances[i].findProperty("name")) != PEG_NOT_FOUND)            {                CIMValue value;                String namespaceComponent;                value = instances[i].getProperty(pos).getValue();                if (value.getType() == CIMTYPE_STRING)                {                    value.get(namespaceComponent);                    cout << namespaceComponent << endl;                }            }        }    }    if (!usingPegasus)    {        Array<CIMNamespaceName> namespaceNames;        // Build the namespaces incrementally starting at the root        // ATTN: 20030319 KS today we start with the "root" directory but this is wrong. We should be        // starting with null (no directoyr) but today we get an xml error return in Pegasus        // returned for this call. Note that the specification requires that the root namespace be used        // when __namespace is defined but does not require that it be the root for allnamespaces. That        // is a hole is the spec, not in our code.        namespaceNames.append(opts.nameSpace);        Uint32 start = 0;        Uint32 end = namespaceNames.size();        if (opts.time)        {            opts.elapsedTime.reset();            opts.elapsedTime.start();        }        do        {            // for all new elements in the output array            for (Uint32 range = start; range < end; range ++)            {                // Get the next increment in naming for all a name element in the array                Array<CIMInstance> instances = client.enumerateInstances(namespaceNames[range],opts.className);                for (Uint32 i = 0 ; i < instances.size(); i++)                {                    Uint32 pos;                    // if we find the property and it is a string, use it.                    if ((pos = instances[i].findProperty("name")) != PEG_NOT_FOUND)                    {                        CIMValue value;                        String namespaceComponent;                        value = instances[i].getProperty(pos).getValue();                        if (value.getType() == CIMTYPE_STRING)                        {                            value.get(namespaceComponent);                                String ns = namespaceNames[range].getString();                                ns.append("/");                                ns.append(namespaceComponent);                                namespaceNames.append(ns);                        }                    }                }                start = end;                end = namespaceNames.size();            }        }        while (start != end);        // Validate that all of the returned entities are really namespaces. It is legal for us to        // have an name component that is really not a namespace (ex. root/fred/john is a namespace        // but root/fred is not.        // There is no clearly defined test for this so we will simply try to get something, in this        // case a wellknown assoication          Array<CIMNamespaceName> returnNamespaces;        for (Uint32 i = 0 ; i < namespaceNames.size() ; i++)        {            try            {                CIMQualifierDecl cimQualifierDecl;                cimQualifierDecl = client.getQualifier(namespaceNames[i],                                               "Association");                returnNamespaces.append(namespaceNames[i]);            }            catch(CIMException& e)            {                if (e.getCode() != CIM_ERR_INVALID_NAMESPACE)                    returnNamespaces.append(namespaceNames[i]);            }        }        if (opts.time)        {            opts.elapsedTime.stop();            opts.saveElapsedTime = opts.elapsedTime.getElapsed();        }        if (opts.summary)        {            cout << returnNamespaces.size() << " namespaces " << " returned." << endl;        }        else        {            for( Uint32 cnt = 0 ; cnt < returnNamespaces.size(); cnt++ )            {                cout << returnNamespaces[cnt] << endl;;            }        }    }    return(0);}/////////////////////////////////////////////////////////////////////// The following section manages the input options.  It includes   //// both the options processor (based on common/options             //// and the options table.                                          ///////////////////////////////////////////////////////////////////////void GetOptions(    OptionManager& om,    int& argc,    char** argv,    const String& testHome){    static const char* outputFormats[] = { "xml", "mof", "txt"};    static const Uint32 NUM_OUTPUTFORMATS = sizeof(outputFormats) /                                            sizeof(outputFormats[0]);    static OptionRow optionsTable[] =        //optionname defaultvalue rqd  type domain domainsize clname hlpmsg    {        {"count", "29346", false, Option::WHOLE_NUMBER, 0, 0, "count",            "Expected count of objects returned if summary set. \n Tests this"            " count and display difference. Return nonzero if test fails  "},        {"debug", "false", false, Option::BOOLEAN, 0, 0, "d",            "More detailed debug messages "},        {"delay", "0", false, Option::WHOLE_NUMBER, 0, 0, "delay",            "Delay between connection and request "},        {"Password", "", false, Option::STRING, 0, 0, "p",            "Defines password for authentication" },        {"location", "", false, Option::STRING, 0, 0, "l",            "specifies system and port (HostName:port). Port is optional" },#ifdef PEGASUS_HAS_SSL        {"ssl", "false", false, Option::BOOLEAN, 0, 0, "s",            "specifies to connect over HTTPS" },        {"clientCert", "", false, Option::STRING, 0, 0, "-cert",            "specifies a client certificate to present to the server. \n This is"            " optional and only has an effect on connections made over HTTPS"            " using -s" },        {"clientKey", "", false, Option::STRING, 0, 0, "-key",            "specifies a client private key. This is optional and only has an"            "\n  effect on connections made over HTTPS using -s" },#endif        {"User", "", false, Option::STRING, 0, 0, "u",            "Defines User Name for authentication" },        {"namespace", "root/cimv2", false, Option::STRING, 0, 0, "n",            "Specifies namespace to use for operation" },        {"deepInheritance", "false", false, Option::BOOLEAN, 0, 0, "di",            "If set deepInheritance parameter set true "},        {"localOnly", "true", false, Option::BOOLEAN, 0, 0, "lo",            "DEPRECATED. This was used to set LocalOnly. However, \n default"            " should be true and we cannot use True as default. See !lo "},        {"!localOnly", "false", false, Option::BOOLEAN, 0, 0, "!lo",            "When set, sets LocalOnly = false on operations.\n DEPRECATED,"            " ! confuses bash. Use -nlo "},        {"notLocalOnly", "false", false, Option::BOOLEAN, 0, 0, "nlo",            "When set, sets LocalOnly = false on operations "},        {"includeQualifiers", "true", false, Option::BOOLEAN, 0, 0, "iq",            "Deprecated. Sets includeQualifiers = True. However, default=true"},        {"!includeQualifiers", "false", false, Option::BOOLEAN, 0, 0, "!iq",            "Sets includeQualifiers = false on operations.\n DEPRECATED,"            " ! confuses bash. Use -niq"},                {"notIncludeQualifiers", "false", false, Option::BOOLEAN, 0, 0, "niq",            "Sets includeQualifiers = false on operations"},        // Uses a magic string as shown below to indicate never used.        {"propertyList", "###!###", false, Option::STRING, 0, 0, "pl",            "Defines a propertyNameList. Format is p1,p2,p3 (without"            " spaces).\n Use \"\" for empty."},        {"assocClass", "", false, Option::STRING, 0, 0, "ac",            "Defines a assocClass string for Associator calls"},        {"assocRole", "", false, Option::STRING, 0, 0, "ar",            "Defines a role string for Associatiors AssocRole parameter"},        {"role", "", false, Option::STRING, 0, 0, "r",            "Defines a role string for reference role parameter"},        {"resultClass", "", false, Option::STRING, 0, 0, "rc",            "Defines a resultClass string for References and Associatiors "},        {"resultRole", "", false, Option::STRING, 0, 0, "rr",            "Defines a role string for associators operation resultRole parameter. "},        {"inputParameters", "", false, Option::STRING, 0, 0, "ip",            "Defines an invokeMethod input parameter list. Format is"            " p1=v1 p2=v2 .. pn=vn \n  (parameters are seperated by spaces)"},        {"filter", "", false, Option::STRING, 0, 0, "f",            "defines a filter to use for query. Single String input "},        // This was never used.  Delete. KS        //{"substitute", "", false, Option::STRING, 0, 0, "-s",        //                    "Defines a conditional substition of input parameters. ) "},        // KS change the output formats to use the enum options function        // Deprecate this function.        {"outputformats", "mof", false, Option::STRING, 0,NUM_OUTPUTFORMATS, "o",            "Output in xml, mof, txt"},        {"xmlOutput", "false", false, Option::BOOLEAN, 0,0, "x",            "Output objects in xml instead of mof format"},        {"version", "false", false, Option::BOOLEAN, 0, 0, "-version",            "Displays software Version "},        {"verbose", "false", false, Option::BOOLEAN, 0, 0, "v",            "Verbose Display. Includes Detailed Param Input display "},        {"summary", "false", false, Option::BOOLEAN, 0, 0, "-sum",            "Displays only summary count for enumerations, associators, etc. "},        {"help", "false", false, Option::BOOLEAN, 0, 0, "h",            "Prints help usage message "},        {"full help", "false", false, Option::BOOLEAN, 0, 0, "-help",            "Prints full hel

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -