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

@ -263,8 +263,8 @@ Example:
Defining partition layouts for disk images:
It is possbile to define a partition layout via `mpp-define-image`. The defined layout
is actually written to a temporary sparse file and read back via `sfdisk`, so that all
It is possbile to define partition layouts via `mpp-define-images`. The defined layouts
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`
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.
@ -273,23 +273,28 @@ Example:
```
...
"mpp-define-image": {
"size": "10737418240",
"table": {
"uuid": "D209C89E-EA5E-4FBD-B161-B461CCE297E0",
"label": "gpt",
"partitions": [
{
"id": "bios-boot",
"start": 2048,
"size": 2048,
"type": "21686148-6449-6E6F-744E-656564454649",
"bootable": true,
"uuid": "FAC7F1FB-3E8D-4137-A512-961DE09A5549"
"attrs": [ 60 ]
},
...
}
"mpp-define-images": [
{
"id": "image",
"size": "10737418240",
"table": {
"uuid": "D209C89E-EA5E-4FBD-B161-B461CCE297E0",
"label": "gpt",
"partitions": [
{
"id": "bios-boot",
"start": 2048,
"size": 2048,
"type": "21686148-6449-6E6F-744E-656564454649",
"bootable": true,
"uuid": "FAC7F1FB-3E8D-4137-A512-961DE09A5549",
"attrs": [ 60 ]
},
...
]
}
}
]
...
```
@ -1016,7 +1021,7 @@ class ManifestFile:
raise ValueError(f"Unknown manfest version {version}")
m.process_imports()
m.process_partition()
m.process_partitions()
return m
@ -1303,16 +1308,23 @@ class ManifestFile:
def process_format(self):
self._process_format(self.root)
def process_partition(self):
desc = self.get_mpp_node(self.root, "define-image")
def process_partitions(self):
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
self._process_format(desc)
name = desc.get("id", "image")
self.vars[name] = Image.from_dict(desc)
for image in images:
self._process_format(image)
name = image["id"]
self.vars[name] = Image.from_dict(image)
# pylint: disable=no-self-use
def get_pipeline_name(self, node):