stages/sfdisk: use device instead of file
Instead of operating directly on a file, which was previously specified by `filename`, operate on a device. This is more flexible since a file can be accessed via a loop back device; but the inverse is obviously not true, like other devices can not be accessed via a plain file. Therefore, re-factor the stage to use a device and adapt the existing test (`fedora-ostree-image`).
This commit is contained in:
parent
386ff713cc
commit
98133add11
3 changed files with 77 additions and 56 deletions
|
|
@ -4,7 +4,6 @@ Partition a target using sfdisk(8)
|
|||
"""
|
||||
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
|
@ -12,53 +11,62 @@ import sys
|
|||
import osbuild.api
|
||||
|
||||
|
||||
SCHEMA = """
|
||||
"additionalProperties": false,
|
||||
"required": ["filename", "label", "uuid"],
|
||||
"properties": {
|
||||
"filename": {
|
||||
"description": "Image filename",
|
||||
"type": "string"
|
||||
},
|
||||
"uuid": {
|
||||
"description": "UUID for the disk image's partition table",
|
||||
"type": "string"
|
||||
},
|
||||
"label": {
|
||||
"description": "The type of the partition table",
|
||||
"type": "string",
|
||||
"enum": ["mbr", "dos", "gpt"]
|
||||
},
|
||||
"partitions": {
|
||||
"description": "Partition layout ",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"description": "Description of one partition",
|
||||
SCHEMA_2 = r"""
|
||||
"devices": {
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"required": ["device"],
|
||||
"properties": {
|
||||
"device": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"bootable": {
|
||||
"description": "Mark the partition as bootable (dos)",
|
||||
"type": "boolean"
|
||||
},
|
||||
"name": {
|
||||
"description": "The partition name (GPT)",
|
||||
"type": "string"
|
||||
},
|
||||
"size": {
|
||||
"description": "The size of this partition",
|
||||
"type": "integer"
|
||||
},
|
||||
"start": {
|
||||
"description": "The start offset of this partition",
|
||||
"type": "integer"
|
||||
},
|
||||
"type": {
|
||||
"description": "The partition type (UUID or identifier)",
|
||||
"type": "string"
|
||||
},
|
||||
"uuid": {
|
||||
"description": "UUID of the partition (GPT)",
|
||||
"type": "string"
|
||||
"additionalProperties": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"options": {
|
||||
"additionalProperties": false,
|
||||
"required": ["label", "uuid"],
|
||||
"properties": {
|
||||
"uuid": {
|
||||
"description": "UUID for the disk image's partition table",
|
||||
"type": "string"
|
||||
},
|
||||
"label": {
|
||||
"description": "The type of the partition table",
|
||||
"type": "string",
|
||||
"enum": ["mbr", "dos", "gpt"]
|
||||
},
|
||||
"partitions": {
|
||||
"description": "Partition layout ",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"description": "Description of one partition",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"bootable": {
|
||||
"description": "Mark the partition as bootable (dos)",
|
||||
"type": "boolean"
|
||||
},
|
||||
"name": {
|
||||
"description": "The partition name (GPT)",
|
||||
"type": "string"
|
||||
},
|
||||
"size": {
|
||||
"description": "The size of this partition",
|
||||
"type": "integer"
|
||||
},
|
||||
"start": {
|
||||
"description": "The start offset of this partition",
|
||||
"type": "integer"
|
||||
},
|
||||
"type": {
|
||||
"description": "The partition type (UUID or identifier)",
|
||||
"type": "string"
|
||||
},
|
||||
"uuid": {
|
||||
"description": "UUID of the partition (GPT)",
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -173,25 +181,24 @@ def partition_from_json(js) -> Partition:
|
|||
return p
|
||||
|
||||
|
||||
def main(tree, options):
|
||||
filename = options["filename"]
|
||||
def main(devices, options):
|
||||
device = devices["device"]["path"]
|
||||
|
||||
ptuuid = options["uuid"]
|
||||
pttype = options["label"]
|
||||
partitions = options.get("partitions")
|
||||
|
||||
dest = os.path.join(tree, filename.lstrip("/"))
|
||||
|
||||
parts = [partition_from_json(p) for p in partitions]
|
||||
pt = PartitionTable(pttype, ptuuid, parts)
|
||||
|
||||
pt.write_to(dest)
|
||||
pt.write_to(device)
|
||||
|
||||
subprocess.run(["sfdisk", "--json", dest],
|
||||
subprocess.run(["sfdisk", "--json", device],
|
||||
encoding='utf-8',
|
||||
check=False)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
args = osbuild.api.arguments()
|
||||
ret = main(args["tree"], args["options"])
|
||||
ret = main(args["devices"], args["options"])
|
||||
sys.exit(ret)
|
||||
|
|
|
|||
|
|
@ -840,8 +840,15 @@
|
|||
},
|
||||
{
|
||||
"type": "org.osbuild.sfdisk",
|
||||
"devices": {
|
||||
"device": {
|
||||
"type": "org.osbuild.loopback",
|
||||
"options": {
|
||||
"filename": "disk.img"
|
||||
}
|
||||
}
|
||||
},
|
||||
"options": {
|
||||
"filename": "disk.img",
|
||||
"uuid": "D209C89E-EA5E-4FBD-B161-B461CCE297E0",
|
||||
"label": "gpt",
|
||||
"partitions": [
|
||||
|
|
|
|||
|
|
@ -171,8 +171,15 @@
|
|||
},
|
||||
{
|
||||
"type": "org.osbuild.sfdisk",
|
||||
"devices": {
|
||||
"device": {
|
||||
"type": "org.osbuild.loopback",
|
||||
"options": {
|
||||
"filename": "disk.img"
|
||||
}
|
||||
}
|
||||
},
|
||||
"options": {
|
||||
"filename": "disk.img",
|
||||
"uuid": "D209C89E-EA5E-4FBD-B161-B461CCE297E0",
|
||||
"label": "gpt",
|
||||
"partitions": [
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue