Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

638 lines
17 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1999-2002 Microsoft Corporation
  4. //
  5. // Module Name: CClusterNode.cpp
  6. //
  7. // Description:
  8. // Implementation of CClusterNode class
  9. //
  10. // Author:
  11. // Henry Wang (HenryWa) 24-AUG-1999
  12. //
  13. //////////////////////////////////////////////////////////////////////////////
  14. #include "Pch.h"
  15. #include "ClusterNode.h"
  16. //****************************************************************************
  17. //
  18. // CClusterNode
  19. //
  20. //****************************************************************************
  21. //////////////////////////////////////////////////////////////////////////////
  22. //++
  23. //
  24. // CClusterNode::CClusterNode
  25. //
  26. // Description:
  27. // Constructor
  28. //
  29. // Arguments:
  30. // pwszNameIn -- Class name
  31. // pNamespaceIn -- Namespace
  32. //
  33. // Return Values:
  34. // None.
  35. //
  36. //--
  37. //////////////////////////////////////////////////////////////////////////////
  38. CClusterNode::CClusterNode(
  39. LPCWSTR pwszNameIn,
  40. CWbemServices * pNamespaceIn
  41. )
  42. : CProvBase( pwszNameIn, pNamespaceIn )
  43. {
  44. } //*** CClusterNode::CClusterNode()
  45. //////////////////////////////////////////////////////////////////////////////
  46. //++
  47. //
  48. // static
  49. // CClusterNode::S_CreateThis
  50. //
  51. // Description:
  52. // Create a cluster node object.
  53. //
  54. // Arguments:
  55. // pwszNameIn -- Class name
  56. // pNamespaceIn -- Namespace
  57. // dwEnumTypeIn -- Type id
  58. //
  59. // Return Values:
  60. // Pointer to the CProvBase
  61. //
  62. //--
  63. //////////////////////////////////////////////////////////////////////////////
  64. CProvBase *
  65. CClusterNode::S_CreateThis(
  66. LPCWSTR pwszNameIn,
  67. CWbemServices * pNamespaceIn,
  68. DWORD // dwEnumTypeIn
  69. )
  70. {
  71. return new CClusterNode( pwszNameIn, pNamespaceIn );
  72. } //*** CClusterNode::S_CreateThis()
  73. //////////////////////////////////////////////////////////////////////////////
  74. //++
  75. //
  76. // CClusterNode::RgGetPropMap
  77. //
  78. // Description:
  79. // Retrieve the property mapping table of the cluster node.
  80. //
  81. // Arguments:
  82. // None.
  83. //
  84. // Return Values:
  85. // Reference to the array of property maping table
  86. //
  87. //--
  88. //////////////////////////////////////////////////////////////////////////////
  89. const SPropMapEntryArray *
  90. CClusterNode::RgGetPropMap( void )
  91. {
  92. static SPropMapEntry s_rgpm[] =
  93. {
  94. {
  95. PVD_PROP_NAME,
  96. CLUSREG_NAME_NODE_NAME,
  97. SZ_TYPE,
  98. READONLY
  99. }
  100. };
  101. static SPropMapEntryArray s_pmea(
  102. sizeof( s_rgpm ) / sizeof( SPropMapEntry ),
  103. s_rgpm
  104. );
  105. return & s_pmea;
  106. } //*** CClusterNode::RgGetPropMap()
  107. //////////////////////////////////////////////////////////////////////////////
  108. //++
  109. //
  110. // CClusterNode::EnumInstance
  111. //
  112. // Description:
  113. // enum cluster instance
  114. //
  115. // Arguments:
  116. // lFlagsIn -- WMI flag
  117. // pCtxIn -- WMI context
  118. // pHandlerIn -- WMI sink pointer
  119. //
  120. // Return Values:
  121. // WBEM_S_NO_ERROR
  122. //
  123. //--
  124. //////////////////////////////////////////////////////////////////////////////
  125. SCODE
  126. CClusterNode::EnumInstance(
  127. long lFlagsIn,
  128. IWbemContext * pCtxIn,
  129. IWbemObjectSink * pHandlerIn
  130. )
  131. {
  132. SAFECLUSTER shCluster;
  133. SAFENODE shNode;
  134. LPCWSTR pwszNode;
  135. shCluster = OpenCluster( NULL );
  136. CClusterEnum cluEnum(
  137. shCluster,
  138. CLUSTER_ENUM_NODE );
  139. while ( ( pwszNode = cluEnum.GetNext() ) != NULL )
  140. {
  141. shNode = OpenClusterNode( shCluster, pwszNode );
  142. ClusterToWMI( shNode, pHandlerIn );
  143. } // while: more nodes
  144. return WBEM_S_NO_ERROR;
  145. } //*** CClusterNode::EnumInstance()
  146. //////////////////////////////////////////////////////////////////////////////
  147. //++
  148. //
  149. // CClusterResource::ClusterToWMI
  150. //
  151. // Description:
  152. // Translate a cluster resource objects to WMI object.
  153. //
  154. // Arguments:
  155. // hNodeIn -- Handle to node
  156. // pHandlerIn -- Pointer to WMI sink
  157. //
  158. // Return Values:
  159. // WBEM_S_NO_ERROR
  160. // Win32 error
  161. //
  162. //--
  163. //////////////////////////////////////////////////////////////////////////////
  164. void
  165. CClusterNode::ClusterToWMI(
  166. HNODE hNodeIn,
  167. IWbemObjectSink * pHandlerIn
  168. )
  169. {
  170. static SGetControl s_rgControl[] =
  171. {
  172. { CLUSCTL_NODE_GET_RO_COMMON_PROPERTIES, FALSE },
  173. { CLUSCTL_NODE_GET_COMMON_PROPERTIES, FALSE },
  174. { CLUSCTL_NODE_GET_RO_PRIVATE_PROPERTIES, TRUE },
  175. { CLUSCTL_NODE_GET_PRIVATE_PROPERTIES, TRUE }
  176. };
  177. static DWORD s_cControl = sizeof( s_rgControl ) / sizeof( SGetControl );
  178. CWbemClassObject wco;
  179. CError er;
  180. UINT idx;
  181. m_pClass->SpawnInstance( 0, & wco );
  182. for ( idx = 0 ; idx < s_cControl; idx ++ )
  183. {
  184. CClusPropList pl;
  185. er = pl.ScGetNodeProperties(
  186. hNodeIn,
  187. s_rgControl[ idx ].dwControl,
  188. NULL,
  189. 0
  190. );
  191. CClusterApi::GetObjectProperties(
  192. RgGetPropMap(),
  193. pl,
  194. wco,
  195. s_rgControl[ idx ].fPrivate
  196. );
  197. } // for: each control code
  198. {
  199. DWORD dwState = GetClusterNodeState( hNodeIn );
  200. wco.SetProperty( dwState, PVD_PROP_STATE );
  201. }
  202. //
  203. // flags and characteristics
  204. //
  205. {
  206. DWORD cbReturned;
  207. DWORD dwOut;
  208. er = ClusterNodeControl(
  209. hNodeIn,
  210. NULL,
  211. CLUSCTL_NODE_GET_CHARACTERISTICS,
  212. NULL,
  213. 0,
  214. & dwOut,
  215. sizeof( DWORD ),
  216. & cbReturned
  217. );
  218. wco.SetProperty( dwOut, PVD_PROP_CHARACTERISTIC );
  219. er = ClusterNodeControl(
  220. hNodeIn,
  221. NULL,
  222. CLUSCTL_NODE_GET_FLAGS,
  223. NULL,
  224. 0,
  225. & dwOut,
  226. sizeof( DWORD ),
  227. & cbReturned
  228. );
  229. wco.SetProperty( dwOut, PVD_PROP_FLAGS );
  230. }
  231. pHandlerIn->Indicate( 1, & wco );
  232. return;
  233. } //*** CClusterResource::ClusterToWMI()
  234. //////////////////////////////////////////////////////////////////////////////
  235. //++
  236. //
  237. // CClusterNode::GetObject
  238. //
  239. // Description:
  240. // retrieve cluster node object based given object path
  241. //
  242. // Arguments:
  243. // rObjPathIn -- Object path to cluster object
  244. // lFlagsIn -- WMI flag
  245. // pCtxIn -- WMI context
  246. // pHandlerIn -- WMI sink pointer
  247. //
  248. // Return Values:
  249. // WBEM_S_NO_ERROR
  250. // win32 error
  251. //
  252. //--
  253. //////////////////////////////////////////////////////////////////////////////
  254. SCODE
  255. CClusterNode::GetObject(
  256. CObjPath & rObjPathIn,
  257. long lFlagsIn,
  258. IWbemContext * pCtxIn,
  259. IWbemObjectSink * pHandlerIn
  260. )
  261. {
  262. SAFECLUSTER shCluster;
  263. SAFENODE shNode;
  264. shCluster = OpenCluster( NULL );
  265. shNode = OpenClusterNode(
  266. shCluster,
  267. rObjPathIn.GetStringValueForProperty( PVD_PROP_NAME )
  268. );
  269. ClusterToWMI( shNode, pHandlerIn );
  270. return WBEM_S_NO_ERROR;
  271. } //*** CClusterNode::GetObject()
  272. //////////////////////////////////////////////////////////////////////////////
  273. //++
  274. //
  275. // CClusterNode::ExecuteMethod
  276. // )
  277. //
  278. // Description:
  279. // execute methods defined in the mof for cluster node
  280. //
  281. // Arguments:
  282. // rObjPathIn -- Object path to cluster object
  283. // pwszMethodNameIn -- Name of the method to be invoked
  284. // lFlagIn -- WMI flag
  285. // pParamsIn -- Input parameters for the method
  286. // pHandlerIn -- WMI sink pointer
  287. //
  288. // Return Values:
  289. // WBEM_E_NOT_SUPPORTED
  290. //
  291. //--
  292. //////////////////////////////////////////////////////////////////////////////
  293. SCODE
  294. CClusterNode::ExecuteMethod(
  295. CObjPath & rObjPathIn,
  296. WCHAR * pwszMethodNameIn,
  297. long lFlagIn,
  298. IWbemClassObject * pParamsIn,
  299. IWbemObjectSink * pHandlerIn
  300. )
  301. {
  302. return WBEM_E_NOT_SUPPORTED;
  303. } //*** CClusterNode::ExecuteMethod()
  304. //////////////////////////////////////////////////////////////////////////////
  305. //++
  306. //
  307. // CClusterNode::PutInstance
  308. //
  309. // Description:
  310. // save this instance
  311. //
  312. // Arguments:
  313. // rInstToPutIn -- WMI object to be saved
  314. // lFlagIn -- WMI flag
  315. // pCtxIn -- WMI context
  316. // pHandlerIn -- WMI sink pointer
  317. //
  318. // Return Values:
  319. // WBEM_S_NO_ERROR
  320. //
  321. //--
  322. //////////////////////////////////////////////////////////////////////////////
  323. SCODE
  324. CClusterNode::PutInstance(
  325. CWbemClassObject & rInstToPutIn,
  326. long lFlagIn,
  327. IWbemContext * pCtxIn,
  328. IWbemObjectSink * pHandlerIn
  329. )
  330. {
  331. static SGetSetControl s_rgControl[] =
  332. {
  333. {
  334. CLUSCTL_NODE_GET_COMMON_PROPERTIES,
  335. CLUSCTL_NODE_SET_COMMON_PROPERTIES,
  336. FALSE
  337. },
  338. {
  339. CLUSCTL_NODE_GET_PRIVATE_PROPERTIES,
  340. CLUSCTL_NODE_SET_PRIVATE_PROPERTIES,
  341. TRUE
  342. }
  343. };
  344. static DWORD s_cControl = sizeof( s_rgControl ) / sizeof( SGetSetControl );
  345. _bstr_t bstrName;
  346. SAFECLUSTER shCluster;
  347. SAFENODE shNode;
  348. CError er;
  349. UINT idx;
  350. rInstToPutIn.GetProperty( bstrName, PVD_PROP_NAME );
  351. shCluster = OpenCluster( NULL );
  352. shNode = OpenClusterNode( shCluster, bstrName );
  353. for ( idx = 0 ; idx < s_cControl ; idx ++ )
  354. {
  355. CClusPropList plOld;
  356. CClusPropList plNew;
  357. er = plOld.ScGetNodeProperties(
  358. shNode,
  359. s_rgControl[ idx ].dwGetControl,
  360. NULL,
  361. NULL,
  362. 0
  363. );
  364. CClusterApi::SetObjectProperties(
  365. RgGetPropMap(),
  366. plNew,
  367. plOld,
  368. rInstToPutIn,
  369. s_rgControl[ idx ].fPrivate
  370. );
  371. if ( plNew.Cprops() > 0 )
  372. {
  373. er = ClusterNodeControl(
  374. shNode,
  375. NULL,
  376. s_rgControl[ idx ].dwSetControl,
  377. plNew.PbPropList(),
  378. static_cast< DWORD >( plNew.CbPropList() ),
  379. NULL,
  380. 0,
  381. NULL
  382. );
  383. }
  384. } // for: each control code
  385. return WBEM_S_NO_ERROR;
  386. } //*** CClusterNode::PutInstance()
  387. //////////////////////////////////////////////////////////////////////////////
  388. //++
  389. //
  390. // CClusterNode::DeleteInstance
  391. //
  392. // Description:
  393. // Delete the object specified in rObjPathIn.
  394. //
  395. // Arguments:
  396. // rObjPathIn -- ObjPath for the instance to be deleted
  397. // lFlagIn -- WMI flag
  398. // pCtxIn -- WMI context
  399. // pHandlerIn -- WMI sink pointer
  400. //
  401. // Return Values:
  402. // WBEM_E_NOT_SUPPORTED
  403. //
  404. //--
  405. //////////////////////////////////////////////////////////////////////////////
  406. SCODE
  407. CClusterNode::DeleteInstance(
  408. CObjPath & rObjPathIn,
  409. long lFlagIn,
  410. IWbemContext * pCtxIn,
  411. IWbemObjectSink * pHandlerIn
  412. )
  413. {
  414. return WBEM_E_NOT_SUPPORTED;
  415. } //*** CClusterNode::DeleteInstance()
  416. //****************************************************************************
  417. //
  418. // CClusterNodeNetInterface
  419. //
  420. //****************************************************************************
  421. CClusterNodeNetInterface::CClusterNodeNetInterface(
  422. const WCHAR * pwszNameIn,
  423. CWbemServices * pNamespaceIn,
  424. DWORD dwEnumTypeIn
  425. )
  426. : CClusterObjAssoc( pwszNameIn, pNamespaceIn, dwEnumTypeIn )
  427. {
  428. } //*** ClusterNodeNetInterface::ClusterNodeNetInterface()
  429. //////////////////////////////////////////////////////////////////////////////
  430. //++
  431. //
  432. // static
  433. // ClusterNodeNetInterface::S_CreateThis
  434. //
  435. // Description:
  436. // Create a cluster Node Network Interface object.
  437. //
  438. // Arguments:
  439. // pwszNameIn -- Class name
  440. // pNamespaceIn -- Namespace
  441. // dwEnumTypeIn -- Str type id
  442. //
  443. // Return Values:
  444. // pointer to the CProvBase
  445. //
  446. //--
  447. //////////////////////////////////////////////////////////////////////////////
  448. CProvBase *
  449. CClusterNodeNetInterface::S_CreateThis(
  450. LPCWSTR pwszNameIn,
  451. CWbemServices * pNamespaceIn,
  452. DWORD dwEnumTypeIn
  453. )
  454. {
  455. return new CClusterNodeNetInterface(
  456. pwszNameIn,
  457. pNamespaceIn,
  458. dwEnumTypeIn
  459. );
  460. } //*** ClusterNodeNetInterface::S_CreateThis()
  461. //////////////////////////////////////////////////////////////////////////////
  462. //++
  463. //
  464. // ClusterNodeNetInterface::EnumInstance
  465. //
  466. // Description:
  467. // Enumerate net interfaces for the node.
  468. //
  469. // Arguments:
  470. // lFlagsIn --
  471. // pCtxIn --
  472. // pHandlerIn --
  473. //
  474. // Return Values:
  475. // WBEM_S_NO_ERROR
  476. //
  477. //--
  478. //////////////////////////////////////////////////////////////////////////////
  479. SCODE
  480. CClusterNodeNetInterface::EnumInstance(
  481. long lFlagsIn,
  482. IWbemContext * pCtxIn,
  483. IWbemObjectSink * pHandlerIn
  484. )
  485. {
  486. SAFECLUSTER shCluster;
  487. CError er;
  488. DWORD dwError;
  489. CWbemClassObject wcoGroup;
  490. _bstr_t bstrGroup;
  491. _bstr_t bstrPart;
  492. DWORD cbName = MAX_PATH;
  493. CWstrBuf wsbName;
  494. CComPtr< IEnumWbemClassObject > pEnum;
  495. HRESULT hr = WBEM_S_NO_ERROR;
  496. shCluster = OpenCluster( NULL );
  497. m_wcoGroup.SpawnInstance( 0, & wcoGroup );
  498. //
  499. // network interface objects
  500. //
  501. er = m_pNamespace->CreateInstanceEnum(
  502. _bstr_t( PVD_CLASS_NETWORKINTERFACE ),
  503. 0,
  504. NULL,
  505. & pEnum
  506. );
  507. wsbName.SetSize( cbName );
  508. for( ; ; )
  509. {
  510. CWbemClassObject wcoNetInterface;
  511. DWORD cWco;
  512. hr = pEnum->Next(
  513. 5000,
  514. 1,
  515. & wcoNetInterface,
  516. & cWco
  517. );
  518. if ( hr == WBEM_S_NO_ERROR )
  519. {
  520. SAFENETINTERFACE shNetInterface;
  521. DWORD cbReturn;
  522. CWbemClassObject wco;
  523. wcoNetInterface.GetProperty( bstrPart, PVD_WBEM_PROP_DEVICEID );
  524. shNetInterface = OpenClusterNetInterface( shCluster, bstrPart );
  525. dwError = ClusterNetInterfaceControl(
  526. shNetInterface,
  527. NULL,
  528. CLUSCTL_NETINTERFACE_GET_NODE,
  529. NULL,
  530. 0,
  531. wsbName,
  532. cbName,
  533. & cbReturn
  534. );
  535. if ( dwError == ERROR_MORE_DATA )
  536. {
  537. cbName = cbReturn;
  538. wsbName.SetSize( cbName );
  539. er = ClusterNetInterfaceControl(
  540. shNetInterface,
  541. NULL,
  542. CLUSCTL_NETINTERFACE_GET_NODE,
  543. NULL,
  544. 0,
  545. wsbName,
  546. cbName,
  547. & cbReturn
  548. );
  549. } // if: more data
  550. wcoGroup.SetProperty( wsbName, PVD_PROP_NAME );
  551. wcoGroup.GetProperty( bstrGroup, PVD_WBEM_RELPATH );
  552. wcoNetInterface.GetProperty( bstrPart, PVD_WBEM_RELPATH );
  553. m_pClass->SpawnInstance( 0, & wco );
  554. wco.SetProperty( (LPWSTR) bstrGroup, PVD_PROP_GROUPCOMPONENT );
  555. wco.SetProperty( (LPWSTR ) bstrPart, PVD_PROP_PARTCOMPONENT );
  556. er = pHandlerIn->Indicate( 1, & wco );
  557. } // if: success
  558. else
  559. {
  560. break;
  561. } // else: E_XXX, or S_FALSE
  562. } // forever
  563. if ( FAILED ( hr ) )
  564. {
  565. throw CProvException( hr );
  566. }
  567. return WBEM_S_NO_ERROR;
  568. } //*** ClusterNodeNetInterface::EnumInstance()