📄 interop.cpp
字号:
} Array<CIMInstance> instances = _client.enumerateInstances(next, 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 a 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. But, this means that namespaces that may be valid but that // have no contents do not show up on this list. Array<CIMNamespaceName> returnNamespaceNames; for (Uint32 i = 0 ; i < namespaceNames.size() ; i++) { try { CIMQualifierDecl cimQualifierDecl; cimQualifierDecl = _client.getQualifier(namespaceNames[i], "Association"); returnNamespaceNames.append(namespaceNames[i]); } catch(CIMException& e) { if (e.getCode() != CIM_ERR_INVALID_NAMESPACE) returnNamespaceNames.append(namespaceNames[i]); } } return(returnNamespaceNames);}Boolean InteropTest::_deleteOneLevelOfNamespace(const CIMNamespaceName& parent, const String & child){ try { CIMObjectPath myReference(String::EMPTY, parent, child); _client.deleteInstance(parent, myReference); } catch(Exception& e) { PEGASUS_STD(cerr) << "Exception NameSpace Deletion: " << e.getMessage() << " Deleting " << child << " from " << parent << PEGASUS_STD(endl); return(false); } return(true);}/* Delete the namespace defined by the input. This function uses the __Namspace tools to do the delete.*/Boolean InteropTest::_deleteNamespaceOld(const String & name){ Uint32 pos; while((pos = name.reverseFind('/')) != PEG_NOT_FOUND) { String parent = name.subString(0, pos); String child = name.subString (pos + 1); Boolean rtn = _deleteOneLevelOfNamespace(CIMNamespaceName(parent), child); if(!rtn) return(false); } return(true);}Boolean InteropTest::_validateNamespaces(Array<CIMNamespaceName>& namespaceNames){ // Validate that these are all namespaces. This is not a certain // Test but we simply check to see if there is an association // qualifier in the namespace. If the call returns the // invalidNamespace exception, assume this is not valid namespace. 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 (verbose) { cout << returnNamespaces.size() << " namespaces " << " returned." << endl; for( Uint32 cnt = 0 ; cnt < returnNamespaces.size(); cnt++ ) { cout << returnNamespaces[cnt] << endl;; } } if (returnNamespaces.size() == namespaceNames.size()) return(true); else return(false);}/* Deleted for nowBoolean _existsOld(CIMNamespaceName& name){ Uint32 pos; String parent = String::EMPTY; String child; String nameString = name.getString(); if((pos = nameString.reverseFind('/')) != PEG_NOT_FOUND) { parent = nameString.subString(0, pos); child = nameString.subString (pos + 1); } else { child = nameString; } Array<CIMKeyBinding> keyBindings; // wrong ATTN: This not good. keyBindings.append(CIMKeyBinding(NAMESPACE_PROPERTYNAME, isRelativeName?childNamespaceName.getString(): parentNamespaceName.getString(), CIMKeyBinding::STRING)); CIMObjectPath ref(String::EMPTY, parent, child); try { CIMInstance instance.getInstance(parent, ref); } catch(CIMException& e) { cerr << "Exception NameSpace query: " << e.getMessage() << " querying " << name << endl; } return(true);}************************************************//* gets the instances for the CIM_Namespace class from host*/Array<CIMInstance> InteropTest::_getCIMNamespaceInstances(){ Array<CIMInstance> instances; try { instances = _client.enumerateInstances(PEGASUS_NAMESPACENAME_INTEROP, CIM_NAMESPACE_CLASSNAME); } catch(Exception& e) { cerr << "Error: " << e.getMessage() << " Conection term abnormal" << endl; // Instead of this returns emptyexit(1); } return(instances);}/* gets the instances for the CIM_Namespace class from host*/Array<CIMInstance> InteropTest::_getPGNamespaceInstances(){ Array<CIMInstance> instances; try { instances = _client.enumerateInstances(PEGASUS_NAMESPACENAME_INTEROP, PG_NAMESPACE_CLASSNAME); } catch(Exception& e) { cerr << "Error: " << e.getMessage() << " Conection term abnormal" << endl; // Instead of this returns emptyexit(1); } return(instances);}/* gets the instancenames for the CIM_Namespace class from host*/Array<CIMObjectPath> InteropTest::_getPGNamespaceInstanceNames(){ Array<CIMObjectPath> objectNames; try { objectNames = _client.enumerateInstanceNames(PEGASUS_NAMESPACENAME_INTEROP, PG_NAMESPACE_CLASSNAME); } catch(Exception& e) { cerr << "Error: " << e.getMessage() << " Conection term abnormal" << endl; // Instead of this returns emptyexit(1); } return(objectNames);}/* gets the instancenames for the CIM_Namespace class from host*/Array<CIMObjectPath> InteropTest::_getCIMNamespaceInstanceNames(){ Array<CIMObjectPath> objectNames; try { objectNames = _client.enumerateInstanceNames(PEGASUS_NAMESPACENAME_INTEROP, CIM_NAMESPACE_CLASSNAME); } catch(Exception& e) { cerr << "Error: " << e.getMessage() << " Conection term abnormal" << endl; // Instead of this returns emptyexit(1); } return(objectNames);}/* find the name key in the keybindings and return the value. Executes exception if the key not found @param object path we will search @param keyName - Name of the key to find. @return value of name property @exceptions CIMInvalidParameterException NOTE: This one is a real NO NO. Should never have been written this way. We should be getting the value from the instance, not the keys.*/String _getKeyValue(const CIMObjectPath& instanceName, const CIMName& keyName){ Array<CIMKeyBinding> kbArray = instanceName.getKeyBindings(); // find the correct key binding for (Uint32 i = 0; i < kbArray.size(); i++) { if (kbArray[i].getName() == keyName) { return (kbArray[i].getValue()); } } cerr <<"_getKeyValue: Invalid key property: " << keyName.getString()<< endl; return(String::EMPTY);}// Get the key value from the instance for the keyName definedString _getKeyValue(const CIMInstance& instance, const CIMName& keyName){ Uint32 pos; CIMValue propertyValue; pos = instance.findProperty(keyName); if (pos == PEG_NOT_FOUND) { cerr << "_getKeyValue Error. Property " << keyName.getString() << " not found " << endl; return(String::EMPTY); } propertyValue = instance.getProperty(pos).getValue(); if (propertyValue.getType() != CIMTYPE_STRING) { cerr << "Key Property " << keyName.getString() << " incorrect type" << endl; return(String::EMPTY); } String name; propertyValue.get(name); return(name);}/** get the namespaceNames into an array. return array of CIMNamespaceName containing the names of all namespaces found through the CIM_Namespace class*/Array<CIMNamespaceName> InteropTest::_getNamespacesNew(){ Array<CIMObjectPath> instanceNames; instanceNames = _getCIMNamespaceInstanceNames(); Array<CIMNamespaceName> rtns; for (Uint32 i = 0 ; i < instanceNames.size(); i++) { String name = _getKeyValue(instanceNames[i], NAMESPACE_PROPERTYNAME); if (name == String::EMPTY) { continue; } rtns.append(CIMNamespaceName(name)); } return(rtns);}/** get one string property from an instance. Note that these functions simply return the default value if the property cannot be found or is of the wrong type thus, in reality being a maintenance problem since there is no error indication. @param instance CIMInstance from which we get property value @param propertyName String name of the property containing the value @param default String optional parameter that is substituted if the property does not exist, is Null, or is not a string type. The substitute is String::EMPTY @return String value found or defaultValue.*/void _getPropertyValue(const CIMInstance& instance, const CIMName& propertyName, const String& defaultValue, String & returnValue){ returnValue = defaultValue; Uint32 pos; if ((pos = instance.findProperty(propertyName)) != PEG_NOT_FOUND) { CIMConstProperty p1 = instance.getProperty(pos); if (p1.getType() == CIMTYPE_STRING) { CIMValue v1 = p1.getValue(); if (!v1.isNull()) v1.get(returnValue); } }}// Overload of _getPropertyValue for boolean typevoid _getPropertyValue(const CIMInstance& instance, const CIMName& propertyName, const Boolean defaultValue, Boolean returnValue){ returnValue = defaultValue; Uint32 pos; if ((pos = instance.findProperty(propertyName)) != PEG_NOT_FOUND) { CIMConstProperty p1 = instance.getProperty(pos); if (p1.getType() == CIMTYPE_BOOLEAN) { CIMValue v1 = p1.getValue(); if (!v1.isNull()) v1.get(returnValue); } }}void InteropTest::_showNamespaceInfo(const String& title){ Array<CIMInstance> instances; instances = _getCIMNamespaceInstances(); cout << title << " size = " << instances.size() << endl; Array<CIMNamespaceName> rtns; for (Uint32 i = 0 ; i < instances.size(); i++) { String isSharable = String::EMPTY; String updatesAllowed = String::EMPTY; String parent = String::EMPTY; String name = String::EMPTY;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -