deletenamespace.cpp
来自「Pegasus is an open-source implementation」· C++ 代码 · 共 640 行 · 第 1/2 页
CPP
640 行
//%2006//////////////////////////////////////////////////////////////////////////// Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development// Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;// IBM Corp.; EMC Corporation, The Open Group.// Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;// IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.// Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;// EMC Corporation; VERITAS Software Corporation; The Open Group.// Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;// EMC Corporation; Symantec Corporation; The Open Group.//// Permission is hereby granted, free of charge, to any person obtaining a copy// of this software and associated documentation files (the "Software"), to// deal in the Software without restriction, including without limitation the// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or// sell copies of the Software, and to permit persons to whom the Software is// furnished to do so, subject to the following conditions:// // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.////==============================================================================//// Author: Warren Otsuka (warren_otsuka@hp.com)//// Modified By: Carol Ann Krug Graves, Hewlett-Packard Company// (carolann_graves@hp.com)// Sean Keenan (sean.keenan@hp.com)////%/////////////////////////////////////////////////////////////////////////////#include <Pegasus/Common/Config.h>#include <Pegasus/Common/Constants.h>#include <Pegasus/Common/PegasusVersion.h>#include <Pegasus/Common/PegasusAssert.h>#include <Pegasus/Common/TLS.h>#include <Pegasus/Client/CIMClient.h>#include <Pegasus/Common/CIMName.h>#include <Pegasus/Common/OptionManager.h>#include <Pegasus/Common/FileSystem.h>#include <Pegasus/Common/Stopwatch.h>#include <Pegasus/Common/Exception.h>#include <Pegasus/Common/XmlWriter.h>PEGASUS_USING_PEGASUS;PEGASUS_USING_STD;CIMNamespaceName globalNamespace = CIMNamespaceName ("root/cimv2");static const CIMNamespaceName __NAMESPACE_NAMESPACE = CIMNamespaceName ("root");static const CIMName CLASSNAME = CIMName ("__Namespace");/** ErrorExit - Print out the error message as an and get out. @param - Text for error message @return - None, Terminates the program @execption - This function terminates the program ATTN: Should write to stderr*/void ErrorExit(const String& message){ cout << message << endl; exit(1);}/* Status display of the various steps. Shows message of function andtime to execute. Grow this to a class so we have start and stop and timedisplay with success/failure for each function.*/static void testStart(const String& message){ cout << "++++ " << message << " ++++" << endl;}static void testEnd(const double elapsedTime){ cout << "In " << elapsedTime << " Seconds\n\n";}static Boolean verifyServerCertificate(SSLCertificateInfo &certInfo){ //ATTN-NB-03-05132002: Add code to handle server certificate verification. return true;}/*****************************************************************// Test Namespaces Hierarchy - Relative Path Name******************************************************************/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); exit(1); } } if(verboseTest) cout << "++ Delete 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(Exception& e) { PEGASUS_STD(cerr) << "Exception NameSpace Deletion 2: " << e.getMessage() << " Deleting " << instanceName << PEGASUS_STD(endl); exit(1); } }}/*****************************************************************// Test Namespaces Hierarchy - Full Path Name******************************************************************/static void TestNamespaceHierarchy2 ( 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 instanceName.clear(); instanceName.append(CLASSNAME.getString()); instanceName.append( ".Name=\"\""); try { CIMObjectPath myReference(instanceName); if(verboseTest) cout << "Deleting " << namespaces[i] << endl; client.deleteInstance(namespaces[i], 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++) { try { // Build the new instance CIMInstance newInstance(CLASSNAME); newInstance.addProperty(CIMProperty(CIMName ("name"), String::EMPTY)); if(verboseTest) { cout << "Creating " << namespaces[i] << endl; } client.createInstance(namespaces[i], newInstance); } catch(Exception& e) { PEGASUS_STD(cerr) << "Exception NameSpace Creation: " << e.getMessage() << " Creating " << namespaces[i] << PEGASUS_STD(endl); exit(1); } } if(verboseTest) cout << "++ Delete 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=\"\""); try {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?