Advertisement
Guest User

Untitled

a guest
Mar 9th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. string clusterName = "app-server.local";
  2. string custerGroupResource = "cluster.server.local";
  3.  
  4. ConnectionOptions options = new ConnectionOptions
  5. {
  6. Authentication = AuthenticationLevel.PacketPrivacy
  7. };
  8.  
  9. ManagementScope s = new ManagementScope("\\" + clusterName, options);
  10.  
  11. ManagementPath p = new ManagementPath("Mscluster_Clustergroup.Name='" + custerGroupResource + "'");
  12.  
  13. using (ManagementObject clrg = new ManagementObject(s, p, null))
  14. {
  15. clrg.Get();
  16. Console.WriteLine(clrg["Status"]);
  17. }
  18.  
  19. using System;
  20. using System.Collections.Generic;
  21. using System.Linq;
  22. using System.Text;
  23. using System;
  24. using System.Management;
  25.  
  26. namespace MyNamespace
  27. {
  28. public class ClusterAdmin
  29. {
  30. [MTAThread]
  31. public static void Main()
  32. {
  33. string clusterName = "MyCluster"; // cluster alias
  34. string custerGroupResource = "FS_Resource1"; // Cluster group name
  35. ConnectionOptions options = new ConnectionOptions();
  36. options.Username = "ClusterAdmin"; //could be in domainuser format
  37. options.Password = "HisPassword";
  38.  
  39. // Connect with the mscluster WMI namespace on the cluster named "MyCluster"
  40. ManagementScope s = new ManagementScope("\\" + clusterName + "\root\mscluster", options);
  41. ManagementPath p = new ManagementPath("Mscluster_Clustergroup.Name='" + custerGroupResource + "'");
  42.  
  43. using (ManagementObject clrg = new ManagementObject(s, p, null))
  44. {
  45. // Take clustergroup off line and read its status property when done
  46. TakeOffLine(clrg);
  47. clrg.Get();
  48. Console.WriteLine(clrg["Status"]);
  49.  
  50. System.Threading.Thread.Sleep(3000); // Sleep for a while
  51.  
  52. // Bring back online and get status.
  53. BringOnLine(clrg);
  54. clrg.Get();
  55. Console.WriteLine(clrg["Status"]);
  56. }
  57. }
  58. static void TakeOffLine(ManagementObject resourceGroup)
  59. {
  60. ManagementBaseObject outParams =
  61. resourceGroup.InvokeMethod("Takeoffline", null, null);
  62. }
  63. static void BringOnLine(ManagementObject resourceGroup)
  64. {
  65. ManagementBaseObject outParams =
  66. resourceGroup.InvokeMethod("Takeoffline", null, null);
  67. }
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement