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.

1555 lines
45 KiB

  1. // Copyright (c) Microsoft. All rights reserved.
  2. //
  3. // This is unpublished source code of Microsoft.
  4. // The copyright notice above does not evidence any
  5. // actual or intended publication of such source code.
  6. // OneLiner : Implementation of MNLBMachine
  7. // DevUnit : wlbstest
  8. // Author : Murtaza Hakim
  9. // History:
  10. // --------
  11. //
  12. // Revised by : mhakim
  13. // Date : 02-09-01
  14. // Reason : clustersetting class no longer has igmpjoininterval
  15. // property.
  16. //
  17. // Revised by : mhakim
  18. // Date : 02-14-01
  19. // Reason : The order in which win2k and whistler settings
  20. // is done depends on previous state of cluster.
  21. // include files
  22. #include "MNLBMachine.h"
  23. #include "MNLBExe.h"
  24. #include "MTrace.h"
  25. #include "MNicInfo.h"
  26. #include "WTokens.h"
  27. #include <iostream>
  28. using namespace std;
  29. // constructor
  30. //
  31. MNLBMachine::MNLBMachine( const _bstr_t& ip,
  32. const _bstr_t& clusterIP )
  33. : mIP( ip ),
  34. mClusterIP( clusterIP ),
  35. p_machine( 0 )
  36. {
  37. connectToMachine();
  38. TRACE(MTrace::INFO, L"mnlbmachine constructor\n");
  39. }
  40. // constructor for local machine
  41. //
  42. MNLBMachine::MNLBMachine( const _bstr_t& clusterIP )
  43. : mIP( L"self" ),
  44. mClusterIP( clusterIP ),
  45. p_machine( 0 )
  46. {
  47. connectToMachine();
  48. TRACE(MTrace::INFO, L"mnlbmachine constructor\n");
  49. }
  50. // default constructor
  51. //
  52. // note that default constructor is purposely left undefined.
  53. // NO one should be using it. It is declared just for vector class usage.
  54. // copy constructor
  55. //
  56. MNLBMachine::MNLBMachine(const MNLBMachine& objToCopy )
  57. : mIP( objToCopy.mIP ),
  58. mClusterIP( objToCopy.mClusterIP ),
  59. p_machine( auto_ptr<MWmiObject>( new MWmiObject( *objToCopy.p_machine ) ) )
  60. {
  61. TRACE(MTrace::INFO, L"mnlbsmachine copy constructor\n");
  62. }
  63. // assignment operator
  64. //
  65. MNLBMachine&
  66. MNLBMachine::operator=( const MNLBMachine& rhs )
  67. {
  68. mIP = rhs.mIP;
  69. mClusterIP = rhs.mClusterIP;
  70. p_machine = auto_ptr<MWmiObject>( new MWmiObject( *rhs.p_machine ) );
  71. TRACE(MTrace::INFO, L"mnlbsmachine assignment operator\n");
  72. return *this;
  73. }
  74. // destructor
  75. //
  76. MNLBMachine::~MNLBMachine()
  77. {
  78. TRACE(MTrace::INFO, L"mnlbsmachine destructor\n");
  79. }
  80. // getClusterProperties
  81. //
  82. MNLBMachine::MNLBMachine_Error
  83. MNLBMachine::getClusterProperties( ClusterProperties* cp )
  84. {
  85. // set parameters to get for win2k
  86. //
  87. vector<MWmiParameter* > parameterStoreWin2k;
  88. MWmiParameter ClusterIPAddress(L"ClusterIPAddress");
  89. parameterStoreWin2k.push_back( &ClusterIPAddress );
  90. MWmiParameter ClusterNetworkMask(L"ClusterNetworkMask");
  91. parameterStoreWin2k.push_back( &ClusterNetworkMask );
  92. MWmiParameter ClusterName(L"ClusterName");
  93. parameterStoreWin2k.push_back( &ClusterName );
  94. MWmiParameter ClusteMACAddress(L"ClusterMACAddress");
  95. parameterStoreWin2k.push_back( &ClusteMACAddress );
  96. MWmiParameter MulticastSupportEnabled(L"MulticastSupportEnabled");
  97. parameterStoreWin2k.push_back( &MulticastSupportEnabled );
  98. MWmiParameter RemoteControlEnabled(L"RemoteControlEnabled");
  99. parameterStoreWin2k.push_back( &RemoteControlEnabled );
  100. // set parameters to get for whistler
  101. // these properties only present in whistler.
  102. //
  103. vector<MWmiParameter* > parameterStoreWhistler;
  104. MWmiParameter IgmpSupport(L"IgmpSupport");
  105. parameterStoreWhistler.push_back( &IgmpSupport );
  106. MWmiParameter ClusterIPToMulticastIP(L"ClusterIPToMulticastIP");
  107. parameterStoreWhistler.push_back( &ClusterIPToMulticastIP );
  108. MWmiParameter MulticastIPAddress(L"MulticastIPAddress");
  109. parameterStoreWhistler.push_back( &MulticastIPAddress );
  110. // Edited( mhakim 02-09-01)
  111. // now no longer do we have any igmpjoininterval property.
  112. //
  113. // MWmiParameter IgmpJoinInterval(L"IgmpJoinInterval");
  114. // parameterStoreWhistler.push_back( &IgmpJoinInterval );
  115. // get instances of clustersetting class.
  116. //
  117. vector< MWmiInstance > instanceStore;
  118. _bstr_t relPath = L"MicrosoftNLB_ClusterSetting.Name=\"" + mClusterIP + L":" + mHostID + L"\"";
  119. p_machine->getSpecificInstance( L"MicrosoftNLB_ClusterSetting",
  120. relPath,
  121. &instanceStore );
  122. // get win2k parameters
  123. instanceStore[0].getParameters( parameterStoreWin2k );
  124. // get whistler parameters
  125. bool machineIsWhistler = true;
  126. try
  127. {
  128. // this will fail on win2k
  129. // as adapterguid, igmpsupport etc are not present.
  130. instanceStore[0].getParameters( parameterStoreWhistler );
  131. }
  132. catch( _com_error e )
  133. {
  134. // maybe it was a win2k machine. This exception is expected, thus catch.
  135. // for better safety, need to find exact error code returned and then only do the
  136. // folllowing otherwise need to rethrow.
  137. //
  138. TRACE( MTrace::INFO, L"tried whistler operation on win2k, this is expected\n");
  139. machineIsWhistler = false;
  140. }
  141. cp->cIP = ClusterIPAddress.getValue();
  142. cp->cSubnetMask = ClusterNetworkMask.getValue();
  143. cp->cFullInternetName = ClusterName.getValue();
  144. cp->cNetworkAddress = ClusteMACAddress.getValue();
  145. cp->multicastSupportEnabled = MulticastSupportEnabled.getValue();
  146. cp->remoteControlEnabled = RemoteControlEnabled.getValue();
  147. if( machineIsWhistler == true )
  148. {
  149. cp->igmpSupportEnabled = IgmpSupport.getValue();
  150. cp->clusterIPToMulticastIP = ClusterIPToMulticastIP.getValue();
  151. cp->multicastIPAddress = MulticastIPAddress.getValue();
  152. // Edited( mhakim 02-09-01)
  153. // now no longer do we have any igmpjoininterval property.
  154. //
  155. // cp->igmpJoinInterval = IgmpJoinInterval.getValue();
  156. }
  157. return MNLBMachine_SUCCESS;
  158. }
  159. // getHostProperties
  160. //
  161. MNLBMachine::MNLBMachine_Error
  162. MNLBMachine::getHostProperties( HostProperties* hp )
  163. {
  164. // get node properties
  165. //
  166. vector<MWmiParameter* > parameterStoreWin2k;
  167. // the status code is to be got from the Node class.
  168. //
  169. MWmiParameter StatusCode(L"StatusCode");
  170. parameterStoreWin2k.push_back( &StatusCode );
  171. vector< MWmiInstance > instanceStore;
  172. _bstr_t relPath = L"MicrosoftNLB_Node.Name=\"" + mClusterIP + L":" + mHostID + L"\"";
  173. p_machine->getSpecificInstance( L"MicrosoftNLB_Node",
  174. relPath,
  175. &instanceStore );
  176. instanceStore[0].getParameters( parameterStoreWin2k );
  177. hp->hostStatus = long( StatusCode.getValue() );
  178. parameterStoreWin2k.erase( parameterStoreWin2k.begin(), parameterStoreWin2k.end() );
  179. instanceStore.erase( instanceStore.begin(), instanceStore.end() );
  180. MWmiParameter DedicatedIPAddress(L"DedicatedIPAddress");
  181. parameterStoreWin2k.push_back( &DedicatedIPAddress );
  182. MWmiParameter DedicatedNetworkMask(L"DedicatedNetworkMask");
  183. parameterStoreWin2k.push_back( &DedicatedNetworkMask );
  184. MWmiParameter HostPriority(L"HostPriority");
  185. parameterStoreWin2k.push_back( &HostPriority );
  186. MWmiParameter ClusterModeOnStart(L"ClusterModeOnStart");
  187. parameterStoreWin2k.push_back( &ClusterModeOnStart );
  188. MWmiParameter Server("__Server");
  189. parameterStoreWin2k.push_back( &Server);
  190. // set parameters to get for whistler
  191. // these properties only present in whistler.
  192. //
  193. vector<MWmiParameter* > parameterStoreWhistler;
  194. MWmiParameter AdapterGuid(L"AdapterGuid");
  195. parameterStoreWhistler.push_back( &AdapterGuid );
  196. // get instances of nodesetting class.
  197. //
  198. relPath = L"MicrosoftNLB_NodeSetting.Name=\"" + mClusterIP + L":" + mHostID + L"\"";
  199. p_machine->getSpecificInstance( L"MicrosoftNLB_NodeSetting",
  200. relPath,
  201. &instanceStore );
  202. // get win2k parameters.
  203. instanceStore[0].getParameters( parameterStoreWin2k );
  204. // get whistler parameters
  205. bool machineIsWhistler = true;
  206. try
  207. {
  208. // this will fail on win2k
  209. // as adapterguid, igmpsupport etc are not present.
  210. instanceStore[0].getParameters( parameterStoreWhistler );
  211. }
  212. catch( _com_error e )
  213. {
  214. // maybe it was a win2k machine. This exception is expected, thus catch.
  215. // for better safety, need to find exact error code returned and then only do the
  216. // folllowing otherwise need to rethrow.
  217. //
  218. TRACE( MTrace::INFO, L"tried whistler operation on win2k, this is expected\n");
  219. machineIsWhistler = false;
  220. }
  221. hp->hIP = DedicatedIPAddress.getValue();
  222. hp->hSubnetMask = DedicatedNetworkMask.getValue();
  223. hp->hID = HostPriority.getValue();
  224. hp->initialClusterStateActive = ClusterModeOnStart.getValue();
  225. hp->machineName = Server.getValue();
  226. if( machineIsWhistler == true )
  227. {
  228. Common::getNLBNicInfoForWhistler( mIP,
  229. _bstr_t( AdapterGuid.getValue() ),
  230. hp->nicInfo );
  231. }
  232. else
  233. {
  234. Common::getNLBNicInfoForWin2k( mIP,
  235. hp->nicInfo );
  236. }
  237. return MNLBMachine_SUCCESS;
  238. }
  239. // setClusterProperties
  240. //
  241. MNLBMachine::MNLBMachine_Error
  242. MNLBMachine::setClusterProperties( const ClusterProperties& cp,
  243. unsigned long* retVal
  244. )
  245. {
  246. // set parameters to set for win2k
  247. vector<MWmiParameter* > parameterStoreWin2k;
  248. MWmiParameter ClusterIPAddress(L"ClusterIPAddress");
  249. ClusterIPAddress.setValue( cp.cIP );
  250. parameterStoreWin2k.push_back( &ClusterIPAddress );
  251. MWmiParameter ClusterNetworkMask(L"ClusterNetworkMask");
  252. ClusterNetworkMask.setValue( cp.cSubnetMask );
  253. parameterStoreWin2k.push_back( &ClusterNetworkMask );
  254. MWmiParameter ClusterName(L"ClusterName");
  255. ClusterName.setValue( cp.cFullInternetName );
  256. parameterStoreWin2k.push_back( &ClusterName );
  257. // mac address cannot be set.
  258. MWmiParameter MulticastSupportEnabled(L"MulticastSupportEnabled");
  259. MulticastSupportEnabled.setValue( cp.multicastSupportEnabled );
  260. parameterStoreWin2k.push_back( &MulticastSupportEnabled );
  261. MWmiParameter RemoteControlEnabled(L"RemoteControlEnabled");
  262. RemoteControlEnabled.setValue( cp.remoteControlEnabled );
  263. parameterStoreWin2k.push_back( &RemoteControlEnabled );
  264. // set parameters for whistler.
  265. // these properties only for whistler
  266. vector<MWmiParameter* > parameterStoreWhistler;
  267. MWmiParameter IgmpSupport(L"IgmpSupport");
  268. IgmpSupport.setValue( cp.igmpSupportEnabled );
  269. parameterStoreWhistler.push_back( &IgmpSupport );
  270. MWmiParameter ClusterIPToMulticastIP(L"ClusterIPToMulticastIP");
  271. ClusterIPToMulticastIP.setValue( cp.clusterIPToMulticastIP );
  272. parameterStoreWhistler.push_back( &ClusterIPToMulticastIP );
  273. MWmiParameter MulticastIPAddress(L"MulticastIPAddress");
  274. MulticastIPAddress.setValue( cp.multicastIPAddress );
  275. parameterStoreWhistler.push_back( &MulticastIPAddress );
  276. // Edited( mhakim 02-09-01)
  277. // now no longer do we have any igmpjoininterval property.
  278. //
  279. // MWmiParameter IgmpJoinInterval(L"IgmpJoinInterval");
  280. // IgmpJoinInterval.setValue( cp.igmpJoinInterval );
  281. // parameterStoreWhistler.push_back( &IgmpJoinInterval );
  282. vector< MWmiInstance > instanceStore;
  283. _bstr_t relPath = L"MicrosoftNLB_ClusterSetting.Name=\"" + mClusterIP + L":" + mHostID + L"\"";
  284. p_machine->getSpecificInstance( L"MicrosoftNLB_ClusterSetting",
  285. relPath,
  286. &instanceStore );
  287. // Edited( mhakim 02-14-01)
  288. //
  289. // The order in which win2k and whistler operations
  290. // need to be done depends on previous state of cluster.
  291. // If the previous mode of cluster was unicast, then
  292. // you have to do win2k first, whistler next.
  293. // If the previous mode was mcast+igmp you have to
  294. // do whistler first, win2k next.
  295. // If the previous mode was mcast, the order does not
  296. // matter.
  297. // All this is because you cant have unicast+igmp
  298. // together.
  299. // find previous cluster mode.
  300. ClusterProperties cpPrevious;
  301. getClusterProperties( &cpPrevious );
  302. if( cpPrevious.multicastSupportEnabled == false )
  303. {
  304. // mode is unicast
  305. // set win2k parameters.
  306. instanceStore[0].setParameters( parameterStoreWin2k );
  307. // set whistler parameters.
  308. try
  309. {
  310. instanceStore[0].setParameters( parameterStoreWhistler );
  311. }
  312. catch( _com_error e )
  313. {
  314. // maybe it was a win2k machine. This exception is expected, thus catch.
  315. // For better safety, need to match error code returned with expected and then only do the
  316. // folllowing otherwise need to rethrow.
  317. //
  318. TRACE( MTrace::INFO, L"tried whistler operation on win2k, this is expected\n");
  319. }
  320. }
  321. else
  322. {
  323. // set whistler parameters.
  324. try
  325. {
  326. instanceStore[0].setParameters( parameterStoreWhistler );
  327. }
  328. catch( _com_error e )
  329. {
  330. // maybe it was a win2k machine. This exception is expected, thus catch.
  331. // For better safety, need to match error code returned with expected and then only do the
  332. // folllowing otherwise need to rethrow.
  333. //
  334. TRACE( MTrace::INFO, L"tried whistler operation on win2k, this is expected\n");
  335. }
  336. // set win2k parameters.
  337. instanceStore[0].setParameters( parameterStoreWin2k );
  338. }
  339. // sync up the driver with these changes.
  340. reload( retVal );
  341. mClusterIP = cp.cIP;
  342. return MNLBMachine_SUCCESS;
  343. }
  344. // setHostProperties
  345. //
  346. MNLBMachine::MNLBMachine_Error
  347. MNLBMachine::setHostProperties( const HostProperties& hp,
  348. unsigned long* retVal )
  349. {
  350. // set node properties
  351. //
  352. vector<MWmiParameter* > parameterStore;
  353. MWmiParameter DedicatedIPAddress(L"DedicatedIPAddress");
  354. DedicatedIPAddress.setValue( hp.hIP );
  355. parameterStore.push_back( &DedicatedIPAddress );
  356. MWmiParameter DedicatedNetworkMask(L"DedicatedNetworkMask");
  357. DedicatedNetworkMask.setValue( hp.hSubnetMask );
  358. parameterStore.push_back( &DedicatedNetworkMask );
  359. MWmiParameter HostPriority(L"HostPriority");
  360. HostPriority.setValue( hp.hID );
  361. parameterStore.push_back( &HostPriority );
  362. MWmiParameter ClusterModeOnStart(L"ClusterModeOnStart");
  363. ClusterModeOnStart.setValue( hp.initialClusterStateActive );
  364. parameterStore.push_back( &ClusterModeOnStart );
  365. // get instances of nodesetting class.
  366. //
  367. vector< MWmiInstance > instanceStore;
  368. _bstr_t relPath = L"MicrosoftNLB_NodeSetting.Name=\"" + mClusterIP + L":" + mHostID + L"\"";
  369. p_machine->getSpecificInstance( L"MicrosoftNLB_NodeSetting",
  370. relPath,
  371. &instanceStore );
  372. instanceStore[0].setParameters( parameterStore );
  373. // convert hp.hID into string
  374. wchar_t hIDString[Common::BUF_SIZE];
  375. swprintf( hIDString, L"%d", hp.hID );
  376. // sync up the driver with these changes.
  377. reload( retVal );
  378. mHostID = hIDString;
  379. return MNLBMachine_SUCCESS;
  380. }
  381. // getPortRulesLoadBalanced
  382. //
  383. MNLBMachine::MNLBMachine_Error
  384. MNLBMachine::getPortRulesLoadBalanced( vector<MNLBPortRuleLoadBalanced>* portsLB )
  385. {
  386. vector<MWmiInstance> instanceStore;
  387. return getPortRulesLoadBalanced_private( portsLB,
  388. &instanceStore );
  389. }
  390. // getPortRulesLoadBalanced_private
  391. //
  392. MNLBMachine::MNLBMachine_Error
  393. MNLBMachine::getPortRulesLoadBalanced_private( vector<MNLBPortRuleLoadBalanced>* portsLB,
  394. vector<MWmiInstance>* instances )
  395. {
  396. _bstr_t myName = mClusterIP + L":" + mHostID;
  397. // get port properties.
  398. //
  399. vector<MWmiParameter* > parameterStore;
  400. MWmiParameter Name(L"Name");
  401. parameterStore.push_back( &Name );
  402. MWmiParameter StartPort(L"StartPort");
  403. parameterStore.push_back( &StartPort );
  404. MWmiParameter EndPort(L"EndPort");
  405. parameterStore.push_back( &EndPort );
  406. MWmiParameter ProtocolProp(L"Protocol");
  407. parameterStore.push_back( &ProtocolProp );
  408. MWmiParameter EqualLoad(L"EqualLoad");
  409. parameterStore.push_back( &EqualLoad );
  410. MWmiParameter LoadWeight(L"LoadWeight");
  411. parameterStore.push_back( &LoadWeight );
  412. MWmiParameter AffinityProp(L"Affinity");
  413. parameterStore.push_back( &AffinityProp );
  414. MNLBPortRule::Affinity affinity;
  415. MNLBPortRule::Protocol trafficToHandle;
  416. p_machine->getInstances( L"MicrosoftNLB_PortRuleLoadBalanced",
  417. instances );
  418. for( int i = 0; i < instances->size(); ++i )
  419. {
  420. (*instances)[i].getParameters( parameterStore );
  421. if( _bstr_t( Name.getValue() ) != myName )
  422. {
  423. // this portrule is not for this cluster
  424. continue;
  425. }
  426. switch( long (ProtocolProp.getValue()) )
  427. {
  428. case 1:
  429. trafficToHandle = MNLBPortRule::tcp;
  430. break;
  431. case 2:
  432. trafficToHandle = MNLBPortRule::udp;
  433. break;
  434. case 3:
  435. trafficToHandle = MNLBPortRule::both;
  436. break;
  437. default:
  438. // bug.
  439. TRACE( MTrace::SEVERE_ERROR, "unidentified protocol\n" );
  440. throw _com_error( WBEM_E_UNEXPECTED );
  441. break;
  442. }
  443. switch( long(AffinityProp.getValue()) )
  444. {
  445. case 0:
  446. affinity = MNLBPortRule::none;
  447. break;
  448. case 1:
  449. affinity = MNLBPortRule::single;
  450. break;
  451. case 2:
  452. affinity = MNLBPortRule::classC;
  453. break;
  454. default:
  455. // bug.
  456. TRACE( MTrace::SEVERE_ERROR, "unidentified affinity\n" );
  457. throw _com_error( WBEM_E_UNEXPECTED );
  458. break;
  459. }
  460. portsLB->push_back( MNLBPortRuleLoadBalanced(long (StartPort.getValue()),
  461. long( EndPort.getValue()),
  462. trafficToHandle,
  463. bool( EqualLoad.getValue()),
  464. long( LoadWeight.getValue()),
  465. affinity) );
  466. }
  467. return MNLBMachine_SUCCESS;
  468. }
  469. // getPortRulesFailover
  470. //
  471. MNLBMachine::MNLBMachine_Error
  472. MNLBMachine::getPortRulesFailover( vector<MNLBPortRuleFailover>* portsF )
  473. {
  474. vector<MWmiInstance> instanceStore;
  475. return getPortRulesFailover_private( portsF,
  476. &instanceStore );
  477. }
  478. // getPortRulesFailover_private
  479. //
  480. MNLBMachine::MNLBMachine_Error
  481. MNLBMachine::getPortRulesFailover_private( vector<MNLBPortRuleFailover>* portsF,
  482. vector<MWmiInstance>* instances )
  483. {
  484. _bstr_t myName = mClusterIP + L":" + mHostID;
  485. // get port properties.
  486. //
  487. vector<MWmiParameter* > parameterStore;
  488. MWmiParameter Name(L"Name");
  489. parameterStore.push_back( &Name );
  490. MWmiParameter StartPort(L"StartPort");
  491. parameterStore.push_back( &StartPort );
  492. MWmiParameter EndPort(L"EndPort");
  493. parameterStore.push_back( &EndPort );
  494. MWmiParameter ProtocolProp(L"Protocol");
  495. parameterStore.push_back( &ProtocolProp );
  496. MWmiParameter Priority(L"Priority");
  497. parameterStore.push_back( &Priority );
  498. MNLBPortRule::Protocol trafficToHandle;
  499. p_machine->getInstances( L"MicrosoftNLB_PortRuleFailover",
  500. instances );
  501. for( int i = 0; i < instances->size(); ++i )
  502. {
  503. (*instances)[i].getParameters( parameterStore );
  504. if( _bstr_t( Name.getValue() ) != myName )
  505. {
  506. // this portrule is not for this cluster
  507. continue;
  508. }
  509. switch( long (ProtocolProp.getValue()) )
  510. {
  511. case 1:
  512. trafficToHandle = MNLBPortRule::tcp;
  513. break;
  514. case 2:
  515. trafficToHandle = MNLBPortRule::udp;
  516. break;
  517. case 3:
  518. trafficToHandle = MNLBPortRule::both;
  519. break;
  520. default:
  521. // bug.
  522. TRACE( MTrace::SEVERE_ERROR, "unidentified protocol\n" );
  523. throw _com_error( WBEM_E_UNEXPECTED );
  524. break;
  525. }
  526. portsF->push_back( MNLBPortRuleFailover(long (StartPort.getValue()),
  527. long( EndPort.getValue()),
  528. trafficToHandle,
  529. long( Priority.getValue()) )
  530. );
  531. }
  532. return MNLBMachine_SUCCESS;
  533. }
  534. // getPortRulesDisabled
  535. //
  536. MNLBMachine::MNLBMachine_Error
  537. MNLBMachine::getPortRulesDisabled( vector<MNLBPortRuleDisabled>* portsD )
  538. {
  539. vector<MWmiInstance> instanceStore;
  540. return getPortRulesDisabled_private( portsD,
  541. &instanceStore );
  542. }
  543. // getPortRulesDisabled_private
  544. //
  545. MNLBMachine::MNLBMachine_Error
  546. MNLBMachine::getPortRulesDisabled_private( vector<MNLBPortRuleDisabled>* portsD,
  547. vector<MWmiInstance>* instances )
  548. {
  549. _bstr_t myName = mClusterIP + L":" + mHostID;
  550. // get port properties.
  551. //
  552. vector<MWmiParameter* > parameterStore;
  553. MWmiParameter Name(L"Name");
  554. parameterStore.push_back( &Name );
  555. MWmiParameter StartPort(L"StartPort");
  556. parameterStore.push_back( &StartPort );
  557. MWmiParameter EndPort(L"EndPort");
  558. parameterStore.push_back( &EndPort );
  559. MWmiParameter ProtocolProp(L"Protocol");
  560. parameterStore.push_back( &ProtocolProp );
  561. MNLBPortRule::Protocol trafficToHandle;
  562. p_machine->getInstances( L"MicrosoftNLB_PortRuleDisabled",
  563. instances );
  564. for( int i = 0; i < instances->size(); ++i )
  565. {
  566. (*instances)[i].getParameters( parameterStore );
  567. if( _bstr_t( Name.getValue() ) != myName )
  568. {
  569. // this portrule is not for this cluster
  570. continue;
  571. }
  572. switch( long (ProtocolProp.getValue()) )
  573. {
  574. case 1:
  575. trafficToHandle = MNLBPortRule::tcp;
  576. break;
  577. case 2:
  578. trafficToHandle = MNLBPortRule::udp;
  579. break;
  580. case 3:
  581. trafficToHandle = MNLBPortRule::both;
  582. break;
  583. default:
  584. // bug.
  585. TRACE( MTrace::SEVERE_ERROR, "unidentified protocol\n" );
  586. throw _com_error( WBEM_E_UNEXPECTED );
  587. break;
  588. }
  589. portsD->push_back( MNLBPortRuleDisabled( long (StartPort.getValue() ),
  590. long( EndPort.getValue() ),
  591. trafficToHandle ) );
  592. }
  593. return MNLBMachine_SUCCESS;
  594. }
  595. // addPortRuleLoadBalanced
  596. //
  597. MNLBMachine::MNLBMachine_Error
  598. MNLBMachine::addPortRuleLoadBalanced( const MNLBPortRuleLoadBalanced& portRuleLB )
  599. {
  600. // set the name as "clusterip:hostid"
  601. _bstr_t str;
  602. str = mClusterIP + L":" + mHostID;
  603. vector<MWmiParameter *> instanceParameter;
  604. MWmiParameter name(L"Name");
  605. name.setValue( str );
  606. instanceParameter.push_back( &name );
  607. MWmiParameter sp(L"StartPort");
  608. sp.setValue( portRuleLB._startPort );
  609. instanceParameter.push_back( &sp );
  610. MWmiParameter EndPort(L"EndPort");
  611. EndPort.setValue( portRuleLB._endPort );
  612. instanceParameter.push_back( &EndPort );
  613. long protocolValue;
  614. MWmiParameter protocol(L"Protocol");
  615. switch( portRuleLB._trafficToHandle )
  616. {
  617. case MNLBPortRule::both:
  618. protocolValue = 3;
  619. protocol.setValue( protocolValue );
  620. break;
  621. case MNLBPortRule::tcp:
  622. protocolValue = 1;
  623. protocol.setValue( protocolValue );
  624. break;
  625. case MNLBPortRule::udp:
  626. protocolValue = 2;
  627. protocol.setValue( protocolValue );
  628. break;
  629. default:
  630. // bug.
  631. TRACE( MTrace::SEVERE_ERROR, "unidentified protocol\n" );
  632. throw _com_error( WBEM_E_UNEXPECTED );
  633. break;
  634. }
  635. instanceParameter.push_back( &protocol );
  636. MWmiParameter el(L"EqualLoad");
  637. el.setValue( portRuleLB._isEqualLoadBalanced );
  638. instanceParameter.push_back( &el );
  639. MWmiParameter lw(L"LoadWeight");
  640. lw.setValue( portRuleLB._load );
  641. instanceParameter.push_back( &lw );
  642. MWmiParameter affinity(L"Affinity");
  643. long affinityValue;
  644. switch( portRuleLB._affinity )
  645. {
  646. case MNLBPortRule::none:
  647. affinityValue = 0;
  648. affinity.setValue(affinityValue);
  649. break;
  650. case MNLBPortRule::single:
  651. affinityValue = 1;
  652. affinity.setValue(affinityValue);
  653. break;
  654. case MNLBPortRule::classC:
  655. affinityValue = 2;
  656. affinity.setValue(affinityValue);
  657. break;
  658. default:
  659. // bug.
  660. TRACE( MTrace::SEVERE_ERROR, "unidentified affinity\n" );
  661. throw _com_error( WBEM_E_UNEXPECTED );
  662. break;
  663. }
  664. instanceParameter.push_back( &affinity );
  665. p_machine->createInstance( L"MicrosoftNLB_PortRuleLoadBalanced",
  666. instanceParameter
  667. );
  668. // sync up the driver with these changes.
  669. unsigned long retVal;
  670. reload( &retVal );
  671. return MNLBMachine_SUCCESS;
  672. }
  673. // addPortRuleFailover
  674. //
  675. MNLBMachine::MNLBMachine_Error
  676. MNLBMachine::addPortRuleFailover( const MNLBPortRuleFailover& portRuleF )
  677. {
  678. // set the name as "clusterip:hostid"
  679. _bstr_t str;
  680. str = mClusterIP + L":" + mHostID;
  681. vector<MWmiParameter *> instanceParameter;
  682. MWmiParameter name(L"Name");
  683. name.setValue( str );
  684. instanceParameter.push_back( &name );
  685. MWmiParameter sp(L"StartPort");
  686. sp.setValue( portRuleF._startPort );
  687. instanceParameter.push_back( &sp );
  688. MWmiParameter EndPort(L"EndPort");
  689. EndPort.setValue( portRuleF._endPort );
  690. instanceParameter.push_back( &EndPort );
  691. long protocolValue;
  692. MWmiParameter protocol(L"Protocol");
  693. switch( portRuleF._trafficToHandle )
  694. {
  695. case MNLBPortRule::both:
  696. protocolValue = 3;
  697. protocol.setValue( protocolValue );
  698. break;
  699. case MNLBPortRule::tcp:
  700. protocolValue = 1;
  701. protocol.setValue( protocolValue );
  702. break;
  703. case MNLBPortRule::udp:
  704. protocolValue = 2;
  705. protocol.setValue( protocolValue );
  706. break;
  707. default:
  708. TRACE( MTrace::SEVERE_ERROR, "unidentified protocol\n" );
  709. throw _com_error( WBEM_E_UNEXPECTED );
  710. break;
  711. }
  712. instanceParameter.push_back( &protocol );
  713. MWmiParameter p("Priority");
  714. p.setValue( portRuleF._priority);
  715. instanceParameter.push_back( &p );
  716. p_machine->createInstance( L"MicrosoftNLB_PortRuleFailover",
  717. instanceParameter
  718. );
  719. // sync up the driver with these changes.
  720. unsigned long retVal;
  721. reload( &retVal );
  722. return MNLBMachine_SUCCESS;
  723. }
  724. // addPortRuleDisabled
  725. //
  726. MNLBMachine::MNLBMachine_Error
  727. MNLBMachine::addPortRuleDisabled( const MNLBPortRuleDisabled& portRuleD )
  728. {
  729. // set the name as "clusterip:hostid"
  730. _bstr_t str;
  731. str = mClusterIP + L":" + mHostID;
  732. vector<MWmiParameter *> instanceParameter;
  733. MWmiParameter name(L"Name");
  734. name.setValue( str );
  735. instanceParameter.push_back( &name );
  736. MWmiParameter sp(L"StartPort");
  737. sp.setValue( portRuleD._startPort );
  738. instanceParameter.push_back( &sp );
  739. MWmiParameter ep(L"EndPort");
  740. ep.setValue( portRuleD._endPort );
  741. instanceParameter.push_back( &ep );
  742. long protocolValue;
  743. MWmiParameter protocol(L"Protocol");
  744. switch( portRuleD._trafficToHandle )
  745. {
  746. case MNLBPortRule::both:
  747. protocolValue = 3;
  748. protocol.setValue( protocolValue );
  749. break;
  750. case MNLBPortRule::tcp:
  751. protocolValue = 1;
  752. protocol.setValue( protocolValue );
  753. break;
  754. case MNLBPortRule::udp:
  755. protocolValue = 2;
  756. protocol.setValue( protocolValue );
  757. break;
  758. default:
  759. // bug.
  760. TRACE( MTrace::SEVERE_ERROR, "unidentified protocol\n" );
  761. throw _com_error( WBEM_E_UNEXPECTED );
  762. break;
  763. }
  764. instanceParameter.push_back( &protocol );
  765. p_machine->createInstance( L"MicrosoftNLB_PortRuleDisabled",
  766. instanceParameter
  767. );
  768. // sync up the driver with these changes.
  769. unsigned long retVal;
  770. reload( &retVal );
  771. return MNLBMachine_SUCCESS;
  772. }
  773. // removePortRuleLoadBalanced
  774. //
  775. MNLBMachine::MNLBMachine_Error
  776. MNLBMachine::removePortRuleLoadBalanced( const MNLBPortRuleLoadBalanced& portRuleLB )
  777. {
  778. _bstr_t myName = mClusterIP + L":" + mHostID;
  779. wchar_t startPortBuffer[Common::BUF_SIZE];
  780. swprintf( startPortBuffer, L"%d", portRuleLB._startPort );
  781. vector<MWmiInstance > instanceStorePortRuleLoadBalanced;
  782. _bstr_t relPath = L"MicrosoftNLB_PortRuleLoadBalanced.Name=\""
  783. + mClusterIP + L":" + mHostID + L"\"" + L"," + L"StartPort=" + startPortBuffer;
  784. p_machine->getSpecificInstance( L"MicrosoftNlb_PortRuleLoadBalanced",
  785. relPath,
  786. &instanceStorePortRuleLoadBalanced );
  787. p_machine->deleteInstance( instanceStorePortRuleLoadBalanced[0] );
  788. // sync up the driver with these changes.
  789. unsigned long retVal;
  790. reload( &retVal );
  791. return MNLBMachine_SUCCESS;
  792. }
  793. // removePortRuleFailover
  794. //
  795. MNLBMachine::MNLBMachine_Error
  796. MNLBMachine::removePortRuleFailover( const MNLBPortRuleFailover& portRuleF )
  797. {
  798. _bstr_t myName = mClusterIP + L":" + mHostID;
  799. wchar_t startPortBuffer[Common::BUF_SIZE];
  800. swprintf( startPortBuffer, L"%d", portRuleF._startPort );
  801. vector<MWmiInstance > instanceStorePortRuleFailover;
  802. _bstr_t relPath = L"MicrosoftNLB_PortRuleFailover.Name=\""
  803. + mClusterIP + L":" + mHostID + L"\"" + L"," + L"StartPort=" + startPortBuffer;
  804. p_machine->getSpecificInstance( L"MicrosoftNlb_PortRuleFailover",
  805. relPath,
  806. &instanceStorePortRuleFailover );
  807. p_machine->deleteInstance( instanceStorePortRuleFailover[0] );
  808. // sync up the driver with these changes.
  809. unsigned long retVal;
  810. reload( &retVal );
  811. return MNLBMachine_SUCCESS;
  812. }
  813. // removePortRuleDisabled
  814. //
  815. MNLBMachine::MNLBMachine_Error
  816. MNLBMachine::removePortRuleDisabled( const MNLBPortRuleDisabled& portRuleD )
  817. {
  818. _bstr_t myName = mClusterIP + L":" + mHostID;
  819. wchar_t startPortBuffer[Common::BUF_SIZE];
  820. swprintf( startPortBuffer, L"%d", portRuleD._startPort );
  821. vector<MWmiInstance > instanceStorePortRuleDisabled;
  822. _bstr_t relPath = L"MicrosoftNLB_PortRuleDisabled.Name=\""
  823. + mClusterIP + L":" + mHostID + L"\"" + L"," + L"StartPort=" + startPortBuffer;
  824. p_machine->getSpecificInstance( L"MicrosoftNlb_PortRuleDisabled",
  825. relPath,
  826. &instanceStorePortRuleDisabled );
  827. p_machine->deleteInstance( instanceStorePortRuleDisabled[0] );
  828. // sync up the driver with these changes.
  829. unsigned long retVal;
  830. reload( &retVal );
  831. return MNLBMachine_SUCCESS;
  832. }
  833. // start
  834. //
  835. MNLBMachine::MNLBMachine_Error
  836. MNLBMachine::start( int hostID, unsigned long* retVal )
  837. {
  838. // get the specific instance to run method on.
  839. vector< MWmiInstance > instanceStore;
  840. getInstanceToRunMethodOn( hostID, &instanceStore );
  841. MNLBExe::start( instanceStore[0], retVal );
  842. return MNLBMachine_SUCCESS;
  843. }
  844. // stop
  845. //
  846. MNLBMachine::MNLBMachine_Error
  847. MNLBMachine::stop( int hostID, unsigned long* retVal )
  848. {
  849. // get the specific instance to run method on.
  850. vector< MWmiInstance > instanceStore;
  851. getInstanceToRunMethodOn( hostID, &instanceStore );
  852. MNLBExe::stop( instanceStore[0], retVal );
  853. return MNLBMachine_SUCCESS;
  854. }
  855. // resume
  856. //
  857. MNLBMachine::MNLBMachine_Error
  858. MNLBMachine::resume( int hostID, unsigned long* retVal )
  859. {
  860. // get the specific instance to run method on.
  861. vector< MWmiInstance > instanceStore;
  862. getInstanceToRunMethodOn( hostID, &instanceStore );
  863. MNLBExe::resume( instanceStore[0], retVal );
  864. return MNLBMachine_SUCCESS;
  865. }
  866. // suspend
  867. //
  868. MNLBMachine::MNLBMachine_Error
  869. MNLBMachine::suspend( int hostID, unsigned long* retVal )
  870. {
  871. // get the specific instance to run method on.
  872. vector< MWmiInstance > instanceStore;
  873. getInstanceToRunMethodOn( hostID, &instanceStore );
  874. MNLBExe::suspend( instanceStore[0], retVal );
  875. return MNLBMachine_SUCCESS;
  876. }
  877. // drainstop
  878. //
  879. MNLBMachine::MNLBMachine_Error
  880. MNLBMachine::drainstop( int hostID, unsigned long* retVal )
  881. {
  882. // get the specific instance to run method on.
  883. vector< MWmiInstance > instanceStore;
  884. getInstanceToRunMethodOn( hostID, &instanceStore );
  885. MNLBExe::drainstop( instanceStore[0], retVal );
  886. return MNLBMachine_SUCCESS;
  887. }
  888. // disable
  889. //
  890. MNLBMachine::MNLBMachine_Error
  891. MNLBMachine::disable( int hostID, unsigned long* retVal, unsigned long portToAffect )
  892. {
  893. // get the specific instance to run method on.
  894. vector< MWmiInstance > instanceStore;
  895. getInstanceToRunMethodOn( hostID, &instanceStore );
  896. MNLBExe::disable( instanceStore[0], retVal, portToAffect );
  897. return MNLBMachine_SUCCESS;
  898. }
  899. // enable
  900. //
  901. MNLBMachine::MNLBMachine_Error
  902. MNLBMachine::enable( int hostID, unsigned long* retVal, unsigned long portToAffect )
  903. {
  904. // get the specific instance to run method on.
  905. vector< MWmiInstance > instanceStore;
  906. getInstanceToRunMethodOn( hostID, &instanceStore );
  907. MNLBExe::enable( instanceStore[0], retVal, portToAffect );
  908. return MNLBMachine_SUCCESS;
  909. }
  910. // drain
  911. //
  912. MNLBMachine::MNLBMachine_Error
  913. MNLBMachine::drain( int hostID, unsigned long* retVal, unsigned long portToAffect )
  914. {
  915. // get the specific instance to run method on.
  916. vector< MWmiInstance > instanceStore;
  917. getInstanceToRunMethodOn( hostID, &instanceStore );
  918. MNLBExe::drain( instanceStore[0], retVal, portToAffect );
  919. return MNLBMachine_SUCCESS;
  920. }
  921. // reload
  922. //
  923. MNLBMachine::MNLBMachine_Error
  924. MNLBMachine::reload( unsigned long* retVal )
  925. {
  926. vector<MWmiInstance > instanceStoreClusterSetting;
  927. _bstr_t relPath = L"MicrosoftNLB_ClusterSetting.Name=\"" + mClusterIP + L":" + mHostID + L"\"";
  928. p_machine->getSpecificInstance( L"MicrosoftNLB_ClusterSetting",
  929. relPath,
  930. &instanceStoreClusterSetting );
  931. // input parameters are none.
  932. //
  933. vector<MWmiParameter *> inputParameters;
  934. // output parameters which are of interest.
  935. //
  936. vector<MWmiParameter *> outputParameters;
  937. MWmiParameter returnValue(L"ReturnValue");
  938. outputParameters.push_back( &returnValue );
  939. instanceStoreClusterSetting[0].runMethod( L"LoadAllSettings",
  940. inputParameters,
  941. outputParameters );
  942. *retVal = ( long ) returnValue.getValue();
  943. return MNLBMachine_SUCCESS;
  944. }
  945. // getInstanceToRunMethodOn
  946. MNLBMachine::MNLBMachine_Error
  947. MNLBMachine::getInstanceToRunMethodOn( int hID, vector <MWmiInstance>* instanceStore )
  948. {
  949. vector<MWmiInstance> instanceStoreX;
  950. _bstr_t relPath;
  951. // see if we want to run clusterwide or host specific method.
  952. if( hID == Common::ALL_HOSTS )
  953. {
  954. // cluster wide
  955. relPath = L"MicrosoftNLB_Cluster.Name=\"" + mClusterIP + L"\"";
  956. p_machine->getSpecificInstance( L"MicrosoftNLB_Cluster",
  957. relPath,
  958. &instanceStoreX );
  959. instanceStore->push_back( instanceStoreX[0] );
  960. }
  961. else if( hID == Common::THIS_HOST )
  962. {
  963. // this host specific
  964. relPath = L"MicrosoftNLB_Node.Name=\"" + mClusterIP + L":" + mHostID + L"\"";
  965. p_machine->getSpecificInstance( L"MicrosoftNLB_Node",
  966. relPath,
  967. &instanceStoreX );
  968. instanceStore->push_back( instanceStoreX[0] );
  969. }
  970. else
  971. {
  972. // some other host
  973. // convert hID into string
  974. wchar_t hostIDBuf[1000];
  975. swprintf( hostIDBuf, L"%d", hID );
  976. relPath = L"MicrosoftNLB_Node.Name=\"" + mClusterIP + L":" + hostIDBuf + L"\"";
  977. p_machine->getSpecificInstance( L"MicrosoftNLB_Node",
  978. relPath,
  979. &instanceStoreX );
  980. instanceStore->push_back( instanceStoreX[0] );
  981. }
  982. return MNLBMachine_SUCCESS;
  983. }
  984. // refreshConnection
  985. //
  986. MNLBMachine::MNLBMachine_Error
  987. MNLBMachine::refreshConnection()
  988. {
  989. return connectToMachine();
  990. }
  991. // connectToMachine
  992. //
  993. MNLBMachine::MNLBMachine_Error
  994. MNLBMachine::connectToMachine()
  995. {
  996. MTrace* trace = MTrace::Instance();
  997. MTrace::TraceLevel prevLevel = trace->GetLevel();
  998. vector<HostProperties> hostPropertiesStore;
  999. // basically two operations need to succeed.
  1000. // 1. Is machine ip specified usable or not.
  1001. // 2. Is the nic specified bound to nlbs or not.
  1002. //
  1003. // connect to machine
  1004. //
  1005. if( mIP == _bstr_t( L"self") )
  1006. {
  1007. // we want to connect to self machine.
  1008. p_machine = auto_ptr< MWmiObject > ( new MWmiObject( L"root\\microsoftnlb") );
  1009. }
  1010. else if( mIP == mClusterIP )
  1011. {
  1012. // connecting to cluster remotely using cluster ip.
  1013. try
  1014. {
  1015. trace->SetLevel( MTrace::NO_TRACE );
  1016. p_machine = auto_ptr<MWmiObject> ( new MWmiObject( mIP,
  1017. L"root\\microsoftnlb",
  1018. L"Administrator",
  1019. L"" ) );
  1020. }
  1021. catch( _com_error e )
  1022. {
  1023. trace->SetLevel( prevLevel );
  1024. TRACE(MTrace::INFO, L"connection using clusterip has failed\n" );
  1025. // Now we will be using api call wlbs query as situation may be that all hosts in cluster are stopped, and no connection
  1026. // can be established to cluster ip, or there may be no such cluster and we will throw exception.
  1027. //
  1028. // get all hosts participating in cluster.
  1029. DWORD ret = Common::getHostsInCluster( mClusterIP, &hostPropertiesStore );
  1030. if( hostPropertiesStore.size() == 0 )
  1031. {
  1032. // no hosts are in this cluster. Cannot proceed reliably.
  1033. wstring errString;
  1034. errString = L"cluster " + wstring( mClusterIP ) + L" reported as having no hosts. Maybe cluster ip is wrong, or remote control is turned off\n";
  1035. TRACE( MTrace::SEVERE_ERROR, errString );
  1036. throw _com_error( WBEM_E_NOT_FOUND );
  1037. }
  1038. // check if any host has dedicated ip not present
  1039. // if this is so then object may not function reliably.
  1040. bool allZero = true;
  1041. int validHost;
  1042. for( int i = 0; i < hostPropertiesStore.size(); ++i )
  1043. {
  1044. if( hostPropertiesStore[i].hIP == _bstr_t( L"0.0.0.0" ) )
  1045. {
  1046. // host does not have valid dedicated ip.
  1047. TRACE( MTrace::SEVERE_ERROR, "a host has no dedicated ip. Some object operations may not work as expected\n");
  1048. }
  1049. else
  1050. {
  1051. // not all hosts have dedicated ip not filled in.
  1052. // keep a track of this host.
  1053. allZero = false;
  1054. validHost = i;
  1055. }
  1056. }
  1057. // check if all hosts had invalid dedicated ip.
  1058. if( allZero == true )
  1059. {
  1060. // all hosts have dedicated ip invalid.
  1061. TRACE( MTrace::SEVERE_ERROR, "all cluster hosts have dedicated ip 0.0.0.0\n");
  1062. throw _com_error( WBEM_E_INVALID_PROPERTY );
  1063. }
  1064. p_machine = auto_ptr<MWmiObject>( new MWmiObject( hostPropertiesStore[validHost].hIP,
  1065. L"root\\microsoftnlb",
  1066. L"Administrator",
  1067. L"") );
  1068. }
  1069. }
  1070. else
  1071. {
  1072. // we want to connect to remote machine.
  1073. p_machine = auto_ptr<MWmiObject> ( new MWmiObject( mIP,
  1074. L"root\\microsoftnlb",
  1075. L"Administrator",
  1076. L"" ) );
  1077. }
  1078. // check if specified cluster ip exists on this machine
  1079. // and find the host id corresponding to this cluster on this machine.
  1080. checkClusterIPAndSetHostID();
  1081. return MNLBMachine_SUCCESS;
  1082. }
  1083. MNLBMachine::MNLBMachine_Error
  1084. MNLBMachine::checkClusterIPAndSetHostID()
  1085. {
  1086. // set parameter to get.
  1087. // we are interested in name.
  1088. //
  1089. vector<MWmiParameter* > parameterStore;
  1090. MWmiParameter Name(L"Name");
  1091. parameterStore.push_back( &Name );
  1092. // get instances of clustersetting class.
  1093. //
  1094. vector< MWmiInstance > instanceStore;
  1095. bool found = false;
  1096. int i;
  1097. p_machine->getInstances( L"Microsoftnlb_ClusterSetting",
  1098. &instanceStore );
  1099. found = false;
  1100. for( i = 0; i < instanceStore.size(); ++i )
  1101. {
  1102. instanceStore[i].getParameters( parameterStore );
  1103. WTokens tok;
  1104. vector<wstring> tokens;
  1105. tok.init( wstring( _bstr_t(Name.getValue()) ),
  1106. L":" );
  1107. tokens = tok.tokenize();
  1108. _bstr_t clusterIP = tokens[0].c_str();
  1109. mHostID = tokens[1].c_str();
  1110. if( mClusterIP == clusterIP )
  1111. {
  1112. // right object found
  1113. found = true;
  1114. break;
  1115. }
  1116. }
  1117. if( found == false )
  1118. {
  1119. TRACE(
  1120. MTrace::SEVERE_ERROR,
  1121. L"this machine does not have any cluster with specified cluster ip\n");
  1122. throw _com_error( WBEM_E_NOT_FOUND );
  1123. }
  1124. return MNLBMachine_SUCCESS;
  1125. }
  1126. // getPresentHostsInfo
  1127. //
  1128. MNLBMachine::MNLBMachine_Error
  1129. MNLBMachine::getPresentHostsInfo(
  1130. vector< MNLBMachine::HostInfo >* hostInfoStore)
  1131. {
  1132. vector<MWmiParameter* > parameterStore;
  1133. MWmiParameter Name(L"Name");
  1134. parameterStore.push_back( &Name );
  1135. MWmiParameter DedicatedIPAddress(L"DedicatedIPAddress");
  1136. parameterStore.push_back( &DedicatedIPAddress );
  1137. vector< MWmiInstance > instanceStore;
  1138. p_machine->getInstances( L"MicrosoftNLB_Node",
  1139. &instanceStore );
  1140. for( int i = 0; i < instanceStore.size(); ++i )
  1141. {
  1142. instanceStore[i].getParameters( parameterStore );
  1143. // Name is in format of "clusterIP:hostID"
  1144. //
  1145. WTokens tok;
  1146. vector<wstring> tokens;
  1147. tok.init( wstring( _bstr_t(Name.getValue()) ),
  1148. L":" );
  1149. tokens = tok.tokenize();
  1150. _bstr_t clusterIP = tokens[0].c_str();
  1151. if( mClusterIP == clusterIP )
  1152. {
  1153. HostInfo hostInfo;
  1154. hostInfo.hostID = _wtoi( tokens[1].c_str() );
  1155. hostInfo.dedicatedIP = DedicatedIPAddress.getValue();
  1156. hostInfoStore->push_back( hostInfo );
  1157. }
  1158. }
  1159. return MNLBMachine_SUCCESS;
  1160. }
  1161. // setPassword
  1162. //
  1163. MNLBMachine::MNLBMachine_Error
  1164. MNLBMachine::setPassword( const _bstr_t& password,
  1165. unsigned long* retVal
  1166. )
  1167. {
  1168. // form path
  1169. _bstr_t relPath = L"MicrosoftNLB_ClusterSetting.Name=\"" + mClusterIP + L":" + mHostID + L"\"";
  1170. vector<MWmiInstance > instanceStoreClusterSetting;
  1171. p_machine->getSpecificInstance( L"MicrosoftNLB_ClusterSetting",
  1172. relPath,
  1173. &instanceStoreClusterSetting );
  1174. // input parameters is password
  1175. //
  1176. vector<MWmiParameter *> inputParameters;
  1177. MWmiParameter Password(L"Password");
  1178. Password.setValue( password );
  1179. inputParameters.push_back( &Password );
  1180. // output parameters which are of interest.
  1181. // none.
  1182. //
  1183. vector<MWmiParameter *> outputParameters;
  1184. instanceStoreClusterSetting[0].runMethod( L"SetPassword",
  1185. inputParameters,
  1186. outputParameters );
  1187. reload( retVal );
  1188. return MNLBMachine_SUCCESS;
  1189. }