Microsoft Virtualization Discussions
Microsoft Virtualization Discussions
So, i'm at it again... Just playing around and thinking of things I can mess around with and we ran across an issue where we had specific shelf issues in our environment and I wanted to know immediately what volumes were affected.
Yah, I can go to my autosupports and backtrack through aggregates, but that's not fun...
So, I'm just messing around with a simple query on the disk but i'm having trouble getting the entire picture...
Here's where i'm at so far..
$hosts = @("filer1a","filer1b")
$hosts | % {
Write-host Connecting to Filer: $_
$c = connect-nacontroller $_
$shelf = get-nadisk | ? {($_.name -like "*1b*" -or $_.name -like "*2b*") -and $_.shelf -eq "3" -and $_.aggregate -ne $null}
$shelf | Ft -groupby @{E ={$C};Label="Filer"} -autosize
}
Tthat will give me a clear picture of which filer owns the disks on channel 1b/2b shelf 3, but I want to turn this into what volumes are part of this... My powershell skills are just not taking me to where I need to be at this moment, but i'm giving it a shot.
I know the get-nadisk has an aggregate property and I planned on looping that into this
get-navol -aggregate $_.aggregate, but i'm having trouble putting it all together..
I need to understand that $shelf should have all the properties and why can't I just do something like $shelf.aggregate.
Can someone point me in the right direction...
Thanks
Shelves don't map directly to aggregates, disks do. So the shelves in a disk may be part of 0, 1, or many aggregates.
In your script you could add a couple lines like the following to enumerate the related vols:
$aggrs = $shelf | select -Unique Aggregate | select -Expand Aggregate
$vols = $aggrs | % {get-navol -Aggregate $_}
Note that those vols/aggregates might spill over into other shelves even if you didn't set it up that way initially (e.g. when replacing a failed disk).
Great question, and nice script example by the way.
Here is some code I was playing with before Eric's response. It is not the most elegant of solutions and doesn't account for the channels, hope it is of some use.
Actually, thinking about it, this code will probably only work if you have 1 loop or stack due to the selections based on the shelf ID.
$hosts | % {
Write-host Connecting to Filer: $_
$c = Connect-NaController $_
#Select distinct shelves from controller
$shelves = Get-NaShelf | select-object id -unique
foreach ($s in $shelves) {
Write-Host "Shelf: " $s.ID
$disks = Get-NaDisk | ? {$_.shelf -eq $s.ID}
#select distinct aggregates from output
$aggregates = (Get-NaDisk | ? {($_.shelf -eq $s.ID) -and ($_.aggregate -ne $null)}) | select-object aggregate -unique
if ($aggregates -ne $null) {
#select volumes from aggregates
foreach ($a in $aggregates) {
$vols = Get-NaVol -aggregate $a.Aggregate
Write-Host " Aggregate: " $a.Aggregate
Write-Host " Volumes: "
foreach ($v in $vols) {
Write-Host " " $v.Name
}
}
}
}
}
Eric,
Thx for the input as usual... Im playing around with it, but not quite getting exactly what I want.. maybe I should group my output by aggregate and filer...
Here's the last line I put in
$vols | Select Name,State,Aggregate | Ft -groupby @{E = {$_.aggregate};Label="Aggregate"} -autosize
Sort of gives me an overall picture of ok, disks on a specified channel contain these disks, which are part of these aggregates, and here's the volume and the status....
I will keep playin around with it.
Ashley -
Great job.. I'm diggin yours... I like the formatting of it a lot better than mine..
What we should do is add the disk ID numbers, so for example it could say
Shelf 1: Disks 1a.10 1a.11 1a.22
etc...
Well, here is a little addition.. Not quite thrilled with it.
Foreach ($d in $disks) { | |
Write-host " Disks: " $d.name | |
} |
So.. What's interesting is i'm specifically looking for issues on channel 1b/2b. But when I run your script it's telling me way too much information for shelf 3.
I'll keep playin around..
Ok, so i'm sure this can be done prettier or more efficient, but this is what I got so far... I am explicitly defining my search criteria.
### File Constants
$date = (get-date).toString('dd-MMM-yyyy_h-mm-ss')
$ext = ".log"
$outfile = "fileclusters_clu_" + $date + $ext
FUNCTION shelfinfo
{
$aggrs = $shelf | select -Unique Aggregate | select -Expand Aggregate
$vols = $aggrs | % {get-navol -Aggregate $_}
$volumes = $vols | Select Name,State,Aggregate | Ft -groupby @{E = {$_.aggregate};Label="Aggregate"} -autosize
$volumes
$volumes | Out-file $outfile -append
}
$hosts = @("filer1a","filer1b")
$hosts | % {
Write-host Connecting to Filer: $_
out-file $outfile -inputobject "Connecting to filer: $_ " -append
$Shelfnumber = "3"
$c = connect-nacontroller $_
Write-host " Shelf Number $shelfnumber on Channel 1b/2b "
Out-file $outfile -inputobject " Shelf Number $shelfnumber on Channel 1b/2b " -append
$shelf = get-nadisk | ? {($_.name -like "*1b*" -or $_.name -like "*2b*") -and $_.shelf -eq $shelfnumber -and $_.aggregate -ne $null}
# Call Shelf info
if ($shelf -ne $null) {
shelfinfo
}
}
## Next Host
$hosts = @("filer2a","filer2b")
$hosts | % {
Write-host Connecting to Filer: $_
out-file $outfile -inputobject "Connecting to filer: $_ " -append
$Shelfnumber = "1"
$c = connect-nacontroller $_
Write-host " Shelf Number $shelfnumber on Channel 1b/2b "
Out-file $outfile -inputobject " Shelf Number $shelfnumber on Channel 1b/2b " -append
$shelf = get-nadisk | ? {($_.name -like "*1b*" -or $_.name -like "*2b*") -and $_.shelf -eq $shelfnumber -and $_.aggregate -ne $null}
# Call Shelf info
if ($shelf -ne $null)
{
shelfinfo
}
}
Last updated for the day...
I forgot the most important part.. disk ID numbers.
Function Diskinfo
{
foreach ($disk in $shelf)
{
$diskname = $disk.name
Write-host " Disk ID:" $diskname
out-file $outfile -inputobject " Disk ID: $diskname " -append
}
}
if ($shelf -ne $null)
#Call function disk info
{
diskinfo
}
Nice, that is looking good.
Do you have more that one loop or stack on the system you ran my code against? I'm being quite harsh in how I determine how many shelves are on the system.
What I did was to identify shelves based purely on their ID:
$shelves = Get-NaShelf | select-object id -unique
In my case this isn't an issue as there is only a single stack of shelves, so what I end up with is one list which makes a big assumption that two shelves with the same ID are actually the same shelf.
My memory is a little hazy on this, but I think if you were to have two separate stacks or loops, then it would be permissible to have the same shelf ID present on separate stacks/loops. The consequence of this is when I run this:
$disks = Get-NaDisk | ? {$_.shelf -eq $s.ID}
The returned result would be that $disks would contain all disks which shared a common shelf ID. Essentially this would amalgamate the results if you had duplicate shelf IDs, which consequently would bear little resemblance to reality.
As I say, I've only got one stack here so it is difficult to test, but I think the below substitutions would give a more accurate output:
$shelves = Get-NaShelf -Controller $c
$disks = Get-NaDisk | ? {($_.shelf -eq $s.ID) -and ($_.name -like $s.channel+"*")}
For completeness, it looks something like this:
$hosts = @("filer1a","filer1b")
$hosts | % {
Write-host Connecting to Filer: $_
$c = Connect-NaController $_
#Select distinct shelves from controller
$shelves = Get-NaShelf -Controller $c
foreach ($s in $shelves) {
Write-Host "Shelf: " $s.ID " Channel: " $s.channel
$disks = Get-NaDisk | ? {($_.shelf -eq $s.ID) -and ($_.name -like $s.channel+"*")}
#select distinct aggregates from output
$aggregates = (Get-NaDisk | ? {($_.shelf -eq $s.ID) -and ($_.aggregate -ne $null)}) | select-object aggregate -unique
if ($aggregates -ne $null) {
#select volumes from aggregates
foreach ($a in $aggregates) {
$vols = Get-NaVol -aggregate $a.Aggregate
Write-Host " Aggregate: " $a.Aggregate
Write-Host " Volumes: "
foreach ($v in $vols) {
Write-Host " " $v.Name
}
}
Write-Host " Disks: "
foreach ($d in $disks) {
Write-Host " " $d
}
}
}
}
You're absolutely correct that you could have multiple shelves with the same integer ID. Even worse it's also possible that you have multiple paths to the same shelf in which case one shelf will show up twice on different channels (very common with MetroClusters).
I usually use the ShelfUid property (an 8 byte random ID) to determine uniqueness:
Get-NaShelf | group ShelfUid
But since disks don't have that info, Ashley is absolutely right. I'd add that for completeness you'll need to match on the Name or SecondaryName properties of the shelf:
get-nadisk | ? {($_.Name -match $shelf.Channel -or $_.SecondaryName -match $shelf.Channel) -and $_.Shelf -eq $shelf.ID}
That's getting pretty ugly, so a function/cmdlet might be in order:
function Get-NaDiskByShelf {
[CmdletBinding()]
Param
(
# Shelf
[Parameter(Mandatory=$true,
ValueFromPipeline=$true,
Position=0)]
$Shelf
)
Get-NaDisk |
Where {$_.Name -match $Shelf.Channel -or $_.SecondaryName -match $Shelf.Channel} |
Where {$_.Shelf -eq $Shelf.ID}
}
so you can do this...
PS C:\> $shelf | Get-NaDiskByShelf
Name Shelf Bay Status UsedSpace PhysSpace RPM FW Model Pool Aggregate
---- ----- --- ------ --------- --------- --- -- ----- ---- ---------
tsbrocade5100-13:10.18 1 2 parity 266 GB 274 GB 15k NA02 X279_S15K5288F15 1 aggr0
tsbrocade5100-13:10.21 1 5 spare 266 GB 274 GB 15k NA02 X279_S15K5288F15 1
tsbrocade5100-13:10.22 1 6 spare 266 GB 274 GB 15k NA02 X279_S15K5288F15 1
...
tsbrocade5100-14:10.16 1 0 data 266 GB 274 GB 15k NA02 X279_S15K5288F15 1 aggr0
...
This post has taken on some good info!