Skip to content

Commit

Permalink
Fix ESXi disk serial parsing (#112)
Browse files Browse the repository at this point in the history
fixes #33
  • Loading branch information
alexsander-souza authored May 9, 2023
1 parent 55febbd commit 8a5b78d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
14 changes: 11 additions & 3 deletions vmware-esxi/maas/storage-esxi
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ def get_disks():
r"Revis:\s+(?P<revis>.*)\s*$"
)

serial_regex = re.compile(
r"^(?P<name>\S+?)__+(?P<model>\S+?)__+(?P<serial>\S+?)__+$"
)

for line in output.splitlines():
if not line.startswith(" " * 3):
# Each section starts with the device name, all fields are defined
Expand All @@ -101,15 +105,17 @@ def get_disks():
disks.append(disk)
other_names = False
name = line.strip()
m = serial_regex.search(name)
disk = {
"name": name,
"other_names": [],
"blocksize": disk_block_sizes.get(name, 0),
"serial": m.group("serial") if m else "",
}
elif disk:
if other_names and not line.startswith(" " * 6):
# Other names is a list which contains the serial. Entries must
# start with 6 spaces.
# Other names is a list of alias.
# Entries must start with 6 spaces.
other_names = False
line = line.strip()
if line.startswith("Size"):
Expand Down Expand Up @@ -139,6 +145,8 @@ def get_disk(disks, model, serial):
# udev will sometimes replace a space in the model name with an
# underscore.
if disk["model"] == model or disk["model"].replace(" ", "_") == model:
if serial == disk["serial"]:
return disk
for other_name in disk["other_names"]:
# VMware doesn't provide the exact serial number. It provides
# a list of other names, one of which contains the serial
Expand Down Expand Up @@ -255,7 +263,7 @@ def get_ending_sector(blocksize, starting_sector, size):
if size.endswith("B"):
size = size[:-1]

mpliers = {"B": 1, "K": 2 ** 10, "M": 2 ** 20, "G": 2 ** 30, "T": 2 ** 40}
mpliers = {"B": 1, "K": 2**10, "M": 2**20, "G": 2**30, "T": 2**40}

mplier = "B"
for m in mpliers:
Expand Down
7 changes: 4 additions & 3 deletions vmware-esxi/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
black==21.5b1
isort==5.8.0
flake8==3.9.2
black==23.1.0
isort==5.12.0
flake8==6.0.0
click==8.1.3

0 comments on commit 8a5b78d

Please sign in to comment.