Monday, 12 September 2016

RAID Groups Calculator (RAID-DP) – Revisited

An update of this post. An example of it in action is below. It’s very simple to run, just run as .\RGcalc.ps1 the first time and it will tell you the command line syntax if you want to re-run and make minor changes.

Image: RGcalc.ps1 in action!

The Script

Copy the below into to a text editor and save as RGcalc.ps1:


##########################
## RGcalc.ps1 (RAID-DP) ##
##########################

Param(
  [Parameter(Mandatory=$True,HelpMessage="Number of shelves on the node/HA-pair.")]
  [alias("SC")][Int]$Shelf_Count___,
  [Parameter(Mandatory=$True,HelpMessage="Number of disks in a shelf (12/14/24/48).")]
  [alias("SD")][Int]$Disks_In_Shelf,
  [Parameter(Mandatory=$True,HelpMessage="If you have require root disks (3 for a node/6 for a HA-pair).")]
  [alias("RD")][Int]$Root_Disks____,
  [Parameter(Mandatory=$True,HelpMessage="Number of spares on the node/HA-pair.")]
  [alias("SP")][Int]$Spares_Count__,
  [Parameter(Mandatory=$True,HelpMessage="Number of other disks to be removed from the calculation.")]
  [alias("OD")][Int]$Other_Disks___,
  [Parameter(Mandatory=$True,HelpMessage="Target RAID group size.`nTYPE: Default => Maximum`nSSD: 23 => 28`nSAS/FC: 16 => 28`nSATA: 14 => 20`n6TB MSATA: 14 => 14")]
  [alias("RG")][Int]$Target_RG_Size,
  [Parameter(Mandatory=$True,HelpMessage="Answer 'y' or 'n' depending on if you want a fixed RAID group size or not.")]
  [alias("Fx")][String]$Fixed_RG_Size_,
  [Parameter(Mandatory=$True,HelpMessage="Right-Size info to get aggr capacity.")]
  [alias("RS")][Int]$Disk_RightSize
)

## ===== PARAM VALIDATION ===== ##
If("y","n" -NotContains $Fixed_RG_Size_){"Answer y or n for FixedRGsize!";EXIT}
$Shelf_Count___,$Disks_In_Shelf,$Target_RG_Size | Foreach{If($_ -le 1){"Invalid input!";EXIT}}
$Root_Disks____,$Spares_Count__,$Other_Disks___,$Disk_RightSize | Foreach{If($_ -lt 0){"Invalid input!";EXIT}}

## ===== CALCULATION ===== ##
Function RoundUp{Param([Double]$N);[Int][Math]::Ceiling($N)}
[Int]$AvailableDisks = ($Shelf_Count___ * $Disks_In_Shelf) - $Root_Disks____ - $Spares_Count__ - $Other_Disks___
[Int]$RaidGroups = RoundUp($AvailableDisks/$Target_RG_Size)
[Int]$AvrgRGsize = RoundUp($AvailableDisks/$RaidGroups)
[Int]$LastRGsize = $AvailableDisks - (($RaidGroups -1)*$AvrgRGsize)
[Int]$Balancer = RoundUp(($AvrgRGsize - $LastRGsize) / $RaidGroups)
[System.Array]$Output = @()
For($i=1;$i -lt $RaidGroups;$i++){
  If(($LastRGsize + $Balancer) -lt $Target_RG_Size){
    $Output += ($AvrgRGsize - $Balancer)
    $LastRGsize += $Balancer
  }else{ $Output += $AvrgRGsize }
}
$Output += $LastRGsize
$Output = $Output | Sort -Descending

## ===== OVERRIDE FOR FIXED RG SIZE ===== ##
If($Fixed_RG_Size_ -eq "y"){
  If(($Target_RG_Size * $RaidGroups) -gt $AvailableDisks){ $RaidGroups-- }
  $Spares_Count__ = $Spares_Count__ + $AvailableDisks - ($RaidGroups * $Target_RG_Size)
  $AvailableDisks = ($RaidGroups * $Target_RG_Size) # Available disks for RAID Groups needs recalculation with -FixedRGsize
  [System.Array]$Output = @()
  For($j=1;$j -lt $RaidGroups;$j++){ $Output += $Target_RG_Size }
};""

## ===== OUTPUT ===== ##
">>>>> RAID Groups Calculator (RAID-DP) - RGcalc.ps1 <<<<<";""
"RAID Group: Count = " + [String]$RaidGroups
"RAID Group: Sizes = " + [String]$Output;""
[Int]$DataDisks = $AvailableDisks - ($RaidGroups * 2)
"DISKS: Data   = " + [String]$DataDisks
"DISKS: Parity = " + [String]($RaidGroups * 2)
"DISKS: Spares = " + [String]$Spares_Count__
"DISKS: Other  = " + [String]($Root_Disks____ + $Other_Disks___)
"------------- -"
"DISKS: TOTAL  = " + [String]($Shelf_Count___ * $Disks_In_Shelf);""
If($Disk_RightSize -ne 0){
  [Int]$AggrCap = $DataDisks * $Disk_RightSize
  "100%/97%/90% AGGR CAPACITY = " + [String]$AggrCap + " / " + [String]([Int]($AggrCap*0.97)) + " / " + [String]([Int]($AggrCap*0.90));""
}
"PS> .\RGcalc.ps1 -SC $Shelf_Count___ -SD $Disks_In_Shelf -RD $Root_Disks____ -SP $Spares_Count__ -OD $Other_Disks___ -RG $Target_RG_Size -Fx $Fixed_RG_Size_ -RS $Disk_RightSize";""


No comments:

Post a Comment