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.

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