Last active
November 3, 2018 21:22
-
-
Save ioggstream/591094441aa86b62b697 to your computer and use it in GitHub Desktop.
PowerPath Udev Environment setter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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