SOLVED
I pulled in the json storage-extra
section from the commissioning output. It successfully applied to the machine:
json_layout = json.loads('{"layout":{<trimmed for brevity>}')
storage_layout = maasserver.storage_custom.get_storage_layout(json_layout)
maasserver.storage_custom.apply_layout_to_machine(storage_layout, machine)
I then edited one of the partitions in the json-extra, to purposefully exceed disk space. When I try to apply the new json using the steps above, I get this error:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/snap/maas/27405/lib/python3.10/site-packages/maasserver/storage_custom.py", line 164, in apply_layout_to_machine
apply_layout(machine, entry, block_devices)
File "/snap/maas/27405/lib/python3.10/site-packages/maasserver/storage_custom.py", line 346, in _apply_layout_partition
block_devices[entry.name] = models.Partition.objects.create(
File "/snap/maas/27405/usr/lib/python3/dist-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/snap/maas/27405/usr/lib/python3/dist-packages/django/db/models/query.py", line 453, in create
obj.save(force_insert=True, using=self.db)
File "/snap/maas/27405/lib/python3.10/site-packages/maasserver/models/partition.py", line 226, in save
return super().save(*args, **kwargs)
File "/snap/maas/27405/lib/python3.10/site-packages/maasserver/models/cleansave.py", line 46, in save
self.full_clean(exclude=exclude_clean_fields, validate_unique=False)
File "/snap/maas/27405/usr/lib/python3/dist-packages/django/db/models/base.py", line 1251, in full_clean
raise ValidationError(errors)
django.core.exceptions.ValidationError: {'size': ['Partition cannot be saved; not enough free space on the block device.']}
For my purposes, this is exactly what I want. I want to fiddle with the disk sizes to remove wasted/extra blocks, without a costly recommissioning step.
If there’s a way to do this from the API, or from the web GUI, please let me know. Otherwise, I consider this solved.