Source code of Windows XP (NT5)
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.

1024 lines
29 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1999-2000 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // ClusterResource.cpp
  7. //
  8. // Description:
  9. // Implementation of CClusterResource class
  10. //
  11. // Author:
  12. // Henry Wang (HenryWa) 24-AUG-1999
  13. //
  14. //////////////////////////////////////////////////////////////////////////////
  15. #include "Pch.h"
  16. #include "ClusterResource.h"
  17. #include "ClusterResource.tmh"
  18. #include <vector>
  19. //****************************************************************************
  20. //
  21. // CClusterResource
  22. //
  23. //****************************************************************************
  24. //////////////////////////////////////////////////////////////////////////////
  25. //++
  26. //
  27. // CClusterResource::CClusterResource(
  28. // LPCWSTR pwszNameIn,
  29. // CWbemServices * pNamespaceIn
  30. // )
  31. //
  32. // Description:
  33. // Constructor.
  34. //
  35. // Arguments:
  36. // pwszNameIn -- Class name
  37. // pNamespaceIn -- Namespace
  38. //
  39. // Return Values:
  40. // None.
  41. //
  42. //--
  43. //////////////////////////////////////////////////////////////////////////////
  44. CClusterResource::CClusterResource(
  45. LPCWSTR pwszNameIn,
  46. CWbemServices * pNamespaceIn
  47. )
  48. : CProvBase( pwszNameIn, pNamespaceIn )
  49. {
  50. } //*** CClusterResource::CClusterResource()
  51. //////////////////////////////////////////////////////////////////////////////
  52. //++
  53. //
  54. // static
  55. // CProvBase *
  56. // CClusterResource::S_CreateThis(
  57. // LPCWSTR pwszNameIn,
  58. // CWbemServices * pNamespaceIn,
  59. // DWORD dwEnumTypeIn
  60. // )
  61. //
  62. // Description:
  63. // Create a resource object
  64. //
  65. // Arguments:
  66. // pwszNameIn -- Class name
  67. // pNamespaceIn -- Namespace
  68. // dwEnumTypeIn -- Type id
  69. //
  70. // Return Values:
  71. // pointer to the CProvBase
  72. //
  73. //--
  74. //////////////////////////////////////////////////////////////////////////////
  75. CProvBase *
  76. CClusterResource::S_CreateThis(
  77. LPCWSTR pwszNameIn,
  78. CWbemServices * pNamespaceIn,
  79. DWORD // dwEnumTypeIn
  80. )
  81. {
  82. return new CClusterResource( pwszNameIn, pNamespaceIn );
  83. } //*** CClusterResource::S_CreateThis()
  84. //////////////////////////////////////////////////////////////////////////////
  85. //++
  86. //
  87. // SCODE
  88. // CClusterResource::EnumInstance(
  89. // long lFlagsIn,
  90. // IWbemContext * pCtxIn,
  91. // IWbemObjectSink * pHandlerIn
  92. // )
  93. //
  94. // Description:
  95. // Enumerate cluster resource instances.
  96. //
  97. // Arguments:
  98. // lFlagsIn -- WMI flag
  99. // pCtxIn -- WMI context
  100. // pHandlerIn -- WMI sink pointer
  101. //
  102. // Return Values:
  103. // WBEM_S_NO_ERROR
  104. //
  105. //--
  106. //////////////////////////////////////////////////////////////////////////////
  107. SCODE
  108. CClusterResource::EnumInstance(
  109. long lFlagsIn,
  110. IWbemContext * pCtxIn,
  111. IWbemObjectSink * pHandlerIn
  112. )
  113. {
  114. SAFECLUSTER shCluster;
  115. SAFERESOURCE shResource;
  116. LPCWSTR pwszResName = NULL;
  117. shCluster = OpenCluster( NULL );
  118. CClusterEnum cluEnum( shCluster, CLUSTER_ENUM_RESOURCE );
  119. while ( ( pwszResName = cluEnum.GetNext() ) != NULL )
  120. {
  121. shResource = OpenClusterResource( shCluster, pwszResName );
  122. ClusterToWMI( shResource, pHandlerIn );
  123. } // while: more resources
  124. return WBEM_S_NO_ERROR;
  125. } //*** CClusterResource::EnumInstance()
  126. // smart_bstr class to make LoadRegistryCheckpoints func exception safe
  127. struct smart_bstr {
  128. BSTR data;
  129. smart_bstr():data(0){}
  130. ~smart_bstr() { SysFreeString(data); }
  131. };
  132. //////////////////////////////////////////////////////////////////////////////
  133. //++
  134. //
  135. // void
  136. // LoadRegistryCheckpoints(
  137. // IN HRESOURCE hResourceIn,
  138. // IN DWORD dwControlCode,
  139. // IN const WCHAR* propName,
  140. // IN OUT CWbemClassObject wco,
  141. // )
  142. //
  143. // Description:
  144. // Translate a cluster resource objects to WMI object.
  145. //
  146. // Arguments:
  147. // hResourceIn -- Handle to resource
  148. // dwControlCode -- show be one of the following
  149. // CLUSCTL_RESOURCE_GET_REGISTRY_CHECKPOINTS
  150. // CLUSCTL_RESOURCE_GET_CRYPTO_CHECKPOINTS
  151. // propName -- property name to load checkpoints to
  152. // wco -- property container
  153. //
  154. // Return Values:
  155. // none
  156. //--
  157. //////////////////////////////////////////////////////////////////////////////
  158. void
  159. LoadRegistryCheckpoints(
  160. IN HRESOURCE hResourceIn,
  161. IN DWORD dwControlCode,
  162. IN const WCHAR* propName,
  163. IN OUT CWbemClassObject &wco
  164. )
  165. {
  166. DWORD cbReturned = 0;
  167. DWORD dwStatus;
  168. CError er;
  169. dwStatus = ClusterResourceControl(
  170. hResourceIn,
  171. NULL,
  172. dwControlCode,
  173. NULL,
  174. 0,
  175. NULL,
  176. 0,
  177. &cbReturned
  178. );
  179. if (dwStatus != ERROR_MORE_DATA) {
  180. er = dwStatus;
  181. }
  182. if (cbReturned == 0) {
  183. return; // no checkpoints
  184. }
  185. std::vector<WCHAR> checkpoints(cbReturned/sizeof(WCHAR));
  186. er = ClusterResourceControl(
  187. hResourceIn,
  188. NULL,
  189. dwControlCode,
  190. NULL,
  191. 0,
  192. &checkpoints[0],
  193. checkpoints.size() * sizeof(WCHAR),
  194. &cbReturned
  195. );
  196. int nKeys = 0; // count how many keys are in the string
  197. for(int i = 0; i < checkpoints.size(); ++i) {
  198. if (checkpoints[i] == 0) {
  199. ++nKeys;
  200. if (i > 0 && checkpoints[i-1] == 0) {
  201. break; // double null
  202. }
  203. }
  204. }
  205. std::vector<smart_bstr> bstrs(nKeys);
  206. WCHAR* p = &checkpoints[0];
  207. for(int i = 0; i < nKeys; ++i) {
  208. bstrs[i].data = SysAllocString( p );
  209. p += wcslen(p) + 1;
  210. }
  211. wco.SetProperty(nKeys, &bstrs[0].data, propName);
  212. }
  213. //////////////////////////////////////////////////////////////////////////////
  214. //++
  215. //
  216. // void
  217. // CClusterResource::ClusterToWMI(
  218. // HRESOURCE hResourceIn,
  219. // IWbemObjectSink * pHandlerIn
  220. // )
  221. //
  222. // Description:
  223. // Translate a cluster resource objects to WMI object.
  224. //
  225. // Arguments:
  226. // hResourceIn -- Handle to resource
  227. // pHandlerIn -- Pointer to WMI sink
  228. //
  229. // Return Values:
  230. // WBEM_S_NO_ERROR
  231. // Win32 error
  232. //
  233. //--
  234. //////////////////////////////////////////////////////////////////////////////
  235. void
  236. CClusterResource::ClusterToWMI(
  237. HRESOURCE hResourceIn,
  238. IWbemObjectSink * pHandlerIn
  239. )
  240. {
  241. static SGetControl s_rgControl[] =
  242. {
  243. { CLUSCTL_RESOURCE_GET_RO_COMMON_PROPERTIES, FALSE },
  244. { CLUSCTL_RESOURCE_GET_COMMON_PROPERTIES, FALSE },
  245. { CLUSCTL_RESOURCE_GET_RO_PRIVATE_PROPERTIES, TRUE },
  246. { CLUSCTL_RESOURCE_GET_PRIVATE_PROPERTIES, TRUE }
  247. };
  248. static DWORD s_cControl = sizeof( s_rgControl ) / sizeof( SGetControl );
  249. CWbemClassObject wco;
  250. CWbemClassObject wcoPrivate;
  251. CWbemClassObject wcoClass;
  252. CError er;
  253. DWORD dwStatus;
  254. UINT idx;
  255. CWstrBuf wsbTypeName ;
  256. DWORD cbTypeName = MAX_PATH;
  257. DWORD cbTypeNameReturned = 0;
  258. //
  259. // get type name and corresponding property class
  260. //
  261. wsbTypeName.SetSize( cbTypeName );
  262. dwStatus = ClusterResourceControl(
  263. hResourceIn,
  264. NULL,
  265. CLUSCTL_RESOURCE_GET_RESOURCE_TYPE,
  266. NULL,
  267. 0,
  268. wsbTypeName,
  269. cbTypeName,
  270. &cbTypeNameReturned
  271. );
  272. if ( dwStatus == ERROR_MORE_DATA )
  273. {
  274. cbTypeName = cbTypeNameReturned;
  275. wsbTypeName.SetSize( cbTypeName );
  276. er = ClusterResourceControl(
  277. hResourceIn,
  278. NULL,
  279. CLUSCTL_RESOURCE_GET_RESOURCE_TYPE,
  280. NULL,
  281. 0,
  282. wsbTypeName,
  283. cbTypeName,
  284. &cbTypeNameReturned
  285. );
  286. }
  287. er = dwStatus;
  288. er = m_pNamespace->GetObject(
  289. g_TypeNameToClass[ static_cast<LPWSTR> ( wsbTypeName ) ],
  290. 0,
  291. 0,
  292. &wcoClass,
  293. NULL
  294. );
  295. er = wcoClass.data()->SpawnInstance( 0, & wcoPrivate );
  296. m_pClass->SpawnInstance( 0, & wco );
  297. //
  298. // get properties from property list
  299. //
  300. for ( idx = 0 ; idx < s_cControl ; idx ++ )
  301. {
  302. CClusPropList pl;
  303. CWbemClassObject wcoTemp;
  304. er = pl.ScGetResourceProperties(
  305. hResourceIn,
  306. s_rgControl[ idx ].dwControl,
  307. NULL,
  308. 0
  309. );
  310. if ( s_rgControl[ idx ].fPrivate )
  311. {
  312. wcoTemp = wcoPrivate;
  313. }
  314. else
  315. {
  316. wcoTemp = wco;
  317. }
  318. CClusterApi::GetObjectProperties(
  319. NULL,
  320. pl,
  321. wcoTemp,
  322. s_rgControl[ idx ].fPrivate
  323. );
  324. } // for: each control code
  325. wco.SetProperty(
  326. wcoPrivate.data(),
  327. PVD_PROP_RES_PRIVATE );
  328. {
  329. DWORD dwState = GetClusterResourceState(
  330. hResourceIn,
  331. NULL,
  332. NULL,
  333. NULL,
  334. NULL
  335. );
  336. wco.SetProperty( dwState, PVD_PROP_RES_STATE );
  337. }
  338. LoadRegistryCheckpoints(hResourceIn,
  339. CLUSCTL_RESOURCE_GET_REGISTRY_CHECKPOINTS, PVD_PROP_RES_CHECKPOINTS, wco);
  340. LoadRegistryCheckpoints(hResourceIn,
  341. CLUSCTL_RESOURCE_GET_CRYPTO_CHECKPOINTS, PVD_PROP_RES_CRYPTO_CHECKPOINTS, wco);
  342. //
  343. // flags and characteristics
  344. //
  345. {
  346. DWORD cbReturned;
  347. DWORD dwOut;
  348. er = ClusterResourceControl(
  349. hResourceIn,
  350. NULL,
  351. CLUSCTL_RESOURCE_GET_CHARACTERISTICS,
  352. NULL,
  353. 0,
  354. &dwOut,
  355. sizeof( DWORD ),
  356. &cbReturned
  357. );
  358. wco.SetProperty( dwOut, PVD_PROP_CHARACTERISTIC );
  359. wco.SetProperty( dwOut & CLUS_CHAR_QUORUM, PVD_PROP_RESTYPE_QUORUM_CAPABLE );
  360. wco.SetProperty( dwOut & CLUS_CHAR_DELETE_REQUIRES_ALL_NODES, PVD_PROP_RESTYPE_DELETE_REQUIRES_ALL_NODES );
  361. wco.SetProperty( dwOut & CLUS_CHAR_LOCAL_QUORUM, PVD_PROP_RESTYPE_LOCALQUORUM_CAPABLE );
  362. er = ClusterResourceControl(
  363. hResourceIn,
  364. NULL,
  365. CLUSCTL_RESOURCE_GET_FLAGS,
  366. NULL,
  367. 0,
  368. &dwOut,
  369. sizeof( DWORD ),
  370. &cbReturned
  371. );
  372. wco.SetProperty( dwOut, PVD_PROP_FLAGS );
  373. wco.SetProperty( dwOut & CLUS_FLAG_CORE, PVD_PROP_RES_CORE_RESOURCE );
  374. }
  375. pHandlerIn->Indicate( 1, & wco );
  376. return;
  377. } //*** CClusterResource::ClusterToWMI()
  378. //////////////////////////////////////////////////////////////////////////////
  379. //++
  380. //
  381. // SCODE
  382. // CClusterResource::GetObject(
  383. // CObjPath & rObjPathIn,
  384. // long lFlagsIn,
  385. // IWbemContext * pCtxIn,
  386. // IWbemObjectSink * pHandlerIn
  387. // )
  388. //
  389. // Description:
  390. // Retrieve cluster resourcee object based on given object path.
  391. //
  392. // Arguments:
  393. // rObjPathIn -- Object path to cluster object
  394. // lFlagsIn -- WMI flag
  395. // pCtxIn -- WMI context
  396. // pHandlerIn -- WMI sink pointer
  397. //
  398. // Return Values:
  399. // WBEM_S_NO_ERROR
  400. // Win32 error
  401. //
  402. //--
  403. //////////////////////////////////////////////////////////////////////////////
  404. SCODE
  405. CClusterResource::GetObject(
  406. CObjPath & rObjPathIn,
  407. long lFlagsIn,
  408. IWbemContext * pCtxIn,
  409. IWbemObjectSink * pHandlerIn
  410. )
  411. {
  412. SAFECLUSTER shCluster;
  413. SAFERESOURCE shRes;
  414. shCluster = OpenCluster( NULL );
  415. shRes = OpenClusterResource(
  416. shCluster,
  417. rObjPathIn.GetStringValueForProperty( CLUSREG_NAME_RES_NAME )
  418. );
  419. ClusterToWMI( shRes, pHandlerIn );
  420. return WBEM_S_NO_ERROR;
  421. } //*** CClusterResource::GetObject()
  422. //////////////////////////////////////////////////////////////////////////////
  423. //++
  424. //
  425. // void
  426. // AddRemoveCheckpoint(
  427. // IN HRESOURCE hResourceIn,
  428. // IN DWORD dwControlCode,
  429. // IN CWbemClassObject wcoInputParam,
  430. // )
  431. //
  432. // Description:
  433. // Adds/Removes regular/crypto checkpoint.
  434. //
  435. // Arguments:
  436. // hResourceIn -- Handle to resource
  437. // dwControlCode -- clusapi control code
  438. // wcoInputParam -- property container
  439. //
  440. // Return Values:
  441. // none
  442. //--
  443. //////////////////////////////////////////////////////////////////////////////
  444. void AddRemoveCheckpoint(
  445. IN HRESOURCE hResourceIn,
  446. IN CWbemClassObject& wcoInputParam,
  447. IN DWORD dwControlCode
  448. )
  449. {
  450. CError er;
  451. _bstr_t keyName;
  452. wcoInputParam.GetProperty( keyName, PVD_MTH_PARM_RES_CHECKPOINT_NAME );
  453. er = ClusterResourceControl(
  454. hResourceIn,
  455. NULL,
  456. dwControlCode,
  457. (wchar_t*)keyName,
  458. SysStringByteLen(keyName) + sizeof(WCHAR),
  459. NULL,
  460. 0,
  461. NULL
  462. );
  463. }
  464. //////////////////////////////////////////////////////////////////////////////
  465. //++
  466. //
  467. // SCODE
  468. // CClusterResource::ExecuteMethod(
  469. // CObjPath & rObjPathIn,
  470. // WCHAR * pwszMethodNameIn,
  471. // long lFlagIn,
  472. // IWbemClassObject * pParamsIn,
  473. // IWbemObjectSink * pHandlerIn
  474. // )
  475. //
  476. // Description:
  477. // Execute methods defined in the mof for cluster resource.
  478. //
  479. // Arguments:
  480. // rObjPathIn -- Object path to cluster object
  481. // pwszMethodNameIn -- Name of the method to be invoked
  482. // lFlagIn -- WMI flag
  483. // pParamsIn -- Input parameters for the method
  484. // pHandlerIn -- WMI sink pointer
  485. //
  486. // Return Values:
  487. // WBEM_S_NO_ERROR
  488. // WBEM_E_INVALID_PARAMETER
  489. //
  490. //--
  491. //////////////////////////////////////////////////////////////////////////////
  492. SCODE
  493. CClusterResource::ExecuteMethod(
  494. CObjPath & rObjPathIn,
  495. WCHAR * pwszMethodNameIn,
  496. long lFlagIn,
  497. IWbemClassObject * pParamsIn,
  498. IWbemObjectSink * pHandlerIn
  499. )
  500. {
  501. SAFECLUSTER shCluster;
  502. SAFERESOURCE shRes;
  503. CWbemClassObject wcoInputParm( pParamsIn );
  504. shCluster = OpenCluster( NULL );
  505. //
  506. // static method
  507. //
  508. if ( _wcsicmp( pwszMethodNameIn, PVD_MTH_RES_CREATE_RESOURCE ) == 0 )
  509. {
  510. _bstr_t bstrTargetGroup;
  511. _bstr_t bstrResource;
  512. BOOL bSeperateMonitor;
  513. _bstr_t bstrResourceType;
  514. SAFERESOURCE shNewResource;
  515. SAFEGROUP shGroup;
  516. CObjPath opGroup;
  517. wcoInputParm.GetProperty( bstrTargetGroup, PVD_MTH_PARM_GROUP );
  518. opGroup.Init( bstrTargetGroup );
  519. bstrTargetGroup = opGroup.GetStringValueForProperty( PVD_PROP_GROUP_NAME );
  520. wcoInputParm.GetProperty( bstrResource, PVD_MTH_PARM_RES_NAME );
  521. wcoInputParm.GetProperty( bstrResourceType, PVD_MTH_PARM_RES_TYPE );
  522. wcoInputParm.GetProperty( &bSeperateMonitor, PVD_MTH_PARM_SEP_MONITOR );
  523. shGroup = OpenClusterGroup( shCluster, bstrTargetGroup );
  524. shNewResource = CreateClusterResource(
  525. shGroup,
  526. bstrResource,
  527. bstrResourceType,
  528. bSeperateMonitor
  529. );
  530. } // if: CREATE_RESOURCE
  531. else
  532. {
  533. shRes = OpenClusterResource(
  534. shCluster,
  535. rObjPathIn.GetStringValueForProperty( PVD_PROP_NAME )
  536. );
  537. if( _wcsicmp( pwszMethodNameIn, PVD_MTH_RES_OFFLINE ) == 0 )
  538. {
  539. return OfflineClusterResource( shRes );
  540. } // if: OFFLINE
  541. else if( _wcsicmp( pwszMethodNameIn, PVD_MTH_RES_ONLINE ) == 0 )
  542. {
  543. return OnlineClusterResource( shRes );
  544. } // else if: ONLINE
  545. else if ( _wcsicmp( pwszMethodNameIn, PVD_MTH_RES_CHANGE_GROUP ) == 0 )
  546. {
  547. _bstr_t bstrGroupObjpath;
  548. SAFEGROUP shGroup;
  549. CObjPath opGroup;
  550. CError er;
  551. wcoInputParm.GetProperty( bstrGroupObjpath, PVD_MTH_PARM_GROUP );
  552. opGroup.Init( bstrGroupObjpath );
  553. bstrGroupObjpath = opGroup.GetStringValueForProperty(PVD_PROP_GROUP_NAME);
  554. shGroup = OpenClusterGroup( shCluster, bstrGroupObjpath );
  555. er = ChangeClusterResourceGroup( shRes, shGroup );
  556. } // else if: CHANGE_GROUP
  557. else if ( _wcsicmp( pwszMethodNameIn, PVD_MTH_RES_ADD_DEPENDENCY ) == 0 )
  558. {
  559. _bstr_t bstrDepResource;
  560. SAFERESOURCE shDepResource;
  561. CError er;
  562. CObjPath opResource;
  563. wcoInputParm.GetProperty( bstrDepResource, PVD_MTH_PARM_RESOURCE );
  564. opResource.Init( bstrDepResource );
  565. bstrDepResource = opResource.GetStringValueForProperty(PVD_PROP_RES_NAME);
  566. shDepResource = OpenClusterResource( shCluster, bstrDepResource );
  567. er = AddClusterResourceDependency( shRes, shDepResource );
  568. } // else if: ADD_DEPENDENCY
  569. else if ( _wcsicmp( pwszMethodNameIn, PVD_MTH_RES_REMOVE_DEPENDENCY ) == 0 )
  570. {
  571. _bstr_t bstrDepResource;
  572. SAFERESOURCE shDepResource;
  573. CError er;
  574. CObjPath opResource;
  575. wcoInputParm.GetProperty( bstrDepResource, PVD_MTH_PARM_RESOURCE );
  576. opResource.Init( bstrDepResource );
  577. bstrDepResource = opResource.GetStringValueForProperty( PVD_PROP_RES_NAME );
  578. shDepResource = OpenClusterResource( shCluster, bstrDepResource );
  579. er = RemoveClusterResourceDependency( shRes, shDepResource );
  580. } // else if: REMOVE_DEPENDENCY
  581. else if ( _wcsicmp( pwszMethodNameIn, PVD_MTH_RES_ADD_REG_CHECKPOINT ) == 0 )
  582. {
  583. AddRemoveCheckpoint(shRes, wcoInputParm, CLUSCTL_RESOURCE_ADD_REGISTRY_CHECKPOINT);
  584. }
  585. else if ( _wcsicmp( pwszMethodNameIn, PVD_MTH_RES_DEL_REG_CHECKPOINT ) == 0 )
  586. {
  587. AddRemoveCheckpoint(shRes, wcoInputParm, CLUSCTL_RESOURCE_DELETE_REGISTRY_CHECKPOINT);
  588. }
  589. else if ( _wcsicmp( pwszMethodNameIn, PVD_MTH_RES_ADD_CRYPTO_CHECKPOINT ) == 0 )
  590. {
  591. AddRemoveCheckpoint(shRes, wcoInputParm, CLUSCTL_RESOURCE_ADD_CRYPTO_CHECKPOINT);
  592. }
  593. else if ( _wcsicmp( pwszMethodNameIn, PVD_MTH_RES_DEL_CRYPTO_CHECKPOINT ) == 0 )
  594. {
  595. AddRemoveCheckpoint(shRes, wcoInputParm, CLUSCTL_RESOURCE_DELETE_CRYPTO_CHECKPOINT);
  596. }
  597. else if ( _wcsicmp( pwszMethodNameIn, PVD_MTH_RES_FAIL_RESOURCE ) == 0 )
  598. {
  599. CError er;
  600. er = FailClusterResource( shRes );
  601. } // if: FAIL_RESOURCE
  602. else if ( _wcsicmp( pwszMethodNameIn, PVD_MTH_RES_RENAME ) == 0 )
  603. {
  604. _bstr_t bstrName;
  605. CError er;
  606. CObjPath opResource;
  607. wcoInputParm.GetProperty( bstrName, PVD_MTH_PARM_NEWNAME );
  608. er = SetClusterResourceName( shRes, bstrName );
  609. } // if: RENAME
  610. else
  611. {
  612. return WBEM_E_INVALID_PARAMETER;
  613. }
  614. } // else: not CREATE_RESOURCE
  615. return WBEM_S_NO_ERROR;
  616. } //*** CClusterResource::ExecuteMethod()
  617. //////////////////////////////////////////////////////////////////////////////
  618. //++
  619. //
  620. // SCODE
  621. // CClusterResource::PutInstance(
  622. // CWbemClassObject & rInstToPutIn,
  623. // long lFlagIn,
  624. // IWbemContext * pCtxIn,
  625. // IWbemObjectSink * pHandlerIn
  626. // )
  627. //
  628. // Description:
  629. // Save this instance.
  630. //
  631. // Arguments:
  632. // rInstToPutIn -- WMI object to be saved
  633. // lFlagIn -- WMI flag
  634. // pCtxIn -- WMI context
  635. // pHandlerIn -- WMI sink pointer
  636. //
  637. // Return Values:
  638. // WBEM_S_NO_ERROR
  639. //
  640. //--
  641. //////////////////////////////////////////////////////////////////////////////
  642. SCODE
  643. CClusterResource::PutInstance(
  644. CWbemClassObject & rInstToPutIn,
  645. long lFlagIn,
  646. IWbemContext * pCtxIn,
  647. IWbemObjectSink * pHandlerIn
  648. )
  649. {
  650. static SGetSetControl s_rgControl[] =
  651. {
  652. {
  653. CLUSCTL_RESOURCE_GET_COMMON_PROPERTIES,
  654. CLUSCTL_RESOURCE_SET_COMMON_PROPERTIES,
  655. FALSE
  656. },
  657. {
  658. CLUSCTL_RESOURCE_GET_PRIVATE_PROPERTIES,
  659. CLUSCTL_RESOURCE_SET_PRIVATE_PROPERTIES,
  660. TRUE
  661. }
  662. };
  663. static DWORD s_cControl = sizeof( s_rgControl ) / sizeof( SGetSetControl );
  664. _bstr_t bstrName;
  665. SAFECLUSTER shCluster;
  666. SAFERESOURCE shResource;
  667. CError er;
  668. UINT idx;
  669. TracePrint(( "CClusterResource::PutInstance entry\n" ));
  670. rInstToPutIn.GetProperty( bstrName, PVD_PROP_NAME );
  671. shCluster = OpenCluster( NULL );
  672. shResource = OpenClusterResource( shCluster, bstrName );
  673. for ( idx = 0 ; idx < s_cControl ; idx ++ )
  674. {
  675. CClusPropList plOld;
  676. CClusPropList plNew;
  677. CWbemClassObject wco;
  678. if ( s_rgControl[ idx ].fPrivate )
  679. {
  680. rInstToPutIn.GetProperty( wco, PVD_PROP_RES_PRIVATE );
  681. }
  682. else
  683. {
  684. wco = rInstToPutIn;
  685. }
  686. er = plOld.ScGetResourceProperties(
  687. shResource,
  688. s_rgControl[ idx ].dwGetControl,
  689. NULL,
  690. NULL,
  691. 0
  692. );
  693. CClusterApi::SetObjectProperties(
  694. NULL,
  695. plNew,
  696. plOld,
  697. wco,
  698. s_rgControl[ idx ].fPrivate
  699. );
  700. if ( plNew.Cprops() > 0 )
  701. {
  702. er = ClusterResourceControl(
  703. shResource,
  704. NULL,
  705. s_rgControl[ idx ].dwSetControl,
  706. plNew.PbPropList(),
  707. plNew.CbPropList(),
  708. NULL,
  709. 0,
  710. NULL
  711. );
  712. }
  713. } // for: each control code
  714. return WBEM_S_NO_ERROR;
  715. } //*** CClusterResource::PutInstance()
  716. //////////////////////////////////////////////////////////////////////////////
  717. //++
  718. //
  719. // SCODE
  720. // CClusterResource::DeleteInstance(
  721. // CObjPath & rObjPathIn,
  722. // long lFlagIn,
  723. // IWbemContext * pCtxIn,
  724. // IWbemObjectSink * pHandlerIn
  725. // )
  726. //
  727. // Description:
  728. // Delete the object specified in rObjPathIn
  729. //
  730. // Arguments:
  731. // rObjPathIn -- ObjPath for the instance to be deleted
  732. // lFlagIn -- WMI flag
  733. // pCtxIn -- WMI context
  734. // pHandlerIn -- WMI sink pointer
  735. //
  736. // Return Values:
  737. // WBEM_S_NO_ERROR
  738. //
  739. //--
  740. //////////////////////////////////////////////////////////////////////////////
  741. SCODE
  742. CClusterResource::DeleteInstance(
  743. CObjPath & rObjPathIn,
  744. long lFlagIn,
  745. IWbemContext * pCtxIn,
  746. IWbemObjectSink * pHandlerIn
  747. )
  748. {
  749. SAFECLUSTER shCluster;
  750. SAFERESOURCE shRes;
  751. CError er;
  752. shCluster = OpenCluster( NULL );
  753. shRes = OpenClusterResource(
  754. shCluster,
  755. rObjPathIn.GetStringValueForProperty( CLUSREG_NAME_RES_NAME )
  756. );
  757. er = OfflineClusterResource( shRes );
  758. er = DeleteClusterResource( shRes );
  759. return WBEM_S_NO_ERROR;
  760. } //*** CClusterResource::DeleteInstance()
  761. //****************************************************************************
  762. //
  763. // CClusterClusterQuorum
  764. //
  765. //****************************************************************************
  766. //////////////////////////////////////////////////////////////////////////////
  767. //++
  768. //
  769. // CClusterClusterQuorum::CClusterClusterQuorum(
  770. // LPCWSTR pwszNameIn,
  771. // CWbemServices * pNamespaceIn,
  772. // DWORD dwEnumType
  773. // )
  774. //
  775. // Description:
  776. // Constructor.
  777. //
  778. // Arguments:
  779. // pwszNameIn -- Class name
  780. // pNamespaceIn -- Namespace
  781. // dwEnumTypeIn -- Type id
  782. //
  783. // Return Values:
  784. // None.
  785. //
  786. //--
  787. //////////////////////////////////////////////////////////////////////////////
  788. CClusterClusterQuorum::CClusterClusterQuorum(
  789. LPCWSTR pwszNameIn,
  790. CWbemServices * pNamespaceIn,
  791. DWORD dwEnumTypeIn
  792. )
  793. : CClusterObjAssoc( pwszNameIn, pNamespaceIn, dwEnumTypeIn )
  794. {
  795. } //*** CClusterClusterQuorum::CClusterClusterQuorum()
  796. //////////////////////////////////////////////////////////////////////////////
  797. //++
  798. //
  799. // static
  800. // CProvBase *
  801. // CClusterClusterQuorum::S_CreateThis(
  802. // LPCWSTR pwszNameIn,
  803. // CWbemServices * pNamespaceIn,
  804. // DWORD dwEnumTypeIn
  805. // )
  806. //
  807. // Description:
  808. // Create a cluster node object
  809. //
  810. // Arguments:
  811. // pwszNameIn -- Class name
  812. // pNamespaceIn -- Namespace
  813. // dwEnumTypeIn -- Type id
  814. //
  815. // Return Values:
  816. // pointer to the CProvBase
  817. //
  818. //--
  819. //////////////////////////////////////////////////////////////////////////////
  820. CProvBase *
  821. CClusterClusterQuorum::S_CreateThis(
  822. LPCWSTR pwszNameIn,
  823. CWbemServices * pNamespaceIn,
  824. DWORD dwEnumTypeIn
  825. )
  826. {
  827. return new CClusterClusterQuorum(
  828. pwszNameIn,
  829. pNamespaceIn,
  830. dwEnumTypeIn
  831. );
  832. } //*** CClusterClusterQuorum::S_CreateThis()
  833. //////////////////////////////////////////////////////////////////////////////
  834. //++
  835. //
  836. // SCODE
  837. // CClusterClusterQuorum::EnumInstance(
  838. // long lFlagsIn,
  839. // IWbemContext * pCtxIn,
  840. // IWbemObjectSink * pHandlerIn
  841. // )
  842. //
  843. // Description:
  844. // Enumerate instances of cluster quorum
  845. //
  846. // Arguments:
  847. // lFlagsIn -- WMI flag
  848. // pCtxIn -- WMI context
  849. // pHandlerIn -- WMI sink pointer
  850. //
  851. // Return Values:
  852. // WBEM_S_NO_ERROR
  853. //
  854. //--
  855. //////////////////////////////////////////////////////////////////////////////
  856. SCODE
  857. CClusterClusterQuorum::EnumInstance(
  858. long lFlagsIn,
  859. IWbemContext * pCtxIn,
  860. IWbemObjectSink * pHandlerIn
  861. )
  862. {
  863. SAFECLUSTER shCluster;
  864. SAFERESOURCE shResource;
  865. DWORD cchResName = MAX_PATH;
  866. CWstrBuf wsbResName;
  867. DWORD cchDeviceName = MAX_PATH;
  868. CWstrBuf wsbDeviceName;
  869. DWORD cchClusterName = MAX_PATH;
  870. CWstrBuf wsbClusterName;
  871. DWORD dwLogsize;
  872. CError er;
  873. DWORD dwError;
  874. CWbemClassObject wco;
  875. CWbemClassObject wcoGroup;
  876. CWbemClassObject wcoPart;
  877. _bstr_t bstrGroup;
  878. _bstr_t bstrPart;
  879. wsbResName.SetSize( cchResName );
  880. wsbDeviceName.SetSize( cchDeviceName );
  881. wsbClusterName.SetSize( cchClusterName );
  882. shCluster = OpenCluster( NULL );
  883. m_wcoGroup.SpawnInstance( 0, & wcoGroup );
  884. m_wcoPart.SpawnInstance( 0, & wcoPart );
  885. dwError = GetClusterQuorumResource(
  886. shCluster,
  887. wsbResName,
  888. &cchResName,
  889. wsbDeviceName,
  890. &cchDeviceName,
  891. &dwLogsize
  892. );
  893. if ( dwError == ERROR_MORE_DATA )
  894. {
  895. wsbResName.SetSize( ++cchResName );
  896. wsbDeviceName.SetSize( ++cchDeviceName );
  897. er = GetClusterQuorumResource(
  898. shCluster,
  899. wsbResName,
  900. &cchResName,
  901. wsbDeviceName,
  902. &cchDeviceName,
  903. &dwLogsize
  904. );
  905. } // if: buffer was too small
  906. dwError = GetClusterInformation(
  907. shCluster,
  908. wsbClusterName,
  909. &cchClusterName,
  910. NULL
  911. );
  912. if ( dwError == ERROR_MORE_DATA )
  913. {
  914. wsbClusterName.SetSize( ++cchClusterName );
  915. er = GetClusterInformation(
  916. shCluster,
  917. wsbClusterName,
  918. &cchClusterName,
  919. NULL
  920. );
  921. } // if: buffer was too small
  922. wcoPart.SetProperty( wsbResName, PVD_PROP_NAME );
  923. wcoPart.GetProperty( bstrPart, PVD_WBEM_RELPATH );
  924. wcoGroup.SetProperty( wsbClusterName, PVD_PROP_NAME );
  925. wcoGroup.GetProperty( bstrGroup, PVD_WBEM_RELPATH );
  926. m_pClass->SpawnInstance( 0, &wco );
  927. wco.SetProperty( (LPWSTR) bstrGroup, PVD_PROP_GROUPCOMPONENT );
  928. wco.SetProperty( (LPWSTR) bstrPart, PVD_PROP_PARTCOMPONENT );
  929. pHandlerIn->Indicate( 1, &wco );
  930. return WBEM_S_NO_ERROR;
  931. } //*** ClusterClusterQuorum::EnumInstance()