📄 interop.cpp
字号:
// get the namespace name from the name property. if ((instances[i].findProperty(NAMESPACE_PROPERTYNAME)) == PEG_NOT_FOUND) isSharable = "ERROR: Name Property Not Found"; else { _getPropertyValue(instances[i],NAMESPACE_PROPERTYNAME, String("ERROR: No Name Property Value"), name); } // if this is a PG_Namespace, get the other characteristics. if (instances[i].getClassName() == PG_NAMESPACE_CLASSNAME) { // Get the sharable property if ((instances[i].findProperty("IsShareable")) == PEG_NOT_FOUND) isSharable = "Property Not Found"; else { Boolean boolRtn = false; _getPropertyValue(instances[i],"IsShareable", false, boolRtn); isSharable = boolRtn? "true" : "false"; } // get the schemUpdatesAllowed property information if ((instances[i].findProperty("SchemaUpdatesAllowed")) == PEG_NOT_FOUND) isSharable = "Property Not Found"; else { Boolean boolRtn = false; _getPropertyValue(instances[i],"SchemaUpdatesAllowed", false, boolRtn); updatesAllowed = boolRtn ? "true" : "false"; } // get the schemUpdatesAllowed property information if ((instances[i].findProperty("ParentNamespace")) == PEG_NOT_FOUND) isSharable = "Property Not Found"; else { _getPropertyValue(instances[i],"ParentNamespace", String("No parent"), parent); } } printf("%-20s %-10s %-10s %-10s\n", (const char *)name.getCString(), (const char *)isSharable.getCString(), (const char *)updatesAllowed.getCString(), (const char *)parent.getCString()); }}void _showNamespaceList(const Array<CIMNamespaceName> names, const String& title){ cout << title << " size = " << names.size() << endl; for (Uint32 i = 0; i < names.size(); i++) { cout << " " << names[i].getString() << endl; }}// Determine if the named namespace exists in the host.// gets all namespaces and compares for this one.Boolean InteropTest::_existsNew(const CIMNamespaceName& name){ //Get all namespace instances Array<CIMNamespaceName> namespaceNames = _getNamespacesNew(); for(Uint32 i = 0; i < namespaceNames.size(); i++) { if(namespaceNames[i].equal ( name )) return true; } return false;}/* Create a single namespace with __Namespace Class. @param parent CIMNameSpaceName defining the parent namespace for this operation @param childname */Boolean InteropTest::_namespaceCreate__Namespace(const CIMNamespaceName& parent, const String& child){ CIMObjectPath newInstanceName; try { // Build the new instance CIMInstance newInstance(__NAMESPACE_CLASSNAME); newInstance.addProperty(CIMProperty(CIMName (NAMESPACE_PROPERTYNAME), child)); newInstanceName = _client.createInstance(parent, newInstance); } catch(CIMException& e) { if (e.getCode() == CIM_ERR_ALREADY_EXISTS) { PEGASUS_STD(cerr) << "CIMException: NameSpace Creation: " << e.getMessage() << ". " << parent << "/" << child << " Already Exists. Cannot create." << PEGASUS_STD(endl); } else { PEGASUS_STD(cerr) << "CIMException: NameSpace Creation: " << e.getMessage() << " Creating " << parent << "/" << child << PEGASUS_STD(endl); } return(false); } catch(Exception& e) { PEGASUS_STD(cerr) << "Exception: NameSpace Creation with __Namespace: " << e.getMessage() << PEGASUS_STD(endl); return(true); } return(true);}/** Create a single namespace using PG_Namespace. Creates the namespace with the name defined in the call by creating a new instance of PG_Namespace. @param name - CIMNamespaceName of namespace to create. @param CIMNamespaceName ns is optional parameter that defines the name of the CIMServer namespace to be used as the target for the instance create. This option is only used to test for ability to create namespaces in other than the defined interop namespace. @return - true if creeate. False if not created or if it already exists.*/Boolean InteropTest::_namespaceCreatePG_Namespace(const CIMNamespaceName& name){ // Does this namespace exist. if (_existsNew(name)) return(false); //Now build the new namespace name instance. Note that we need to get the // collection of keys that are required. Easy way was to simply // use an existing instance and change the name field. Array<CIMInstance> instances = _getCIMNamespaceInstances(); if(instances.size() == 0) { return(false); } // El cheapo code Modify one existing instance and send it back as // method to construct the correct keys. CIMInstance instance = instances[0]; // remove the qualifiers, etc. // NOTE should do this as part of the get. instance.filter(false, false, CIMPropertyList()); // Modify the name property value for new name Uint32 pos = instance.findProperty(NAMESPACE_PROPERTYNAME); if (pos == PEG_NOT_FOUND) { cerr << "Error in property on create. No " << NAMESPACE_PROPERTYNAME << " property" << endl; return(false); } // Modify the name field in the instance and resend String localName = name.getString(); CIMProperty p = instance.getProperty(pos); // test for correct property type, etc. p.setValue(localName); instance.removeProperty(pos); instance.addProperty(p); if (verbose) { cout << "Show instance used to do namespace create: " << endl; XmlWriter::printInstanceElement(instance); } try { CIMObjectPath path; path = _client.createInstance(PEGASUS_NAMESPACENAME_INTEROP, instance); } catch(Exception& e) { cerr << "Error during Creation of " << name.getString() << " in Namespace " << PEGASUS_NAMESPACENAME_INTEROP << ": " << e.getMessage() << " Instance Creation error" << endl; return(false); } return(true);}/** Create a single namespace using CIM_Namespace. @param name CIMNamespaceName of namespace to create @param target CIMNamespaceName of namespace in which we issue the command to create the namespace. This paramater is primarily to test if we can issue this operation in namespaces other than the interop namespace.*/Boolean InteropTest::_namespaceCreateCIM_Namespace(const CIMNamespaceName& name, const CIMNamespaceName& targetNamespace){ // Does this namespace exist. if (_existsNew(name)) { cout << "Namespace " << name.getString() << " already Exists in _namespacCreateCIM_Namespace function." << endl; return(false); } //Now build the new namespace name instance. Note that we need to get the // collection of keys that are required. Easy way was to simply // use an existing instance and change the name field. Array<CIMInstance> instances = _getCIMNamespaceInstances(); if(instances.size() == 0) { return(false); } // Modify one existing instance and send it back as // method to construct the correct keys. CIMInstance instance = instances[0]; CIMInstance newInstance(CIM_NAMESPACE_CLASSNAME); for (Uint32 i = 0 ; i < instance.getQualifierCount() ; i++) { newInstance.addQualifier(instance.getQualifier(i).clone()); } Array<CIMName> droplist; droplist.append("SchemaUpdatesAllowed"); droplist.append("IsShareable"); droplist.append("ParentNamespace"); for (Uint32 i = 0 ; i < instance.getPropertyCount() ; i++) { for (Uint32 j = 0 ; j < droplist.size() ; j++) { if (Contains(droplist, instance.getProperty(i).getName())) { break; } } newInstance.addProperty(instance.getProperty(i).clone()); } // remove the qualifiers, etc. // NOTE should do this as part of the get. instance.filter(false, false, CIMPropertyList()); // Modify the name property value for new name Uint32 pos = instance.findProperty(NAMESPACE_PROPERTYNAME); if (pos == PEG_NOT_FOUND) { cerr << "Error in property on create. No " << NAMESPACE_PROPERTYNAME << " property" << endl; return(false); } // Modify the name field in the instance and resend String localName = name.getString(); CIMProperty p = instance.getProperty(pos); // test for correct property type, etc. p.setValue(localName); instance.removeProperty(pos); instance.addProperty(p); if (verbose) { cout << "Show instance used to do namespace create: " << endl; XmlWriter::printInstanceElement(instance); } try { CIMObjectPath path; path = _client.createInstance(targetNamespace, instance); } catch(CIMException& e) { if ((e.getCode() != CIM_ERR_INVALID_CLASS) && (e.getCode() != CIM_ERR_NOT_SUPPORTED)) { cerr << "CIMException during Creation of " << name.getString() << " in namespace " << targetNamespace << ": " << e.getMessage() << " CIM_Namespace Instance Creation error" << endl; } return(false); } catch(Exception& e) { cerr << "Exception during Creation of " << name.getString() << ": " << e.getMessage() << " CIM_Namespace Instance Creation error" << endl; return(false); } return(true);}Boolean InteropTest::_testPGNamespace(const CIMNamespaceName& name, Boolean shared, Boolean updatesAllowed, const String& parent){ // get the instance // We only get PG Namespaces because these characteristics would // not exist for any CIMNamespace. // TODO: There should NOT be any CIMNamespaces so we should be able // to enumerate at that level successfully. Array<CIMObjectPath> paths = _getPGNamespaceInstanceNames(); CIMInstance instance; for (Uint32 i = 0 ; i < paths.size() ; i++ ) { String testString = paths[i].toString(); //TODO.poor test. if (testString.find("CIM_Namespace" != 0)) { continue; } if (testString.find(name.getString()) != 0) { // get this instance. instance = _client.getInstance(PEGASUS_NAMESPACENAME_INTEROP, paths[i], false, //lo true, //includeQualifiers true, //includeClassOrigin CIMPropertyList()); } // // Match the properties in the instance against the method inputs. // String errorMsg ("NamespaceInstance: "); errorMsg.append(paths[i].toString()); if ((instance.findProperty("IsShareable")) == PEG_NOT_FOUND) { cerr << errorMsg << ". Property IsShareable not found" << endl; return(false); } else { Boolean boolRtn = false; _getPropertyValue(instance,"IsShareable", false, boolRtn); if (boolRtn != shared) { cout << errorMsg << ". Error in sharing" << endl; return(false); } } // test for shared property if ((instance.findProperty("SchemaUpdatesAllowed")) == PEG_NOT_FOUND) cerr << errorMsg << "Property SchemaUpdatesAllowed not found" << endl; else { Boolean boolRtn = false; _getPropertyValue(instance,"SchemaUpdatesAllowed", false, boolRtn); if (boolRtn != updatesAllowed) { cerr << errorMsg << ". Error in SchemaUpdatesAllowed" << endl; return(false); } } if ((instance.findProperty("ParentNamespace")) == PEG_NOT_FOUND) cerr << errorMsg << "Property " << "ParentNamespace" << " not found" << endl; else { String rtnParent; _getPropertyValue(instance, "ParentNamespace", String("No parent"), rtnParent); if (parent != rtnParent ) { cerr << errorMsg <<". Error in ParentNamespace" << endl; return(false); } } } return(true);}/** Create a single namespace using PG_Namespace. Creates namespace with the
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -