📄 cli.cpp
字号:
opts.propertyName = String::EMPTY; opts.methodName = CIMName("unknown"); opts.delay = 0; opts.trace = 0; opts.count= 97832; opts.repeat = 0; opts.time = false; opts.termCondition = 0; opts.debug = false; opts.queryLanguage = "WQL"; // move any other input parameters left to the extraParams List CheckCommonOptionValues(om, argv, opts); /* note that this is in error since it assumes a fixed number of parameters will be used for all of the commands It needs to be expanded to allow for a variable minimum number of commands before it picks up any extras */ if (argc > 2) { for (int i = 2 ; i < argc ; i++ ) opts.extraParams.append(argv[i]); } } catch(CIMException& e) { cerr << argv[0] << " Caught CIMException during init: " << "\n" << e.getMessage() << endl; exit(1); } catch (Exception& e) { cerr << argv[0] << ": " << e.getMessage() << endl; exit(1); } catch(...) { cerr << argv[0] << " Caught General Exception During Init:" << endl; exit(1); } // if there is still an arg1, assume it is the command name. if (argc > 1) { opts.cimCmd = argv[1]; } else { cout << " Command name must be first parameter or --c parameter." << " \n ex. cli enumerateclasses\n" << "Enter " << argv[0] << " -h for help." << endl; exit(1); } // if the trace option was set initialize the trace function. if (opts.trace != 0) { const char* tmpDir = getenv ("PEGASUS_TMP"); if (tmpDir == NULL) { tmpDir = "."; } String traceFile (tmpDir); traceFile.append("/cliTrace.trc"); Tracer::setTraceFile (traceFile.getCString()); Tracer::setTraceComponents("ALL"); Tracer::setTraceLevel(opts.trace); } // Find the command and save index in cmdIndex Uint32 cmdIndex = 0; opts.cimCmd.toLower(); if (opts.verboseTest && opts.debug) cout << "TEST Command = " << opts.cimCmd << endl; // Find the command or the short cut name for( ; cmdIndex < NUM_COMMANDS; cmdIndex++ ) { if ((opts.cimCmd == CommandTable[cmdIndex].CommandName) || (opts.cimCmd == CommandTable[cmdIndex].ShortCut)) // Break if found break; } Stopwatch totalElapsedExecutionTime; totalElapsedExecutionTime.start(); // Now try to open the connection to the cim server CIMClient client; try { if (CommandTable[cmdIndex].ID_Command != ID_ShowOptions) { // Take off port number if it is on host name Uint32 index = opts.location.find (':'); String host = opts.location.subString (0, index); Uint32 portNumber = WBEM_DEFAULT_HTTP_PORT; if (index != PEG_NOT_FOUND) { String portStr = opts.location.subString (index + 1, opts.location.size ()); sscanf (portStr.getCString (), "%u", &portNumber); } //check whether we should use connect() or connectLocal() //an empty location option indicates to use connectLocal() if (String::equal(host, String::EMPTY)) { if (opts.verboseTest) { cout << "Connecting to localhost" << endl; } client.connectLocal(); } else { if (opts.verboseTest) { cout << "Connecting to " << opts.location << " for User = " << opts.user << " password = " << opts.password << endl; }#ifdef PEGASUS_HAS_SSL if (opts.ssl) //connect over HTTPS { if (!String::equal(opts.clientCert, String::EMPTY) && !String::equal(opts.clientKey, String::EMPTY)) { client.connect(host, portNumber, SSLContext("", opts.clientCert, opts.clientKey, NULL, "ssl.rnd"), opts.user, opts.password); } else { client.connect(host, portNumber, SSLContext("", NULL, "ssl.rnd"), opts.user, opts.password); } } else //connect over HTTP { client.connect(host, portNumber, opts.user, opts.password); }#else client.connect(host, portNumber, opts.user, opts.password);#endif } } } catch(Exception &e) { cerr << "Pegasus Exception: " << e.getMessage() << " Trying to connect to " << opts.location << endl; exit(1); } // Register for Client statistics. ClientStatistics statistics = ClientStatistics(); client.registerClientOpPerformanceDataHandler(statistics); if (opts.delay != 0) { // This was a test because of some delay caused problems. Threads::sleep(opts.delay * 1000); } // If the timeout is not zero, set the timeout for this connection. if (opts.connectionTimeout != 0) { client.setTimeout(opts.connectionTimeout * 1000); } // Save the total connect time. double totalConnectTime = opts.elapsedTime.getElapsed(); double totalTime = 0; Uint32 repeatCount = opts.repeat; double maxTime = 0; double minTime = 10000000; Uint64 serverTotalTime = 0; Uint64 maxServerTime = 0; Uint64 minServerTime = 10000000; Uint64 rtTotalTime = 0; Uint64 maxRtTime = 0; Uint64 minRtTime = 10000000; // Process the input command within a try block. try { // Loop to repeat the command a number of times. do { // or exit with error through default of case logic switch(CommandTable[cmdIndex].ID_Command) { case ID_EnumerateInstanceNames : if (!_getClassNameInput(argc, argv, opts, true)) exit(1); enumerateInstanceNames(client, opts); break; case ID_EnumerateAllInstanceNames : if (!_getClassNameInput(argc, argv, opts, false)) exit(1); enumerateAllInstanceNames(client, opts); break; case ID_EnumerateInstances : if (!_getClassNameInput(argc, argv, opts, true)) exit(1); enumerateInstances(client, opts); break; case ID_GetInstance : if (!_getObjectNameInput(argc, argv, opts, true)) exit(1); getInstance(client, opts); break; case ID_EnumerateClassNames : if (!_getClassNameInput(argc, argv, opts, false)) exit(1); enumerateClassNames(client, opts); break; case ID_EnumerateClasses : if (!_getClassNameInput(argc, argv, opts, false)) exit(1); enumerateClasses(client, opts); break; case ID_GetClass : if (!_getClassNameInput(argc, argv, opts, true)) exit(1); getClass(client, opts); break; case ID_CreateInstance : if (!_getClassNameInput(argc, argv, opts, true)) exit(1); createInstance(client, opts); break; case ID_DeleteInstance : if (!_getObjectNameInput(argc, argv, opts, true)) exit(1); deleteInstance(client, opts); break; case ID_CreateClass : cerr << "CreateClass not implemented" << endl; break; case ID_DeleteClass : if (!_getClassNameInput(argc, argv, opts, true)) exit(1); deleteClass(client, opts); break; case ID_GetProperty : // ATTN: This one is wrong if (argc != 4) cout << "Usage: cli getproperty <instancename> <propertyname>" << endl; if (argc > 2) { opts.instanceName = argv[2]; opts.inputObjectName = argv[2]; } if (argc > 3) opts.propertyName = argv[3];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -