本文整理汇总了C++中CIMClient类的典型用法代码示例。如果您正苦于以下问题:C++ CIMClient类的具体用法?C++ CIMClient怎么用?C++ CIMClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CIMClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testAssociationClass
void testAssociationClass(CIMClient & client, const CIMName & className)
{
cout << "Testing Association Class "
<< (const char *)className.getString().getCString()
<< "...";
Array<CIMInstance> instances = testAnyClass(client, className);
for(unsigned int i = 0, n = instances.size(); i < n; ++i)
{
//
// Now make sure that the references are valid and that association
// traversal between them is working properly.
//
CIMObjectPath referenceA;
CIMObjectPath referenceB;
CIMInstance currentInstance = instances[i];
CIMObjectPath currentInstanceName = currentInstance.getPath();
if(currentInstanceName.getNameSpace().isNull())
currentInstanceName.setNameSpace(interopNamespace);
for(unsigned int j = 0, m = currentInstance.getPropertyCount();
j < m; ++j)
{
CIMProperty currentProp = currentInstance.getProperty(j);
if(currentProp.getValue().getType() == CIMTYPE_REFERENCE)
{
if(referenceA.getKeyBindings().size() == 0)
{
currentProp.getValue().get(referenceA);
}
else
{
currentProp.getValue().get(referenceB);
break;
}
}
}
if(referenceA.getKeyBindings().size() == 0 ||
referenceB.getKeyBindings().size() == 0)
{
exitFailure(
String("Could not find reference properties for ") +
String("association: ") +
currentInstanceName.toString());
}
try
{
client.getInstance(referenceA.getNameSpace(), referenceA);
client.getInstance(referenceB.getNameSpace(), referenceB);
}
catch(CIMException &)
{
exitFailure(String("Could not get instances for association : ") +
currentInstanceName.toString());
}
Boolean associationFailure = false;
try
{
Array<CIMObjectPath> results = client.associatorNames(
referenceA.getNameSpace(), referenceA, className);
Boolean found = false;
for(unsigned int j = 0, m = results.size(); j < m; ++j)
{
CIMObjectPath result = results[j];
result.setHost(referenceB.getHost());
result.setNameSpace(referenceB.getNameSpace());
if(result == referenceB)
{
found = true;
break;
}
}
if(found)
{
results = client.associatorNames(referenceB.getNameSpace(),
referenceB, className);
for(unsigned int j = 0, m = results.size(); j < m; ++j)
{
CIMObjectPath result = results[j];
result.setHost(referenceA.getHost());
result.setNameSpace(referenceA.getNameSpace());
if(result == referenceA)
{
found = true;
break;
}
}
}
if(!found)
{
associationFailure = true;
}
}
catch(CIMException & e)
{
//.........这里部分代码省略.........
示例2: main
int main(int argc, char** argv)
{
verbose = (getenv("PEGASUS_TEST_VERBOSE")) ? true : false;
//
// Check for command line option
//
if (argc != 2)
{
cerr << "Usage: TestCMPIAssociation {namespace}" << endl;
return(1);
}
providerNamespace = CIMNamespaceName (argv[1]);
CIMClient client;
// Connect to server
try
{
client.connectLocal();
}
catch (Exception& e)
{
_errorExit(e.getMessage());
}
// =======================================================================
// Test passing Instance object path to the Association Methods
// =======================================================================
// Get the instance object paths for the Person and Vehicle class
//
Array<CIMObjectPath> personRefs;
Array<CIMObjectPath> vehicleRefs;
try
{
personRefs =
client.enumerateInstanceNames(providerNamespace, CMPI_TEST_PERSON);
vehicleRefs =
client.enumerateInstanceNames(providerNamespace, CMPI_TEST_VEHICLE);
}
catch (Exception& e)
{
cerr << "enumerateInstanceNames() failed." << endl;
_errorExit(e.getMessage());
}
for(Uint32 i=0;i<personRefs.size();i++)
{
cout<<"PersonRefs values : "<<personRefs[i].toString()<<endl;
}
for(Uint32 i=0;i<vehicleRefs.size();i++)
{
cout<<"VehicleRefs values : "<<vehicleRefs[i].toString()<<endl;
}
Uint32 numPersonInstances = personRefs.size();
Uint32 numVehicleInstances = vehicleRefs.size();
cout << "Number of PersonInstances: " << numPersonInstances << endl;
cout << "Number of VehicleInstances: " << numVehicleInstances << endl;
// =======================================================================
// Test associators
//
// Get the CIM instances that are associated with the specified source CIM
// instance via an instance of a specified association class.
// =======================================================================
if (verbose)
{
cout << "+++++ Test associators" << endl;
}
for (Uint32 i = 0; i < numPersonInstances; i++)
{
_testAssociators(
client,
CMPI_TEST_RACING,
personRefs[i],
resultArray_asso_P1[i]);
}
for (Uint32 i = 0; i < numVehicleInstances; i++)
{
_testAssociators(client, CMPI_TEST_RACING, vehicleRefs[i],
resultArray_asso_V1[i]);
}
// =======================================================================
// Test associatorNames
//
// Get the names of the CIM instances that are associated with the specified
// source CIM instance via an instance of a association class.
// =======================================================================
if (verbose)
{
//.........这里部分代码省略.........
示例3: _testCMPIAssociationClassOperations
void _testCMPIAssociationClassOperations(CIMClient& client, CIMName className)
{
Array<CIMObjectPath> resultObjectPaths;
Array<CIMObject> resultObjects;
CIMObjectPath op(className.getString());
CIMName assocClass;
CIMName resultClass;
String role;
String resultRole;
// =======================================================================
// associators
//
// Get the CIM classes that are associated with the specified CIM Class
// =======================================================================
if (verbose)
{
cout << "+++++ Test associators for (" << className.getString();
cout << ")" << endl;
}
try
{
// get the association classes
resultObjects = client.associators(providerNamespace, op, assocClass,
resultClass, role, resultRole);
// display result
_displayResult(resultObjects);
}
catch (Exception& e)
{
// Do nothing.
_errorExit(e.getMessage());
}
// =======================================================================
// associatorNames
//
// Get the name of the CIM classes that are associated with the specified
// CIM class.
// =======================================================================
if (verbose)
{
cout << "+++++ Test associatorNames for (" << className.getString();
cout << ")" << endl;
}
try
{
resultObjectPaths = client.associatorNames(
providerNamespace,
op,
assocClass,
resultClass,
role,
resultRole);
// display result
_displayResult(resultObjectPaths);
}
catch (Exception& e)
{
// Do nothing.
_errorExit(e.getMessage());
}
// =======================================================================
// references
//
// Get the association classes that refer to the specified CIM class.
// =======================================================================
if (verbose)
{
cout << "+++++ Test references for (" << className.getString()
<< ")" << endl;
}
try
{
resultObjects = client.references(
providerNamespace,
op,
resultClass,
role);
// display result
_displayResult(resultObjects);
}
catch (Exception& e)
{
// Do nothing.
_errorExit(e.getMessage());
}
// =======================================================================
//.........这里部分代码省略.........
示例4: TestNamespaceHierarchy1
static void TestNamespaceHierarchy1 ( CIMClient& client,
Boolean activeTest,
Boolean verboseTest)
{
Array<CIMNamespaceName> namespaces;
String instanceName;
namespaces.append(CIMNamespaceName ("test1"));
namespaces.append(CIMNamespaceName ("test2"));
namespaces.append(CIMNamespaceName ("test3"));
namespaces.append(CIMNamespaceName ("test4"));
namespaces.append(CIMNamespaceName ("test5"));
namespaces.append(CIMNamespaceName ("test6"));
namespaces.append(CIMNamespaceName ("test1/test2"));
namespaces.append(CIMNamespaceName ("test1/test2/test3"));
namespaces.append(CIMNamespaceName ("test1/test2/test3/test4"));
namespaces.append(CIMNamespaceName ("test1/test2/test3/test4/test5"));
namespaces.append(CIMNamespaceName ("test1/test2/test3/test4/test5/test6"));
if(verboseTest)
{
cout << "++ Cleanup existing test namespaces" << endl;
}
for (Sint32 i = namespaces.size()-1; i > -1; i--)
{
// Build the instance name for __namespace
CIMNamespaceName testNamespaceName = namespaces[i];
instanceName.clear();
instanceName.append(CLASSNAME.getString());
instanceName.append( ".Name=\"");
instanceName.append(testNamespaceName.getString());
instanceName.append("\"");
try
{
CIMObjectPath myReference(instanceName);
if(verboseTest)
cout << "Deleting " << testNamespaceName << endl;
client.deleteInstance(__NAMESPACE_NAMESPACE, myReference);
}
catch(...)
{
//Ignore errors we are just trying to cleanup
}
}
if(verboseTest)
{
cout << "++ Create test namespaces" << endl;
}
for (Uint32 i = 0; i < namespaces.size(); i++)
{
// Build the instance name for __namespace
CIMNamespaceName testNamespaceName = namespaces[i];
String instanceName = CLASSNAME.getString();
instanceName.append( ".Name=\"");
instanceName.append(testNamespaceName.getString());
instanceName.append("\"");
if(verboseTest)
{
cout << "Creating " << testNamespaceName << endl;
}
try
{
// Build the new instance
CIMInstance newInstance(CLASSNAME);
newInstance.addProperty(CIMProperty(CIMName ("name"),
testNamespaceName.getString()));
client.createInstance(__NAMESPACE_NAMESPACE, newInstance);
}
catch(Exception& e)
{
PEGASUS_STD(cerr) << "Exception NameSpace Creation: "
<< e.getMessage() << " Creating " << instanceName
<< PEGASUS_STD(endl);
exit(1);
}
}
for (Sint32 i = namespaces.size()-1; i > -1; i--)
{
// Build the instance name for __namespace
CIMNamespaceName testNamespaceName = namespaces[i];
instanceName.clear();
instanceName.append(CLASSNAME.getString());
instanceName.append( ".Name=\"");
instanceName.append(testNamespaceName.getString());
instanceName.append("\"");
try
{
CIMObjectPath myReference(instanceName);
if(verboseTest)
cout << "getInstance " << testNamespaceName << endl;
CIMInstance namespaceInstance = client.getInstance(__NAMESPACE_NAMESPACE, myReference);
}
catch(Exception& e)
{
PEGASUS_STD(cerr) << "Exception NameSpace Deletion1: "
<< e.getMessage() << " Deleting " << instanceName
<< PEGASUS_STD(endl);
//.........这里部分代码省略.........
示例5: main
int main(int argc, char** argv)
{
char *ptr;
Uint32 port = 0;
String host = "localhost:5988";
String userName;
String password;
Boolean enumInst = true;
Boolean enumInstNames = true;
Boolean getInst = true;
Boolean verboseTest = false;
// check if have a "verbose" on the command line
if (argv[1] != 0)
{
const char *arg = argv[1];
if ((strcmp(arg, "-verbose") == 0) ||
(strcmp(arg, "verbose") == 0))
verboseTest = true;
}
ptr = getenv("CIM_HOST");
if (ptr != NULL)
host.assign(ptr);
ptr = getenv("CIM_PORT");
if (ptr != NULL)
port = atol(ptr);
ptr = getenv("CIM_USER");
if (ptr != NULL)
userName.assign(ptr);
ptr = getenv("CIM_PASSWORD");
if (ptr != NULL)
password.assign(ptr);
// need to first connect to the CIMOM
// use null string for user and password, port 5988
if (verboseTest)
cout << "Starting NIS Client test" << endl;
try
{
if (verboseTest)
cout << "Create client" << endl;
// specify the timeout value for the connection (if inactive)
// in milliseconds, thus setting to one minute
CIMClient client;
client.setTimeout(60 * 1000);
if (verboseTest)
cout << "Client created" << endl;
cout << "NISTestClient connecting to " << host << endl;
if (port == 0)
{
// Connect to local host
client.connectLocal();
}
else
{
// Conect to remote host
client.connect(host, port, userName, password);
}
cout << "NISTestClient Connected" << endl;
NISTestClient testClient(client);
if (enumInstNames)
{
testClient.testEnumerateInstanceNames(client, verboseTest);
}
if (enumInst)
{
testClient.testEnumerateInstances(client, verboseTest);
}
if (getInst)
{
testClient.testGetInstance(client, verboseTest);
}
cout << "NISTestClient disconnecting from CIMOM " << endl;
client.disconnect();
}
catch (Exception& e)
{
cout << "---- NIS Provider Test Failed " << e.getMessage() << endl;
}
return 0;
}
示例6: main
//.........这里部分代码省略.........
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
示例7: main
int main (int argc, char ** argv)
{
try
{
CIMClient client;
//
// Connect to CIM Server
//
try
{
client.connectLocal ();
}
catch(Exception& e)
{
cerr << "Exception thown by client.connectLocal(): "
<< e.getMessage() << endl;
return -1;
}
if (argc > 2)
{
_usage ();
return 1;
}
else if (argc == 1)
{
try
{
_subscribe (client);
}
catch(Exception& e)
{
cerr << "Exception thrown by _subscribe method: "
<< e.getMessage() << endl;
return -1;
}
Sint32 result = _sendTestIndications (client);
if (result == 0)
{
cout << "Successfully sent test indications" << endl;
}
else
{
cerr << "Failed to send test indications" << endl;
}
try
{
_unsubscribe (client);
}
catch(Exception& e)
{
cerr << "Exception thrown by _unsubscribe method: "
<< e.getMessage() << endl;
return -1;
}
}
else
{
const char * opt = argv [1];
if (String::equalNoCase (opt, "subscribe"))
{
try
{
_subscribe (client);
}
catch(Exception& e)
{
cerr << "Exception thrown by _subscribe method: "
<< e.getMessage() << endl;
return -1;
}
}
else if (String::equalNoCase (opt, "sendTestIndications"))
{
Sint32 result = _sendTestIndications (client);
if (result == 0)
{
cout << "Successfully sent test indications" << endl;
}
else
{
cerr << "Failed to send test indications" << endl;
}
}
else if (String::equalNoCase (opt, "unsubscribe"))
{
try
{
_unsubscribe (client);
}
//.........这里部分代码省略.........
示例8: main
//.........这里部分代码省略.........
<< argv[7] << PEGASUS_STD(endl);
exit(1);
}
}
}
else if (strcmp(argv[6],"NONE") == 0)
{
expectedResult = NONE;
}
else
{
PEGASUS_STD(cout) << "Invalid expectedResult parameter: "
<< argv[6] << PEGASUS_STD(endl);
exit(1);
}
}
try
{
AutoPtr<SSLContext> pCtx;
if (certpath != String::EMPTY)
{
pCtx.reset(
new SSLContext(String::EMPTY, certpath, keypath, 0, randFile));
}
else
{
pCtx.reset(new SSLContext(String::EMPTY, 0, randFile));
}
PEGASUS_STD(cout)<< "TestCertClient::Connecting to 127.0.0.1:5989"
<< PEGASUS_STD(endl);
CIMClient client;
client.connect("127.0.0.1", 5989, *pCtx, userName, password);
Array<CIMParamValue> inParams;
Array<CIMParamValue> outParams;
CIMValue retValue = client.invokeMethod(
CIMNamespaceName("test/TestProvider"),
CIMObjectPath("Test_MethodProviderClass"),
CIMName("getIdentity"),
inParams,
outParams);
if (expectedResult == FAIL)
{
throw Exception("Failure: Connection unexpectedly succeeded");
}
String retUserName;
retValue.get(retUserName);
if (expectedUserName != String::EMPTY)
{
if (expectedUserName != retUserName)
{
throw Exception("Provider returned unexpected Identity: "
+ retUserName);
}
}
CIMClass c = client.getClass("root/cimv2",
"CIM_ComputerSystem", false, false, true);
PEGASUS_STD(cout) << "Result: " << c.getClassName().getString()
<< PEGASUS_STD(endl);
示例9: createErrorInstance
int createErrorInstance(CIMClient& client)
{
// Build the embedded instance
Array<CIMKeyBinding> embeddedPathKeys;
CIMName key1Name("key1");
CIMValue key1Value(String("fake-key1"));
CIMName key2Name("key2");
CIMValue key2Value(String("fake-key2"));
embeddedPathKeys.append(CIMKeyBinding(key1Name, key1Value));
embeddedPathKeys.append(CIMKeyBinding(key2Name, key2Value));
CIMObjectPath embeddedPath(
"localhost",
TEST_NAMESPACE,
CIMName("PG_EmbeddedClass"),
embeddedPathKeys);
embeddedInstance.reset(new CIMInstance(CIMName("PG_EmbeddedClass")));
//embeddedInstance->setPath(embeddedPath);
embeddedInstance->addProperty(CIMProperty(key1Name,
key1Value));
embeddedInstance->addProperty(CIMProperty(key2Name,
key2Value));
embeddedInstance->addProperty(CIMProperty(CIMName("prop01"),
Uint8(234)));
embeddedInstance->addProperty(CIMProperty(CIMName("prop02"),
Uint16(16234)));
embeddedInstance->addProperty(CIMProperty(CIMName("prop03"),
Uint32(32234)));
embeddedInstance->addProperty(CIMProperty(CIMName("prop04"),
Uint64(64234)));
embeddedInstance->addProperty(CIMProperty(CIMName("prop05"),
Sint8(-234)));
embeddedInstance->addProperty(CIMProperty(CIMName("prop06"),
Sint16(-16234)));
embeddedInstance->addProperty(CIMProperty(CIMName("prop07"),
Sint32(-32234)));
embeddedInstance->addProperty(CIMProperty(CIMName("prop08"),
Sint64(-64234)));
embeddedInstance->addProperty(CIMProperty(CIMName("prop09"),
Real32(-64234.46)));
embeddedInstance->addProperty(CIMProperty(CIMName("prop10"),
Real64(-23464234.78)));
embeddedInstance->addProperty(CIMProperty(CIMName("prop11"),
CIMDateTime(60, true)));
// Build the embedded instance
Array<CIMKeyBinding> errorPathKeys;
CIMName errorKeyName("errorKey");
CIMValue errorKeyValue(String("error key 1"));
errorPathKeys.append(CIMKeyBinding(errorKeyName, errorKeyValue));
CIMObjectPath localErrorPath(
"localhost",
TEST_NAMESPACE,
CIMName("PG_EmbeddedError"),
errorPathKeys);
errorInstance.reset(new CIMInstance(CIMName("PG_EmbeddedError")));
errorInstance->setPath(localErrorPath);
errorInstance->addProperty(CIMProperty(errorKeyName,
errorKeyValue));
errorInstance->addProperty(CIMProperty(CIMName("EmbeddedInst"),
CIMValue(*embeddedInstance)));
try
{
errorPath = client.createInstance(TEST_NAMESPACE, *errorInstance);
PEGASUS_STD(cout) << "Created EmbeddedError: " << errorPath.toString()
<< PEGASUS_STD(endl);
errorInstance->setPath(errorPath);
}
catch (Exception& e)
{
PEGASUS_STD(cout) << "Exception while creating Error Instance: "
<< e.getMessage() << PEGASUS_STD(endl);
return -1;
}
return 0;
}
示例10: testGetInstance
/*
testGetInstance of the NIS provider.
*/
void NISTestClient::testGetInstance(
CIMClient &client,
Boolean verboseTest)
{
CIMObjectPath getTestRef; // will need an instance for Get
try
{
Boolean localOnly = true;
Boolean includeQualifiers = false;
Boolean includeClassOrigin = false;
testLog("NIS Provider Test GetInstance");
// first do an EnumerateInstanceNames - select one to play with
// doesn't hurt to keep testing enumerate :-)
Array<CIMObjectPath> cimReferences =
client.enumerateInstanceNames(NAMESPACE, CLASS_NAME);
Uint32 numberInstances = cimReferences.size();
if (verboseTest)
cout << numberInstances << " instances of PG_NISServerService" <<
endl;
for (Uint32 i = 0; i < cimReferences.size(); i++)
{
CIMName className = cimReferences[i].getClassName();
if (!className.equal(CLASS_NAME))
{
errorExit("EnumInstanceNames failed - wrong class");
}
// add in some content checks on the keys returned
if (verboseTest)
cout << " Validate keys of PG_NISServerService ... " <<endl;
_validateKeys(cimReferences[i], verboseTest);
// let's just take the first instance found
getTestRef = cimReferences[i];
} // end for looping through instances
if (verboseTest)
cout << "EnumerateInstanceNames for Get Instance completed" << endl;
// now call GetInstance with the appropriate references
CIMInstance getTestInstance = client.getInstance(
NAMESPACE,
getTestRef,
localOnly,
includeQualifiers,
includeClassOrigin);
// now validate the properties returned
_validateProperties(getTestInstance, verboseTest);
testLog("NIS Provider Test Get Instance passed ");
}
catch(Exception& e)
{
errorExit(e.getMessage());
}
}
示例11: retrieveErrorInstance
int retrieveErrorInstance(CIMClient& client)
{
try
{
PEGASUS_STD(cout) << "Getting error instance: " << errorPath.toString()
<< PEGASUS_STD(endl);
CIMInstance ret = client.getInstance(
TEST_NAMESPACE, errorPath, true, false, false, errorPropList);
ret.setPath(errorPath);
if (!errorInstance->identical(ret))
{
if (!ret.getPath().identical(errorInstance->getPath()))
{
PEGASUS_STD(cout) << "Object Paths not identical"
<< PEGASUS_STD(endl);
}
PEGASUS_STD(cout) << "Error Instance and instance retrieved "
<< "through GetInstance operation not the same\n"
<< PEGASUS_STD(endl);
PEGASUS_STD(cout) << "Local Error Instance: "
<< errorInstance->getPath().toString() << PEGASUS_STD(endl);
for (unsigned int i = 0, n = errorInstance->getPropertyCount();
i < n; i++)
{
CIMProperty prop = errorInstance->getProperty(i);
PEGASUS_STD(cout) << i << ". " << prop.getName().getString()
<< prop.getValue().toString() << PEGASUS_STD(endl);
}
PEGASUS_STD(cout) << "Retrieved Error Instance: " <<
ret.getPath().toString() << PEGASUS_STD(endl);
for (unsigned int i = 0, n = ret.getPropertyCount();
i < n; i++)
{
CIMProperty prop = ret.getProperty(i);
PEGASUS_STD(cout) << i << ". " << prop.getName().getString()
<< prop.getValue().toString() << PEGASUS_STD(endl);
}
CIMProperty localEmbeddedProp = errorInstance->getProperty(
errorInstance->findProperty("EmbeddedInst"));
CIMProperty retEmbeddedProp = ret.getProperty(
ret.findProperty("EmbeddedInst"));
CIMInstance localEmbeddedInst;
CIMInstance retEmbeddedInst;
localEmbeddedProp.getValue().get(localEmbeddedInst);
retEmbeddedProp.getValue().get(retEmbeddedInst);
CIMObjectPath localEmbeddedPath = localEmbeddedInst.getPath();
CIMObjectPath retEmbeddedPath = retEmbeddedInst.getPath();
PEGASUS_STD(cout) << "Local Embedded Path: " <<
localEmbeddedPath.toString() << PEGASUS_STD(endl);
PEGASUS_STD(cout) << "Ret Embedded Path: " <<
retEmbeddedPath.toString() << PEGASUS_STD(endl);
return -1;
}
}
catch (Exception& e)
{
cout << "Exception caught while getting error instance: "
<< e.getMessage() << endl;
return -1;
}
try
{
Array<CIMInstance> ret = client.enumerateInstances(
TEST_NAMESPACE,
"PG_EmbeddedError",
true,
true,
false,
false,
errorPropList);
int count = ret.size();
for (int i = 0; i < count; i++)
{
if (!errorInstance->identical(ret[i]))
{
printf("Error instance and instance retrieved through "
"EnumerateInstances operation not the same\n");
return -1;
}
}
}
catch (Exception& e)
{
cout << "Exception caught while enumerating error instances: "
<< e.getMessage() << endl;
return -1;
}
return 0;
}
示例12: createSubscription
int createSubscription(CIMClient& client)
{
// Create a Listener Destination
CIMInstance destinationInstance("CIM_ListenerDestinationCIMXML");
destinationInstance.addProperty(CIMProperty(
CIMName("SystemCreationClassName"),
System::getSystemCreationClassName()));
// destinationInstance.addProperty(CIMProperty(CIMName("SystemName"),
// System::getFullyQualifiedHostName()));
// destinationInstance.addProperty(CIMProperty(CIMName("CreationClassName"),
// String("CIM_ListenerDestinationCIMXML")));
destinationInstance.addProperty(CIMProperty(CIMName("Name"),
String("EmbeddedInstance Test Handler")));
destinationInstance.addProperty(CIMProperty(CIMName("Destination"),
String("http://localhost:2003")));
try
{
destinationPath =
client.createInstance(TEST_NAMESPACE, destinationInstance);
}
catch (Exception& e)
{
cout << "Exception caught while creating listener destination: "
<< e.getMessage() << endl;
return -1;
}
// Create a Filter
CIMInstance filterInstance("CIM_IndicationFilter");
filterInstance.addProperty(CIMProperty(
CIMName("SystemCreationClassName"),
System::getSystemCreationClassName()));
filterInstance.addProperty(CIMProperty(CIMName("SystemName"),
System::getFullyQualifiedHostName()));
filterInstance.addProperty(CIMProperty(CIMName("CreationClassName"),
String("CIM_IndicationFilter")));
filterInstance.addProperty(CIMProperty(CIMName("Name"),
String("Embedded Instance Test Filter")));
filterInstance.addProperty(CIMProperty(CIMName("Query"),
String("SELECT * FROM PG_InstMethodIndication")));
filterInstance.addProperty(CIMProperty(CIMName("QueryLanguage"),
String("CIM:CQL")));
filterInstance.addProperty(CIMProperty(CIMName("SourceNamespace"),
TEST_NAMESPACE.getString()));
try
{
filterPath = client.createInstance (TEST_NAMESPACE, filterInstance);
}
catch (Exception& e)
{
cout << "Exception caught while creating indication filter: "
<< e.getMessage() << endl;
return -1;
}
// Create a Subscription
CIMInstance subscriptionInstance("CIM_IndicationSubscription");
subscriptionInstance.addProperty(CIMProperty(CIMName("Filter"),
filterPath, 0, "CIM_IndicationFilter"));
subscriptionInstance.addProperty(CIMProperty(CIMName("Handler"),
destinationPath, 0, "CIM_ListenerDestinationCIMXML"));
subscriptionInstance.addProperty(CIMProperty(
CIMName("SubscriptionState"), CIMValue((Uint16) 2)));
try
{
subscriptionPath = client.createInstance(TEST_NAMESPACE,
subscriptionInstance);
}
catch (Exception& e)
{
cout << "Exception caught while creating subscription: "
<< e.getMessage() << endl;
return -1;
}
return 0;
}
示例13: _connectToServer
/**
Connects to cimserver.
@param outPrintWriter the ostream to which error output should be
written
@exception Exception if an error is encountered in creating
the connection
*/
void OSInfoCommand::_connectToServer( CIMClient& client,
ostream& outPrintWriter )
{
String host = String ();
Uint32 portNumber = 0;
Boolean connectToLocal = false;
//
// Construct host address
//
if ((!_hostNameSet) && (!_portNumberSet)
&& (!_userNameSet) && (!_passwordSet))
{
connectToLocal = true;
}
else
{
if (!_hostNameSet)
{
_hostName = System::getHostName();
}
if( !_portNumberSet )
{
if( _useSSL )
{
#ifdef PEGASUS_HAS_SSL
_portNumber = System::lookupPort( WBEM_HTTPS_SERVICE_NAME,
WBEM_DEFAULT_HTTPS_PORT );
#else
PEGASUS_ASSERT(false);
#endif
}
else
{
_portNumber = System::lookupPort( WBEM_HTTP_SERVICE_NAME,
WBEM_DEFAULT_HTTP_PORT );
}
char buffer[32];
sprintf( buffer, "%lu", (unsigned long) _portNumber );
_portNumberStr = buffer;
}
}
host = _hostName;
portNumber = _portNumber;
if( connectToLocal )
{
client.connectLocal();
}
else
{
if (!_userNameSet)
{
_userName = System::getEffectiveUserName();
}
if (!_passwordSet)
{
_password = _promptForPassword( outPrintWriter );
}
if( _useSSL )
{
#ifdef PEGASUS_HAS_SSL
//
// 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_ASSERT(false);
#endif
}
else
{
client.connect(host, portNumber, _userName, _password );
}
}
//.........这里部分代码省略.........
示例14: _testCMPIFilterOfAssociation
void _testCMPIFilterOfAssociation(CIMClient& client)
{
try
{
Array<CIMObjectPath> personRefs;
Uint32 numPersonInstances ;
personRefs =
client.enumerateInstanceNames(providerNamespace,CMPI_TEST_PERSON);
numPersonInstances = personRefs.size();
CIMName resultClass;
String role;
String resultRole;
cout<<"++++++++Filtering the NULL propery list+++"<<endl;
for (Uint32 i = 0; i < numPersonInstances; ++i)
{
Array<CIMObject> resultObjects =
client.associators(
providerNamespace,
personRefs[i],
CMPI_TEST_RACING,
resultClass,
role,
resultRole,
false,
false,
CIMPropertyList());
Uint32 size = resultObjects.size();
for(Uint32 j = 0;j<size;j++)
{
Uint32 propCount = resultObjects[j].getPropertyCount();
Uint32 propNameCount = 0;
if(propCount != 0)
{
String propName=
resultObjects[j].getProperty(0).getName().getString();
if(verbose)
{
cout<<"Property Name of :"<<i<<":"<<propName<<endl;
}
if(propName == "vehiclename")
{
propNameCount++;
}
}
if((size != 0)&&(propCount == 1) &&(propNameCount == 1))
{
cout<<"Filter associator test on CMPI_TEST_RACING SUCCEEDED"
<<":Filtering the ciminstance with a NULL property list"
<<" returned all properties as expected"<<endl;
}
else
{
cout<<"Filter associator test on CMPI_TEST_RACING FAILED"
<<":Filtering the ciminstance with a NULL property list"
<<" did not return all properties as expected"<<endl;
PEGASUS_TEST_ASSERT(false);
}
}
}
cout<<"++++++Filtering the empty propery list+++"<<endl;
Array<CIMName> propList;
for (Uint32 i = 0; i < numPersonInstances; ++i)
{
Array<CIMObject> resultObjects =
client.associators(
providerNamespace,
personRefs[i],
CMPI_TEST_RACING,
resultClass,
role,
resultRole,
false,
false,
CIMPropertyList(propList));
Uint32 size = resultObjects.size();
for(Uint32 j = 0;j<size;j++)
{
Uint32 propCount = resultObjects[j].getPropertyCount();
if((size != 0)&&(propCount == 0))
{
cout<<"Filter associator test on CMPI_TEST_RACING SUCCEEDED"
<<":Filtering the ciminstance with a empty property "
<<"list returned zero properties as expected"<<endl;
}
else
{
cout<<"Filter associators test on CMPI_TEST_RACING FAILED"
<<":Filtering the ciminstance with a empty property "
<<"list returned some properties which is not expected"
<<endl;
PEGASUS_TEST_ASSERT(false);
}
}
}
cout<<"+++filtering the wrong properties ++++++"<<endl;
Array<CIMName> propList1;
propList1.append(CIMName(String("nam")));
for (Uint32 i = 0; i < numPersonInstances; ++i)
{
//.........这里部分代码省略.........
示例15: call_func
void call_func()
{
try
{
// Connect.
CIMClient client;
client.connectLocal();
//
// uint32 AssignSpares(
// [IN(false), OUT] CIM_ConcreteJob REF Job,
// [IN, OUT(false)] CIM_StoragePool REF InPool,
// [Required, IN, OUT (false)] CIM_StorageExtent REF InExtents[],
// [IN, OUT (false)] CIM_StorageRedundancySet REF RedundancySet);
//
// Build input arguments.
Array<CIMParamValue> in;
// InPool:
CIMObjectPath InPool("CIM_StoragePool.InstanceID=\"1\"");
in.append(CIMParamValue("InPool", InPool));
// InExtents:
CIMObjectPath StorageExtent(
"root/cimv2:MyStorageExtent."
"CreationClassName=\"Aristos_DiskStorageExtent\","
"DeviceID=\"3:5000c500003ac807\","
"SystemCreationClassName=\"Aristos_ControllerSystem\","
"SystemName=\"500062E987654391\"");
Array<CIMObjectPath> InExtents;
InExtents.append(StorageExtent);
InExtents.append(StorageExtent);
InExtents.append(StorageExtent);
in.append(CIMParamValue("InExtents", InExtents));
// RedundancySet:
CIMObjectPath RedundancySet(
"CIM_StorageRedundancySet.InstanceID=\"1\"");
in.append(CIMParamValue("RedundancySet", RedundancySet));
// Invoke method.
CIMObjectPath target("SNIA_SpareConfigurationService."
"SystemCreationClassName=\"Mike\","
"SystemName=\"Mike\","
"CreationClassName=\"SNIA_SpareConfigurationService\"");
Array<CIMParamValue> out;
CIMValue value = client.invokeMethod(
"root/cimv2",
target,
"AssignSpares",
in,
out);
// Expect one output argument.
assert(out.size() == 1);
// Check return value.
assert(value.getType() == CIMTYPE_UINT32);
Uint32 return_value = 0;
value.get(return_value);
assert(return_value == 100);
}
catch(Exception& e)
{
cerr << "Error: " << e.getMessage() << endl;
exit(1);
}
}