VMware Cloud Community
satheeshsatz
Enthusiast
Enthusiast
Jump to solution

Check if the Datastore is detached or not using LUNID

Whenever we perform EOW of storage array controller, we are performing datastore migration from OLD datastore to NEW datastore.

After migraion, we are informing Storage team to reclaim those LUNs during that stage, they always double check with us, whether these LUNs can be reclaimed or not. We used to manually check, if these LUNs are detached or not and confirming them.

Always they used to give us LUN ID as below

isrtpxiv32     7811090_01e2 (thp_474)      RAID1      1     4388000

isrtpxiv32     7811090_0d8d (thp_630)      RAID1      4     4388000

isrtpxiv32     7811090_3b44 (thp_606)      RAID1      2     4388000

isrtpxiv32     7811090_3b45 (thp_607)      RAID1      3     4388000

 

Where LUN ID is = 01e2, 0d8d 3b44 3b45 and NAA ID will have these strings ex: NAA.6742b0f0000004530000000000003b45, NAA.6742b0f0000004530000000000003b44.

Now i want to automate this to avoid manual error.

Whenever they give as LUN ID, i would like to check, those string contains LUN(NAA ID) is in place or detached.

 

Please help me on this.

Always they used to give us LUN ID as below
isrtpxiv32     7811090_01e2 (thp_474)      RAID1      1     4388000
isrtpxiv32     7811090_0d8d (thp_630)      RAID1      4     4388000
isrtpxiv32     7811090_3b44 (thp_606)      RAID1      2     4388000
isrtpxiv32     7811090_3b45 (thp_607)      RAID1      3     4388000
 
Where LUN ID is = 01e2, 0d8d 3b44 3b45 and NAA ID will have these strings ex: NAA.6742b0f0000004530000000000003b45, NAA.6742b0f0000004530000000000003b44.
Now i want to automate this to avoid manual error.
 
Whenever they give as LUN ID, i would like to check, those string contains LUN(NAA ID) is in place or detached.
 
Please help me on this.
Regards, Satheesh
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

The V2 switch on the Get-EsxCli cmdlet was introduced already some PowerCLI releases ago.

It allows to work with the newer esxcli objects.

If you are running a PowerCLI version that does not support this, you should seriously consider upgrading.

Try like this

$data = @(

"isrtpxiv32     7811090_01e2 (thp_474)      RAID1      1     4388000",

"isrtpxiv32     7811090_0d8d (thp_630)      RAID1      4     4388000",

"isrtpxiv32     7811090_3b44 (thp_606)      RAID1      2     4388000",

"isrtpxiv32     7811090_3b45 (thp_607)      RAID1      3     4388000"

)

$lunIds = $data | %{

    ($_.Split() | where{$_})[1].Split('_')[1]

}

Foreach($esx in Get-VMHost){

    $esxcli = Get-EsxCli -VMHost $esx -V2

    Get-ScsiLun -VmHost $esx -LunType disk |

    where{$lunIds -contains $_.CanonicalName.Substring($_.CanonicalName.IndexOf('_') + 1)} | %{

        $esxcli.storage.core.device.list.Invoke(@{device=$_.CanonicalName}) |

        Select @{N='VMHost';E={$esx.Name}},Device,Status,

            @{N='Datastore';E={

                $canName =  $_.Device

                $esxcli.storage.vmfs.extent.list.Invoke() |

                where{$_.DeviceName -eq $canName} |

                Select -ExpandProperty VolumeName}}

    }

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
5 Replies
LucD
Leadership
Leadership
Jump to solution

You could do something like this

$data = @(

"isrtpxiv32     7811090_01e2 (thp_474)      RAID1      1     4388000",

"isrtpxiv32     7811090_0d8d (thp_630)      RAID1      4     4388000",

"isrtpxiv32     7811090_0020 (thp_606)      RAID1      2     4388000",

"isrtpxiv32     7811090_0024 (thp_607)      RAID1      3     4388000"

)

$lunIds = $data | %{

    ($_.Split() | where{$_})[1].Split('_')[1]

}

Foreach($esx in Get-VMHost){

    $esxcli = Get-EsxCli -VMHost $esx -V2

    Get-ScsiLun -VmHost $esx -LunType disk |

    where{$lunIds -contains $_.CanonicalName.Substring($_.CanonicalName.Length - 4)} | %{

        $esxcli.storage.core.device.list.Invoke(@{device=$_.CanonicalName}) |

        Select @{N='VMHost';E={$esx.Name}},Device,Status

    }

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

satheeshsatz
Enthusiast
Enthusiast
Jump to solution

    $esxcli = Get-EsxCli -VMHost $esx -V2, 

in this whatis -V2?

Thank you Lucd,

i will check this and let you know. however 

Regards, Satheesh
0 Kudos
satheeshsatz
Enthusiast
Enthusiast
Jump to solution

hi LucD,
found few errors like, on the below commands, we gave input as constant 4 to minus for substring.

    Get-ScsiLun -VmHost $esx -LunType disk |

    where{$lunIds -contains $_.CanonicalName.Substring($_.CanonicalName.Length - 4)}

 

but in certain cases, input might be with 4digit LUN and it also can contain 5 or 6 digit LUN, 

during that stage, this is not working properly, what shall we do in that case?

 

Regards, Satheesh
0 Kudos
satheeshsatz
Enthusiast
Enthusiast
Jump to solution

also, if any LUNs status is on, then i need to get its datastore name, how to do?

your scripts are very very high level and i feel like, i am at very very beginning stage 😄

Regards, Satheesh
0 Kudos
LucD
Leadership
Leadership
Jump to solution

The V2 switch on the Get-EsxCli cmdlet was introduced already some PowerCLI releases ago.

It allows to work with the newer esxcli objects.

If you are running a PowerCLI version that does not support this, you should seriously consider upgrading.

Try like this

$data = @(

"isrtpxiv32     7811090_01e2 (thp_474)      RAID1      1     4388000",

"isrtpxiv32     7811090_0d8d (thp_630)      RAID1      4     4388000",

"isrtpxiv32     7811090_3b44 (thp_606)      RAID1      2     4388000",

"isrtpxiv32     7811090_3b45 (thp_607)      RAID1      3     4388000"

)

$lunIds = $data | %{

    ($_.Split() | where{$_})[1].Split('_')[1]

}

Foreach($esx in Get-VMHost){

    $esxcli = Get-EsxCli -VMHost $esx -V2

    Get-ScsiLun -VmHost $esx -LunType disk |

    where{$lunIds -contains $_.CanonicalName.Substring($_.CanonicalName.IndexOf('_') + 1)} | %{

        $esxcli.storage.core.device.list.Invoke(@{device=$_.CanonicalName}) |

        Select @{N='VMHost';E={$esx.Name}},Device,Status,

            @{N='Datastore';E={

                $canName =  $_.Device

                $esxcli.storage.vmfs.extent.list.Invoke() |

                where{$_.DeviceName -eq $canName} |

                Select -ExpandProperty VolumeName}}

    }

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos