Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix datastore creation issues with vmfs6 storage layout #256

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 17 additions & 31 deletions vmware-esxi/maas/storage-esxi
Original file line number Diff line number Diff line change
Expand Up @@ -295,34 +295,13 @@ def get_starting_sector(path):
return starting_sector + 1


def get_ending_sector(blocksize, starting_sector, size):
"""Return the ending sector from the size."""
if isinstance(size, int):
return size
elif isinstance(size, float):
if int(size) != size:
raise ValueError(
"'%s': resulted in non-integer (%s)" % ((size, int(size)))
)
elif not isinstance(size, str):
raise TypeError("cannot convert type %s ('%s')." % (type(size), size))

size = size.upper()
# Any size can end with B
if size.endswith("B"):
size = size[:-1]

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

mplier = "B"
for m in mpliers:
if size.endswith(m):
size = size[0 : -len(m)]
mplier = m
break

return int(starting_sector + float(size) * mpliers[mplier] / blocksize)
def get_ending_sector(path):
"""Return the ending sector from the disk path."""
ending_sector = 0
part_info = check_output(["partedUtil", "get", path]).decode().splitlines()[0]
ending_sector = int(part_info.split()[3]) - int(part_info.split()[0])

return ending_sector

def partition_disks(disks, partitions):
"""Partition all disks."""
Expand All @@ -335,9 +314,14 @@ def partition_disks(disks, partitions):
# It needs to be recreated. On VMware ESXi 7.0 the offical installer
# defines 5 partitions and skips partitions 2-4. Partition 8 is the
# datastore which can be extended.
#
# When vmfs6 storage layout is selected, MAAS nonetheless sets
# partition 3 for datastores on grub_device.
#
# On non-grub-device disks, the datastore remains partition 1.
if disk.get("grub_device") and (
(is_esxi67() and part["number"] != 3 and part["number"] <= 9)
or (has_esx_os_data() and part["number"] <= 7)
or (has_esx_os_data() and part["number"] != 3)
):
continue
elif not disk.get("partitioned"):
Expand All @@ -348,11 +332,13 @@ def partition_disks(disks, partitions):
check_call(["partedUtil", "mklabel", disk["path"], disk["ptable"]])
disk["partitioned"] = True

info("Creating partition %s on %s" % (part["number"], disk["path"]))
starting_sector = get_starting_sector(disk["path"])
ending_sector = get_ending_sector(
disk["blocksize"], starting_sector, part["size"]
ending_sector = get_ending_sector(disk["path"])
info(
"Creating partition %s on %s (Start: %s End: %s)"
% (part["number"], disk["path"], starting_sector, ending_sector)
)

check_call(
[
"partedUtil",
Expand Down
Loading