Showing posts with label script. Show all posts
Showing posts with label script. Show all posts

Friday, 27 June 2014

Before using PowerPath, we wanted a way to check/fix primary fibre (even fiber) storage paths that were active across our interswitch link.

We can go in to vCenter and click on poperties for a datastore (or lun if it's an RDM) and change the active path:

But how do you do this automatically for hundreds of luns, or just check to see if they're wrong.  NetApp has a command to run on the filer to tell you if traffic is going down the wrong path, but these ESX commands will tell you if they're set wrong, even if no traffic is going down them (like on servers in a cluter that aren't running the VMs).

It's not simple, but a few key commands will get the info needed:

list all your luns by NAAid:
naa_list=`esxcfg-mpath -l | grep "naa\." | grep "Device: " | cut -d: -f2 | sort -u`

loop through all of them to check the primary path currently assigned, and whether it matches what it should be.

for naa_identifier in `echo $naa_list` ; do
   echo $naa_identifier
   echo do other commands here
done



Find the RunTime Name (VHBA-Controller-Target-LUNID) which is the active path:

# esxcli nmp fixed getpreferred --device  naa.60a98000375334364a2b42436c754239

or

# esxcli nmp fixed getpreferred --device  ${naa_identifier}

which gives:
vmhba1:C0:T3:L200

Is that on the correct initiator (SAN HBA)?

# esxcfg-mpath -L -P  vmhba1:C0:T3:L200
vmhba1:C0:T3:L200 state:active naa.60a98000375334364a2b42436c754239 vmhba1 0 3 200 NMP active san fc.20000024ff03607f:21000024ff03607f fc.500a09808d310651:500a09819d310651


See in bold above, that's the unique part of our NAAid which shows which filer owns the storage.

If it's right, you've confirmed so, if it's wrong, you need to get the correct RunTime Name and change the active path to match it.  You'll need to find a few other things first:

lun_ID=`esxcli nmp fixed getpreferred --device ${naa_identifier}  | cut -d: -f4 | tr -d "L" `
naa_identifier (see above)
correct_pripathwwn (this is one thing you have to figure out and set as variables in your script based on your unique identifiers reported by ESX for your SAN HBAs)

esxcfg-mpath -m | grep -i ${naa_identifier}

vmhba2:C0:T3:L200 vmhba2 fc.2000001b329cdc1d:2100001b329cdc1d fc.500a09808d310651:500a09829d310651 naa.60a98000375334364a2b42436c754239
vmhba1:C0:T3:L200 vmhba1 fc.20000024ff03607f:21000024ff03607f fc.500a09808d310651:500a09819d310651 naa.60a98000375334364a2b42436c754239
vmhba2:C0:T2:L200 vmhba2 fc.2000001b329cdc1d:2100001b329cdc1d fc.500a09808d310651:500a09818d310651 naa.60a98000375334364a2b42436c754239
vmhba1:C0:T2:L200 vmhba1 fc.20000024ff03607f:21000024ff03607f fc.500a09808d310651:500a09828d310651 naa.60a98000375334364a2b42436c754239
[root@VHB24 scripts]#


see how similar this info above is to the screen grab of what vCenter shows?  it's all four paths for our lun, with the full RunTime Name (VHBA-Controller-Target-LUNID) for eath of the paths to the lun.

With all that, you can get the bit needed to change the active path with this command:
correct_pripath=`[root@VHB24 scripts]# esxcfg-mpath -m | grep -i naa.60a98000375334364a2b42436c754239 | grep -i vmhba[1-2]:C0:T[0-9]:L${lun_ID} | grep ${correct_pripathwwn}`

so you can fix the active path with:
#esxcli nmp fixed setpreferred  --device ${naa_identifier} --path  ${correct_pripath}

We do have to run this on each of our hosts, but if running the script takes 20 minutes per host, imagine how long it would take to manually fix these paths on once for each of our 200 luns on our dozen hosts! 

Anyone want to put this in a powershell script?  I'm a bit embarrassed about putting my final script here as it's messy and not optimised beautifully.

The RDM part of my script looks a little like this:



-KC



Friday, 11 April 2014

Script for Setting Perennial Reservations on RDM luns

RDM's must have the perennial reservation flag set to true.

Unfortunately the four bits of info (perennial reservations setting, NAA ID, LUN_ID and Data Store Name, aren't all available from one command, so you need to do a little work.

NAAID and Perennial Reservation status:

ssh to host and run:
# esxcli storage core device list > /tmp/esxcli_reservations_naaID.txt
where you'll see the NAA id and Perennially Reserved status for all luns on that host:
naa.60060160b1b02d00559a83248cc0e311
   Display Name: DGC Fibre Channel Disk (naa.60060160b1b02d00559a83248cc0e311)
   Has Settable Display Name: false
   Size: 122880
   Device Type: Direct-Access
   Multipath Plugin: PowerPath
   Devfs Path: /vmfs/devices/disks/naa.60060160b1b02d00559a83248cc0e311
   Vendor: DGC
   Model: VRAID
   Revision: 0532
   SCSI Level: 4
   Is Pseudo: false
   Status: on
   Is RDM Capable: true
   Is Local: false
   Is Removable: false
   Is SSD: false
   Is Offline: false
   Is Perennially Reserved: false
   Queue Full Sample Size: 0
   Queue Full Threshold: 0
   Thin Provisioning Status: yes
   Attached Filters: VAAI_FILTER
   VAAI Status: supported
   Other UIDs: vml.020003000060060160b1b02d00559a83248cc0e311565241494420
   Is Local SAS Device: false
   Is Boot USB Device: false

LUN_ID and NAAID

# esxcli storage core device list | grep -C12 "Reserved: false" | grep "Path: /vmfs/devices" | cut -d. -f2 | tee /tmp/NAA_perennial_false.txt
to get the list of NAA ids of luns without perennial reservation set.

List all LUN numbers:
~ # esxcfg-mpath -l | grep "LUN:" | cut -d: -f4,5 | awk '{print $2,$3}' | sort -
u | sort -n -k2
LUN: 0
LUN: 1
LUN: 2
LUN: 3
LUN: 8
LUN: 9
LUN: 10
LUN: 11
LUN: 12
LUN: 13
LUN: 14
LUN: 15
LUN: 42
LUN: 132
LUN: 149
LUN: 151
LUN: 198
LUN: 200
LUN: 201
LUN: 202
LUN: 203
LUN: 204

NAAid and Data Store name

But most of these are VMFS datastores, which are set correctly when they have perennial reservation as false (default is correct, so don't change):

~ # esxcfg-scsidevs -m | awk '{print $1,$5}' > /tmp/esxcfg-scsidevs-m-naaID_DataStore.txt

naa.6000144000000010a0245b40d0472b3a:1 SAN_DS1
~ #

You can manually verify the RDMs and build the command below to change from False to True on RDMs:
esxcli storage core device setconfig -d naa.id --perennially-reserved=true
for example:
# esxcli storage core device setconfig -d naa.6000144000000010a0245b40d047369b --perennially-reserved=true
# esxcli storage core device setconfig -d naa.6000144000000010a0245b40d047369e --perennially-reserved=true

Or just run this script to build the commands for you:
_____________________________________________________________________________
esxcfg-scsidevs -m > /tmp/esxcfg-scsidevs-m-naaID_DataStore.txt
esxcli storage core device list | grep -C12 "Reserved: false" | \
grep "Path: /vmfs/devices" | cut -d. -f2 | while read naaID ; do
#echo "checking ${naaID} for datastore" ;
grep ${naaID} /tmp/esxcfg-scsidevs-m-naaID_DataStore.txt >/dev/null
RC=$?
if [ ${RC} != 0 ] ; then
echo -n "${naaID} does not have datastore, assuming RDM, "
echo "which needs perennial reservation set with command shown:"
echo
echo -n "esxcli storage core device setconfig -d "
echo "naa.${naaID} --perennially-reserved=true"
echo
echo
else
DataStore=`grep ${naaID} /tmp/esxcfg-scsidevs-m-naaID_DataStore.txt |\
awk '{print $1,$5}' | awk '{print $2}'`
echo -n "NAAID ${naaID} has datastore ${DataStore}, so does not need "
echo "perennial reservation changed"
fi
done
__________________________________________________________________________

Example run of script follows:

60060160b1b02d00559a83248cc0e311 does not have datastore, assuming RDM, which needs perennial reservation set with command shown:

esxcli storage core device setconfig -d  naa.60060160b1b02d00559a83248cc0e311 --perennially-reserved=true

NAAID 6000144000000010a0245b40d047339f has datastore SAN_DS1, so does not need perennial reservation changed

References:
http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1016106