1 martin 1.8 //%LICENSE////////////////////////////////////////////////////////////////
|
2 martin 1.9 //
|
3 martin 1.8 // Licensed to The Open Group (TOG) under one or more contributor license
4 // agreements. Refer to the OpenPegasusNOTICE.txt file distributed with
5 // this work for additional information regarding copyright ownership.
6 // Each contributor licenses this file to you under the OpenPegasus Open
7 // Source License; you may not use this file except in compliance with the
8 // License.
|
9 martin 1.9 //
|
10 martin 1.8 // Permission is hereby granted, free of charge, to any person obtaining a
11 // copy of this software and associated documentation files (the "Software"),
12 // to deal in the Software without restriction, including without limitation
13 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 // and/or sell copies of the Software, and to permit persons to whom the
15 // Software is furnished to do so, subject to the following conditions:
|
16 martin 1.9 //
|
17 martin 1.8 // The above copyright notice and this permission notice shall be included
18 // in all copies or substantial portions of the Software.
|
19 martin 1.9 //
|
20 martin 1.8 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
21 martin 1.9 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
22 martin 1.8 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
27 martin 1.9 //
|
28 martin 1.8 //////////////////////////////////////////////////////////////////////////
|
29 kumpf 1.1 //
30 //%/////////////////////////////////////////////////////////////////////////////
31
32 #include <cstring>
33
34 // The nisinfo CIM client does an enumerateInstances of the
35 // PG_NISServerService class and displays properties of interest.
36
|
37 kumpf 1.10 // At this time, there is only one instance of PG_NISServerService.
|
38 kumpf 1.1
|
39 kumpf 1.10 #include "NISInfo.h"
|
40 kumpf 1.1
41 PEGASUS_USING_PEGASUS;
42 PEGASUS_USING_STD;
43
44 #define NAMESPACE CIMNamespaceName ("root/cimv2")
45 #define CLASSNAME CIMName ("PG_NISServerService")
46
47 /** Constructor
48 */
|
49 kumpf 1.5 NISInfo::NISInfo()
|
50 kumpf 1.1 {
51 }
52
|
53 kumpf 1.5 NISInfo::~NISInfo()
|
54 kumpf 1.1 {
|
55 kumpf 1.10 }
|
56 kumpf 1.1
57 /** ErrorExit - Print out the error message and get out.
58 @param Text for error message
59 @return None, Terminates the program
60 @exception This function terminates the program
61 */
62 void NISInfo::errorExit(const String& message)
63 {
64 cerr << "nisinfo error: " << message << endl;
65 exit(1);
66 }
67
68 /** _usage method for nisinfo
69 */
70 void NISInfo::_usage()
71 {
72 cerr << "Usage: nisinfo " << endl;
73 }
74
75 /**
76 displayProperties method of the nisinfo Test Client
77 kumpf 1.1 */
78 void NISInfo::displayProperties()
79 {
80 // interesting properties are stored off in class variables
|
81 kumpf 1.10 String strTit;
82 Array<String> cTit;
|
83 kumpf 1.1
84 cout << "Network Information Service (NIS) Information" << endl;
85 cout << endl;
86
87 // expect to have values for the properties (even if Unknown) (do not remove)
88
89 cout << " SystemCreationClassName: " << nisSystemCreationClassName << endl;
90 cout << " SystemName : " << nisSystemName << endl;
91 cout << " CreationClassName : " << nisCreationClassName << endl;
92 cout << " Name : " << nisName << endl;
93 cout << " Caption : " << nisCaption << endl;
94 cout << " Description : " << nisDescription << endl;
95
96 cTit.clear();
97 cTit.append("Unknown");
98 cTit.append("Other");
99 cTit.append("None");
100 cTit.append("NIS Master");
101 cTit.append("NIS Slave");
|
102 kumpf 1.10 cout << " ServerType : "
103 << CIMValue(nisServerType).toString().getCString()
104 << " (" << cTit[nisServerType].getCString() << ")" << endl;
|
105 kumpf 1.1
106 cTit.clear();
107 cTit.append("Unknown");
108 cTit.append("Other");
109 cTit.append("Wait");
110 cTit.append("No Wait");
|
111 kumpf 1.10 cout << " ServerWaitFlag : "
112 << CIMValue(nisServerWaitFlag).toString().getCString()
113 << " (" << cTit[nisServerWaitFlag].getCString() << ")" << endl;
|
114 kumpf 1.1 }
115
116 /**
117 gatherProperties method of the nisinfo Test Client
118 */
|
119 kumpf 1.10 void NISInfo::gatherProperties(CIMInstance &inst)
|
120 kumpf 1.1 {
121 #ifdef DEBUG
122 cout << "NISInfo::gatherProperties()" << endl;
123 #endif
124 // don't have a try here - want it to be caught by caller
125
126 // loop through the properties
127 for (Uint32 j=0; j < inst.getPropertyCount(); j++)
128 {
129 CIMName propertyName = inst.getProperty(j).getName();
130
131 // only pull out those properties of interest (do not remove)
132
133 if (propertyName.equal (CIMName ("SystemCreationClassName")))
134 {
135 inst.getProperty(j).getValue().get(nisSystemCreationClassName);
136 } // end if SystemCreationClassName
137
138 if (propertyName.equal (CIMName ("SystemName")))
139 {
140 inst.getProperty(j).getValue().get(nisSystemName);
141 kumpf 1.1 } // end if SystemName
142
143 if (propertyName.equal (CIMName ("CreationClassName")))
144 {
145 inst.getProperty(j).getValue().get(nisCreationClassName);
146 } // end if CreationClassName
147
148 if (propertyName.equal (CIMName ("Name")))
149 {
150 inst.getProperty(j).getValue().get(nisName);
151 } // end if Name
152
153 if (propertyName.equal (CIMName ("Caption")))
154 {
155 inst.getProperty(j).getValue().get(nisCaption);
156 } // end if Caption
157
158 if (propertyName.equal (CIMName ("Description")))
159 {
160 inst.getProperty(j).getValue().get(nisDescription);
161 } // end if Description
162 kumpf 1.1
163 if (propertyName.equal (CIMName ("ServerType")))
164 {
165 inst.getProperty(j).getValue().get(nisServerType);
166 } // end if ServerType
167
168 if (propertyName.equal (CIMName ("ServerWaitFlag")))
169 {
170 inst.getProperty(j).getValue().get(nisServerWaitFlag);
171 } // end if ServerWaitFlag
172 } // end of for looping through properties
173 }
174
|
175 kumpf 1.10 /*
176 getNISInfo of the NIS provider.
|
177 kumpf 1.1 */
178 void NISInfo::getNISInfo(const int argc, const char** argv)
179 {
180 String hostname;
181 String user;
182 String passwd;
183
184 // before we even connect to CIMOM, make sure we're
185 // syntactically valid
186
187 if (argc > 1)
188 {
189 _usage();
190 exit(1);
191 }
192
193 // need to first connect to the CIMOM
194
195 try
196 {
197 // specify the timeout value for the connection (if inactive)
198 kumpf 1.1 // in milliseconds, thus setting to one minute
199 CIMClient client;
200 client.setTimeout(120 * 1000);
|
201 kumpf 1.10
|
202 karl 1.6 client.connectLocal();
|
203 kumpf 1.10
|
204 kumpf 1.1 Boolean deepInheritance = true;
205 Boolean localOnly = true;
206 Boolean includeQualifiers = false;
207 Boolean includeClassOrigin = false;
208 Uint32 numberInstances;
209
210 #ifdef DEBUG
211 cout << "NISInfo::getNISInfo() - doing enumerateInstances . . ."
212 << endl;
213 #endif
214
|
215 kumpf 1.10 Array<CIMInstance> cimNInstances =
216 client.enumerateInstances(NAMESPACE, CLASSNAME,
|
217 karl 1.6 deepInheritance,
|
218 kumpf 1.10 localOnly,
|
219 karl 1.6 includeQualifiers,
220 includeClassOrigin );
|
221 kumpf 1.1
222 #ifdef DEBUG
223 cout << "NISInfo::getNISInfo() - enumerateInstances done" << endl;
224 #endif
|
225 kumpf 1.10
|
226 kumpf 1.1 numberInstances = cimNInstances.size();
227
228 for (Uint32 i = 0; i < cimNInstances.size(); i++)
229 {
230 CIMObjectPath instanceRef = cimNInstances[i].getPath ();
231 if ( !(instanceRef.getClassName().equal (CIMName (CLASSNAME))))
232 {
233 errorExit("EnumerateInstances failed");
234 }
235
236 // first gather the interesting properties
237 gatherProperties(cimNInstances[i]);
|
238 kumpf 1.10
|
239 kumpf 1.1 // then display them
240 displayProperties();
241
242 } // end for looping through instances
243 }
244 catch(Exception& e)
245 {
246 errorExit(e.getMessage());
247 }
248 }
249
250 ///////////////////////////////////////////////////////////////
251 // MAIN
252 ///////////////////////////////////////////////////////////////
253
254 int main(const int argc, const char** argv)
255 {
256 NISInfo nisInfo;
257 nisInfo.getNISInfo(argc, argv);
258 return 0;
259 }
260 kumpf 1.1
|