Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Managing a windows cluster from C#

I am trying to start/stop a windows based cluster in C#, below is the code I am working with so far...when I get to TakeOffLine function below I get a "Not Found" exception from, System.Management.ManagementStatus.NotFound. Not sure what is exactly not being found? If there is a (alternate) better way of doing this please let me know.

Thanks!

using System.Management;
class App
{
    public static void Main()
    {
        string clusterName = "clusterHex";    // cluster alias
        string custerGroupResource = "clusterHex.internal.com"; // Cluster group name

        ConnectionOptions options = new ConnectionOptions();
        options.Authentication = System.Management.AuthenticationLevel.PacketPrivacy;

        // 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 void TakeOffLine(ManagementObject resourceGroup)
    {
        ManagementBaseObject outParams =
        resourceGroup.InvokeMethod("Takeoffline", null, null);
    }
    static void BringOnLine(ManagementObject resourceGroup)
    {
        ManagementBaseObject outParams =
        resourceGroup.InvokeMethod("Takeoffline", null, null);
    }
}
like image 445
user205834 Avatar asked Feb 01 '11 20:02

user205834


People also ask

What is Microsoft failover cluster Manager?

Microsoft Failover Cluster Manager (MSFCM) is a specific management function within the Windows Server operating system which is used to create, validate, and manage failover server clusters running Windows Server.


1 Answers

Looks like you're missing case in your method call. You have to use TakeOffline according to msdn

static void TakeOffLine(ManagementObject resourceGroup)
{
    ManagementBaseObject outParams =
    resourceGroup.InvokeMethod("TakeOffline", null, null);
}
like image 113
Nekresh Avatar answered Oct 15 '22 11:10

Nekresh