コード例 #1
0
ファイル: WbemExecCommand.cpp プロジェクト: eSDK/eSDK_OBS_API
/**

    Connects to cimserver.

    @param   outPrintWriter     the ostream to which error output should be
                                written

    @return  the Channel created

    @exception       Exception  if an error is encountered in creating
                               the connection

 */
 void WbemExecCommand::_connectToServer( WbemExecClient& client,
                         ostream& outPrintWriter )
{
    String                 host                  = String ();
    Uint32                 portNumber            = 0;
    Boolean                connectToLocal        = false;

    //
    //  Construct host address
    //
    if ((!_hostNameSet) && (!_portNumberSet))
      {
        connectToLocal = true;
      }
#ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET
    if ((_hostNameSet) || (_portNumberSet))
    {
#endif
      host = _hostName;
      portNumber = _portNumber;
#ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET
    }
#endif

    if( _useSSL )
    {
#ifdef PEGASUS_HAS_SSL
        if( connectToLocal )
        {
            client.connectLocal();
        }
        else
        {
            //
            // Get environment variables:
            //
            const char* pegasusHome = getenv("PEGASUS_HOME");

            String certpath = FileSystem::getAbsolutePath(
                    pegasusHome, PEGASUS_SSLCLIENT_CERTIFICATEFILE);

            String randFile;

#ifdef PEGASUS_SSL_RANDOMFILE
            randFile = FileSystem::getAbsolutePath(
                    pegasusHome, PEGASUS_SSLCLIENT_RANDOMFILE);
#endif
            SSLContext sslcontext(certpath, verifyCertificate, randFile);
            client.connect(host, portNumber, &sslcontext, _userName, _password);
        }
#else
        PEGASUS_UNREACHABLE(PEGASUS_ASSERT(false);)
#endif
    }
    else
    {
        if( connectToLocal )
コード例 #2
0
void ClientProvider::invokeMethod(
	const OperationContext & context,
	const CIMObjectPath & objectReference,
	const CIMName & methodName,
	const Array<CIMParamValue> & inParameters,
	MethodResultResponseHandler & handler)
{
    handler.processing();

    if (objectReference.getClassName().equal ("Sample_ClientProviderClass"))
    {
        if (methodName.equal ("DoConnect"))
        {
            if( inParameters.size() > 0 )
	    {
	        String 		connectType = String::EMPTY;
                CIMValue 	paramVal;
                CIMClient 	client;

	        paramVal = inParameters[0].getValue();
		paramVal.get( connectType );

		if( connectType == "Local" )
		{
                   client.connectLocal();

                  // Enumerate Instances.
                  Array<CIMObjectPath> instanceNames = 
                          client.enumerateInstanceNames(  
                              "root/cimv2", 
                              "CIM_ManagedElement");

                  client.disconnect();
                  handler.deliver(CIMValue(0));
                }
                else if ( connectType == "Remote" )
                {
                    String HOST     = "localhost";
                    Uint32 PORT     = 5989;
                    String USER     = "******";
                    String PASSWORD = "******";
                    const char* pegasusHome = getenv("PEGASUS_HOME");

                    String certpath = FileSystem::getAbsolutePath(
                            pegasusHome, PEGASUS_SSLCLIENT_CERTIFICATEFILE);

                    String randFile = String::EMPTY;

                    randFile = FileSystem::getAbsolutePath(
                                pegasusHome, PEGASUS_SSLCLIENT_RANDOMFILE);

                    SSLContext sslcontext(
                                certpath, verifyCertificate, randFile);

                    client.connect( 
                                   HOST,
                                   PORT,
                                   sslcontext,
                                   USER,
                                   PASSWORD ); 
		  }
                  // Enumerate Instances.

                  Array<CIMObjectPath> instanceNames = client.enumerateInstanceNames( "root/cimv2", "CIM_ManagedElement");

                  client.disconnect();
		  handler.deliver(CIMValue(0));
	     }
	     else
	     {
		  handler.deliver(CIMValue(1));
             }
	}
    }
    handler.complete();
}
コード例 #3
0
int main(int argc, char** argv)
{

  // char connection[50] = "localhost:5988";
  char *address_string = NULL;

    Uint32 repetitions = 1;

    // Get environment variables:

    String pegasusHome;
    pegasusHome = "/";

    // GetEnvironmentVariables(argv[0], pegasusHome);

    // Get options (from command line and from configuration file); this
    // removes corresponding options and their arguments fromt he command
    // line.

    // Get options (from command line and from configuration file); this
    // removes corresponding options and their arguments fromt he command
    // line.

    OptionManager om;

    try
    {
         GetOptions(om, argc, argv, pegasusHome);
    }
    catch (Exception& e)
    {
         cerr << argv[0] << ": " << e.getMessage() << endl;
         exit(1);
    }

    // Check to see if user asked for help (-h otpion):
    if (om.valueEquals("help", "true"))
    {
                String header = "Usage ";
                header.append(argv[0]);
                header.append(" -parameters host [host]");

                String trailer = "Assumes localhost:5988 if host not specified";
                trailer.append("\nHost may be of the form name or name:port");
                trailer.append("\nPort 5988 assumed if port number missing.");
                om.printOptionsHelpTxt(header, trailer);

         exit(0);
    }

    String localNameSpace;
    om.lookupValue("namespace", localNameSpace);
    globalNamespace = localNameSpace;
    cout << "Namespace = " << localNameSpace << endl;

    String userName;
    om.lookupValue("user", userName);
    if (userName != String::EMPTY)
    {
       cout << "Username = "******"verbose");

    String password;
    om.lookupValue("password", password);
    if (password != String::EMPTY)
    {
       cout << "password = "******"repeat", repeatTestCount))
        repeatTestCount = 1;
    /*
    if (om.lookupValue("repeat", repeats))
        {
        repeatTestCount = atol(repeats.getCString());
        }
    else
        repeatTestCount = 1;
    */
    if(verboseTest)
        cout << "Test repeat count " << repeatTestCount << endl;

    // Setup the active test flag.  Determines if we change repository.
    Boolean activeTest = false;
    if (om.valueEquals("active", "true"))
         activeTest = true;

    // here we determine the list of systems to test.
    // All arguments remaining in argv go into list.

    Boolean localConnection = (om.valueEquals("local", "true"))? true: false;
    cout << "localConnection " << (localConnection ? "true" : "false") << endl;

    Array<String> connectionList;
    if (argc > 1 && !localConnection)
         for (Sint32 i = 1; i < argc; i++)
             connectionList.append(argv[i]);

    // substitute the default if no params
    if(argc < 2)
      connectionList.append("localhost:5988");

    // Expand host to add port if not defined

    Boolean useSSL =  om.isTrue("ssl");

    // Show the connectionlist
    cout << "Connection List size " << connectionList.size() << endl;
    for (Uint32 i = 0; i < connectionList.size(); i++)
    cout << "Connection " << i << " address " << connectionList[i] << endl;

    for(Uint32 numTests = 1; numTests <= repeatTestCount; numTests++)
    {
        cout << "Test Repetition # " << numTests << endl;
        for (Uint32 i = 0; i < connectionList.size(); i++)
        {
            cout << "Start Try Block" << endl;
          try
          {
             cout << "Set Stopwatch" << endl;

             Stopwatch elapsedTime;

             cout << "Create client" << endl;
             CIMClient client;
             client.setTimeout(60 * 1000);
             cout << "Client created" << endl;

                     //
                     //  Get host and port number from connection list entry
                     //
                     Uint32 index = connectionList[i].find (':');
                     String host = connectionList[i].subString (0, index);
                     Uint32 portNumber = 0;
                     if (index != PEG_NOT_FOUND)
                     {
                         String portStr = connectionList[i].subString
                             (index + 1, connectionList[i].size ());
                         sscanf (portStr.getCString (), "%u", &portNumber);
                     }

                     if (useSSL)
             {

                        //
                        // Get environment variables:
                        //
                        const char* pegasusHome = getenv("PEGASUS_HOME");

                        String certpath = FileSystem::getAbsolutePath(
                            pegasusHome, PEGASUS_SSLCLIENT_CERTIFICATEFILE);

            String randFile;
#ifdef PEGASUS_SSL_RANDOMFILE
            randFile = FileSystem::getAbsolutePath(
                            pegasusHome, PEGASUS_SSLCLIENT_RANDOMFILE);
#endif

                        SSLContext sslcontext(certpath,verifyServerCertificate, randFile);

            if (om.isTrue("local"))
            {
                 cout << "Using local SSL connection mechanism " << endl;
                     client.connectLocal();
            }
            else
            {
                            cout << "connecting to " << connectionList[i] << " using SSL" << endl;
                            client.connect (host, portNumber, sslcontext,
                                            userName, password);
                        }
              }
                  else
              {
            if (om.isTrue("local"))
            {
                 cout << "Using local connection mechanism " << endl;
                     client.connectLocal();
            }
            else
            {
              cout << "Connecting to " << connectionList[i] << endl;
                            client.connect (host, portNumber,
                                            userName, password);
            }
              }
              cout << "Client Connected" << endl;

              testStart("Test NameSpace Operations - Relative Name");
              elapsedTime.reset();
              elapsedTime.start();
              TestNamespaceHierarchy1(client, activeTest, verboseTest);
              elapsedTime.stop();
              testEnd(elapsedTime.getElapsed());

              testStart("Test NameSpace Operations - Absolute Name");
              elapsedTime.reset();
              elapsedTime.start();
              TestNamespaceHierarchy2(client, activeTest, verboseTest);
              elapsedTime.stop();
              testEnd(elapsedTime.getElapsed());

              client.disconnect();
          }
          catch(Exception& e)
          {
               PEGASUS_STD(cerr) << "Error: " << e.getMessage() <<
                 PEGASUS_STD(endl);
               exit(1);
          }
        }
    }
    PEGASUS_STD(cout) << "+++++ "<< argv[0] << " Terminated Normally" << PEGASUS_STD(endl);
    return 0;
}