Skip to content

Instantly share code, notes, and snippets.

@ioggstream
Last active November 3, 2018 21:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ioggstream/591094441aa86b62b697 to your computer and use it in GitHub Desktop.
Save ioggstream/591094441aa86b62b697 to your computer and use it in GitHub Desktop.
PowerPath Udev Environment setter
#!/usr/bin/python
#
# script to be used in udev IMPORT{program} directive
# for naming emcpower devices
#
# Sample output is the following
# #/usr/local/bin/powermt_udev.py /dev/emcpowera
# POWERPATH_WWID=0000FFFF12345678BBBB0000
# POWERPATH_VNXNAME=MY_SPOOL_SPACE
#
# You need at least two udev rules: the first one sets the udev environment
# which cannot be set inline
# KERNEL=="emcpower*", IMPORT{program}="/usr/local/bin/powermt_udev.py %k"
#
# Then the following rules to rename the device
# KERNEL=="emcpower*", ENV{POWERPATH_VNXNAME}=="MY_SPOOL_SPACE", NAME="spool", OWNER="root", GROUP="root", MODE="0600"
import os
from sys import argv
from re import split
device = os.path.basename(argv[1])
for l in os.popen("/sbin/powermt display dev=%s"%device).readlines():
if not 'Logical' in l:
continue
_, _, _, wwid, _, vnxname = split(r'[= \[\]]', l)[:6]
print("POWERPATH_WWID=%s\nPOWERPATH_VNXNAME=%s" % (wwid, vnxname))
exit(0)
exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment