Isn't this simple and intuitive?
When using Cluster Administrator to add a Disk, the following steps are carried out by the Failover Cluster Management tool. When using cluster.exe, these have to be done manually.
Let’s go through these steps with an example:
To create a resource using cluster.exe on the cluster node we need to provide few parameters
Resource-name: A name that you want to give to your resource.
Disk ID is what we are looking for. If the Disk ID is a GUID we set DiskIDGUID parameter or if the DISK ID is a number we set DiskSignature. Generally MBR disks have signatures and GPT disks have GUIDs.
Example:
cluster res "Cluster Disk 9" /priv DiskIDGuid={E743EA77-5B49-4305-A081-A16EF94E2C63}
NOTE:
/priv represents private properties of the resource. The string following /priv should be the property name. Be careful when assigning a value to a property as a typing mistake may prevent the resource from working properly, but you can always go back and change it.
We are all set to bring the resource online and see it in action. Execute:
C:\>cluster res "Cluster Disk 9" /on
Bringing resource 'Cluster Disk 9' online...
Resource Group Node Status
-------------------- -------------------- --------------- ------
Cluster Disk 9 Available Storage c5c1f4x64n4 Online
The /on switch will bring the resource online. If this command fails double check the parameters to ensure they have the correct values.
Cluster WMI:
Many new classes have been added to Cluster WMI to make cluster administration simple and easy using WMI. We can either use any scripting language, C# code or even C++ to achieve this. For this post, I am going to provide a sample C# code and a VB script. First a few classes should be described:
MSCluster_Disk
Enumerating an instance of this class gives us a list of all the disks that are added to the cluster. More information about this class can be found at http://msdn2.microsoft.com/en-us/library/aa965285(vs.85).aspx
MSCluster_AvailableDisk
This is a new class that has been introduced in Windows Server 2008. This class provides a list of all the disks that are visible from all the nodes and can be added to the cluster.
MSCluster_ClusterToAvailableDisk
This is an associator class. Like other associater classes this provides an association between cluster and the available disks.
GroupComponent of this class is a reference of the MSCluster_Cluster class and the PartComponent is a reference to MSCluster_AvailableDisk
Let see Cluster WMI in action through a VB Script:
strClusterName = "."
' Connect to the MSCLuster name space on the Cluster
Set objWMIService = GetObject ("winmgmts:" _
& "{impersonationLevel=impersonate," _
& "authenticationLevel=pktPrivacy}!" _
& "\\" & strClusterName & "\root\MSCluster")
' Get the list of Disks with Cluster
Set objClusDisks = objWMIService.ExecQuery ("Select * from MSCLuster_Disk")
' Dump all the disks with cluster
WScript.Echo "Lists of Disks with cluster"
For each objDisk in objClusDisks
' If you wish you can dump other properties of the disk
WScript.Echo objDisk.ID
Next
' Lets get the disks that are available to be added to the cluster
Set objAvailableDisks = objWMIService.ExecQuery ("Select * from MSCluster_AvailableDisk")
WScript.Echo "Looking for Available Disks"
' Dump all the available Disks
for each objAvailDisk in objAvailableDisks
WScript.Echo "Found Disks with ID: " & objAvailDisk.ID
'Add the disk to the cluster
objRelPath = "MSCluster_AvailableDisk.ID='"
objRelPath = objRelPath & objAvailDisk.ID
objRelPath = objRelPath & "'"
WScript.Echo "Adding Disk " & objRelPath & " to the cluster"
Set objOutParams = objWMIService.ExecMethod(objRelPath, "AddToCluster")
Wscript.echo "Created Resource: " & objOutParams.Path
' Once the Disk has been added we need to online the disk
' We need to call "BringOnline" method with a timeout parameter
' Time out is specified in secs
WScript.Echo "Bringing Resource " & objOutParams.Path & " Online"
Set objResDisk = objWMIService.Get (objOutParams.Path)
Set objInParam = objResDisk.Methods_("BringOnline").inParameters.SpawnInstance_()
objInParam.Properties_.Item("TimeOut") = 60
Set objOut = objWMIService.ExecMethod(objOutParams.Path, "BringOnline", objInParam)
WScript.Echo "Resource " & objOutParams.Path & " Brougth Online"
Next
Here is a code sample in C#:
static void Main(string[] args)
{
String machineName = ".";
String nameSpace = "MSCluster";
System.Management.ConnectionOptions connOptions = new System.Management.ConnectionOptions();
connOptions.Authentication = AuthenticationLevel.PacketPrivacy;
connOptions.Username = null;
connOptions.Password = null;
System.Management.ManagementScope mgmtScope = new System.Management.ManagementScope(string.Format(@" \\{0}\root\{1} ", machineName, nameSpace), connOptions);
System.Management.ManagementObjectCollection mgmtObjColl = null;
try
{
mgmtScope.Connect();
// We are connected to WMI MSCluster namespace
// Lets Get All the available Disks.
String wmiClassName = "MSCluster_AvailableDisk";
System.Management.ManagementClass mgmtClass = new ManagementClass(mgmtScope, new ManagementPath(wmiClassName), null);
mgmtClass.Get();
mgmtObjColl = mgmtClass.GetInstances();
foreach (System.Management.ManagementObject clusDisk in mgmtObjColl)
{
ManagementBaseObject inParamsMgmtObj = null;
ManagementBaseObject outParam = null;
System.Management.ManagementObject DiskResObj = null;
try
{
Console.WriteLine("Disk ID = {0}", clusDisk["ID"].ToString());
Console.WriteLine("Path = {0}", clusDisk.SystemProperties["__RELPATH"].Value.ToString());
Console.WriteLine("Adding the disk to cluster");
inParamsMgmtObj = clusDisk.GetMethodParameters("AddToCluster");
outParam = (ManagementBaseObject)clusDisk.InvokeMethod("AddToCluster", inParamsMgmtObj, null);
Console.WriteLine("Disk Added to cluster, now trying to bring it online");
PropertyDataCollection retPropDataColl = (PropertyDataCollection)outParam.Properties;
String ResPath = retPropDataColl["Path"].Value.ToString();
Console.WriteLine("Resource Path returned = {0}", ResPath);
DiskResObj = new ManagementObject(mgmtScope, new ManagementPath(ResPath), null);
DiskResObj.Get();
DiskResObj.InvokeMethod("BringOnline", new object[] { 60 });
Console.WriteLine("Resource = {0} is brought online", ResPath);
}
catch (ManagementException mgmtException)
{
Console.WriteLine("Management (WMI) exception occured. Exception message: {0}, Error Code: {1}.", mgmtException.Message, mgmtException.ErrorCode);
if (null != mgmtException.ErrorInformation)
Console.WriteLine("Status: '{0}', Description: '{1}'.", mgmtException.ErrorInformation["StatusCode"], mgmtException.ErrorInformation["Description"]);
Console.WriteLine("Stack Trace: {0}", mgmtException.StackTrace);
// If you wisht to continue adding other disks do that else bail out
// I choose to continue
continue;
}
finally
{
if (inParamsMgmtObj != null)
inParamsMgmtObj.Dispose();
if (outParam != null)
outParam.Dispose();
if (DiskResObj != null)
DiskResObj.Dispose();
}
}
}
catch (ManagementException mgmtException)
{
Console.WriteLine("Management (WMI) exception occured. Exception message: {0}, Error Code: {1}.", mgmtException.Message, mgmtException.ErrorCode);
if (null != mgmtException.ErrorInformation)
Console.WriteLine("Status: '{0}', Description: '{1}'.", mgmtException.ErrorInformation["StatusCode"], mgmtException.ErrorInformation["Description"]);
Console.WriteLine("Stack Trace: {0}", mgmtException.StackTrace);
return;
}
finally
{
if (mgmtObjColl != null)
mgmtObjColl.Dispose();
}
}
Known Issues with Cluster WMI:
1. When we add a disk using Cluster WMI, the names given to the disk are not same as in the Failover Cluster Administrator snap-in. For example, when you add a disk through the GUI it would be assigned "Cluster Disk 1" whereas Cluster WMI would assign it "Disk 1".
2. If any node of the Cluster is not online MSCluster_AvailableDisk/MSCLuster_CLusterToAvailableDisk would return 0 available Disks.
If you have any further questions, please post a comment to this blog entry and it will be addressed.
Thanks,
Vikas Kumar
Software Development Engineer in Test
Clustering & HA
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.