tools/osbuild-mpp: support defining multiple image layouts

Right now you can only define a single image, lets add mpp-define-images
and accept a list.
This commit is contained in:
Dusty Mabe 2023-11-21 21:06:05 -05:00 committed by Simon de Vlieger
parent b824e1e57a
commit 2e1f6e2553
2 changed files with 68 additions and 56 deletions

View file

@ -6,35 +6,35 @@ mpp-vars:
boot_size_mb: 384 boot_size_mb: 384
root_size_mb: 2048 root_size_mb: 2048
sector_size: 512 sector_size: 512
mpp-define-image: mpp-define-images:
id: image - id: image
size: size:
mpp-format-string: "{disk_size_gb * 1024 * 1024 * 1024}" mpp-format-string: "{disk_size_gb * 1024 * 1024 * 1024}"
table: table:
uuid: 00000000-0000-4000-a000-000000000001 uuid: 00000000-0000-4000-a000-000000000001
label: gpt label: gpt
partitions: partitions:
- id: BIOS-BOOT - id: BIOS-BOOT
type: 21686148-6449-6E6F-744E-656564454649 type: 21686148-6449-6E6F-744E-656564454649
bootable: true bootable: true
uuid: FAC7F1FB-3E8D-4137-A512-961DE09A5549 uuid: FAC7F1FB-3E8D-4137-A512-961DE09A5549
size: size:
mpp-format-int: "{bios_boot_size_mb * 1024 * 1024 / sector_size}" mpp-format-int: "{bios_boot_size_mb * 1024 * 1024 / sector_size}"
- id: EFI-SYSTEM - id: EFI-SYSTEM
type: C12A7328-F81F-11D2-BA4B-00A0C93EC93B type: C12A7328-F81F-11D2-BA4B-00A0C93EC93B
uuid: 68B2905B-DF3E-4FB3-80FA-49D1E773AA33 uuid: 68B2905B-DF3E-4FB3-80FA-49D1E773AA33
size: size:
mpp-format-int: "{efi_system_size_mb * 1024 * 1024 / sector_size}" mpp-format-int: "{efi_system_size_mb * 1024 * 1024 / sector_size}"
- id: boot - id: boot
type: 0FC63DAF-8483-4772-8E79-3D69D8477DE4 type: 0FC63DAF-8483-4772-8E79-3D69D8477DE4
uuid: 61B2905B-DF3E-4FB3-80FA-49D1E773AA32 uuid: 61B2905B-DF3E-4FB3-80FA-49D1E773AA32
size: size:
mpp-format-int: "{boot_size_mb * 1024 * 1024 / sector_size}" mpp-format-int: "{boot_size_mb * 1024 * 1024 / sector_size}"
- id: root - id: root
type: 0FC63DAF-8483-4772-8E79-3D69D8477DE4 type: 0FC63DAF-8483-4772-8E79-3D69D8477DE4
uuid: CA7D7CCB-63ED-4C53-861C-1742536059CC uuid: CA7D7CCB-63ED-4C53-861C-1742536059CC
size: size:
mpp-format-int: "{root_size_mb * 1024 * 1024 / sector_size}" mpp-format-int: "{root_size_mb * 1024 * 1024 / sector_size}"
pipelines: pipelines:
- mpp-import-pipelines: - mpp-import-pipelines:
path: fedora-vars.ipp.yaml path: fedora-vars.ipp.yaml

View file

@ -263,8 +263,8 @@ Example:
Defining partition layouts for disk images: Defining partition layouts for disk images:
It is possbile to define a partition layout via `mpp-define-image`. The defined layout It is possbile to define partition layouts via `mpp-define-images`. The defined layouts
is actually written to a temporary sparse file and read back via `sfdisk`, so that all are actually written to a temporary sparse file and read back via `sfdisk`, so that all
partition data like `size` and `start` include actual padding and such. The `image` partition data like `size` and `start` include actual padding and such. The `image`
variable will be defined with `size` and `layout` keys, the latter containing the variable will be defined with `size` and `layout` keys, the latter containing the
partition layout data. It can be accessed via the "String expansion" explained above. partition layout data. It can be accessed via the "String expansion" explained above.
@ -273,23 +273,28 @@ Example:
``` ```
... ...
"mpp-define-image": { "mpp-define-images": [
"size": "10737418240", {
"table": { "id": "image",
"uuid": "D209C89E-EA5E-4FBD-B161-B461CCE297E0", "size": "10737418240",
"label": "gpt", "table": {
"partitions": [ "uuid": "D209C89E-EA5E-4FBD-B161-B461CCE297E0",
{ "label": "gpt",
"id": "bios-boot", "partitions": [
"start": 2048, {
"size": 2048, "id": "bios-boot",
"type": "21686148-6449-6E6F-744E-656564454649", "start": 2048,
"bootable": true, "size": 2048,
"uuid": "FAC7F1FB-3E8D-4137-A512-961DE09A5549" "type": "21686148-6449-6E6F-744E-656564454649",
"attrs": [ 60 ] "bootable": true,
}, "uuid": "FAC7F1FB-3E8D-4137-A512-961DE09A5549",
... "attrs": [ 60 ]
} },
...
]
}
}
]
... ...
``` ```
@ -1016,7 +1021,7 @@ class ManifestFile:
raise ValueError(f"Unknown manfest version {version}") raise ValueError(f"Unknown manfest version {version}")
m.process_imports() m.process_imports()
m.process_partition() m.process_partitions()
return m return m
@ -1303,16 +1308,23 @@ class ManifestFile:
def process_format(self): def process_format(self):
self._process_format(self.root) self._process_format(self.root)
def process_partition(self): def process_partitions(self):
desc = self.get_mpp_node(self.root, "define-image") images = self.get_mpp_node(self.root, "define-images") or []
if not desc: # Backwards compat for mpp-define-image (no list)
image = self.get_mpp_node(self.root, "define-image")
if image:
if id not in image:
image['id'] = "image"
images.append(image)
if len(images) == 0:
return return
self._process_format(desc) for image in images:
self._process_format(image)
name = desc.get("id", "image") name = image["id"]
self.vars[name] = Image.from_dict(desc) self.vars[name] = Image.from_dict(image)
# pylint: disable=no-self-use # pylint: disable=no-self-use
def get_pipeline_name(self, node): def get_pipeline_name(self, node):