Chuck Haeberle said:
Willy,
I would be very interested in seeing such a sample. What are the WMI
Cluster Classes you mention? I have a similar need - to monitor and
restart
if needed a service on a cluster, and have not had much luck to date
finding
manged objects to allow me to perform this simple task. I could always
issue
shell commands, but thats just ... klugy.
Your help would be MOST appreciated!
Chuck Haeberle
Herewith a small sample that illustrates how one can use System.Management
and WMI to write cluster management application, note that the cluster needs
to run W2K3 for this to work.
using System;
using System.Management;
class App {
[MTAThread]
public static void Main() {
string clusterName = "MyCluster"; // cluster alias
string custerGroupResource = "FS_Resource1"; // Cluster group name
ConnectionOptions options = new ConnectionOptions();
options.Username = "ClusterAdmin"; //could be in domain\user format
options.Password = "HisPassword";
// Connect with the mscluster WMI namespace on the cluster named "MyCluster"
ManagementScope s = new ManagementScope("\\\\" + clusterName +
"\\root\\mscluster", options);
ManagementPath p = new ManagementPath("Mscluster_Clustergroup.Name='" +
custerGroupResource +"'");
using(ManagementObject clrg = new ManagementObject (s, p, null ))
{
// Take clustergroup off line and read its status property when done
TakeOffLine(clrg);
clrg.Get();
Console.WriteLine(clrg["Status"]);
System.Threading.Thread.Sleep(3000); // Sleep for a while
// Bring back online and get status.
BringOnLine(clrg);
clrg.Get();
Console.WriteLine(clrg["Status"]);
}
}
static voidTakeOffLine(ManagementObject resourceGroup)
{
ManagementBaseObject outParams =
resourceGroup.InvokeMethod("Takeoffline", null, null);
}
static void BringOnLine(ManagementObject resourceGroup)
{
ManagementBaseObject outParams =
resourceGroup.InvokeMethod("Takeoffline", null, null);
}
}
Check the MSDN documentation for all other WMI mscluster namespace classes,
and write some small programs to exercize the features offered by the
individual classes.
If in doubt about some property or feature, load wbemtest.exe and connect to
the cluster namespace. Wbemtest allows you to get/change the properties of
cluster resources and execute the methods exposed by the mscluster classes.
Willy.