Created
June 24, 2013 16:14
-
-
Save vicenteg/5851286 to your computer and use it in GitHub Desktop.
Rename external storage so that JBOD disks are renamed in the form: jbod-S-D/d where S == S-card slot, D == JBOD internal device (0,1,2,3), d == disk number in the internal device.
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 | |
import re, sys | |
show_storage_external_brief = sys.stdin.readlines() | |
pattern = re.compile(r"^\s+(?P<name>\S+)\s+(?P<device>\S+)\s+(?P<slot>\d+)") | |
slots_seen = { } | |
# trying out what happens when we sort the JBOD WWNs | |
for line in sorted(show_storage_external_brief): | |
m = pattern.match( line ) | |
if m: | |
matches = m.groupdict() | |
slot = matches['slot'] | |
device = matches['device'] | |
name = matches['name'] | |
if slot in slots_seen: | |
slots_seen[slot] += 1 | |
else: | |
slots_seen[slot] = 0 | |
# default name is the device ID. If that's the case, print the command to change it. | |
if name == device: | |
print "storage external jbod{}-{} device {} slot {}".format(slot, slots_seen[slot], device, slot) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment