osbuild2: use aliased type for QEMU format, instead of string

Define a new aliased type `QEMUFormat` for the format type used by the
osbuild2 QEMU stage and define constants for all allowed values.

Use QEMU format type constants in all relevant places, instead of string
literals. Not using string literals minimizes the room for making a
typo.
This commit is contained in:
Tomas Hozza 2022-04-06 09:18:17 +02:00 committed by Tomáš Hozza
parent e30fa53c50
commit 0e512e97d2
10 changed files with 71 additions and 61 deletions

View file

@ -35,7 +35,7 @@ func qcow2Pipelines(t *imageType, customizations *blueprint.Customizations, opti
imagePipeline := liveImagePipeline(treePipeline.Name, diskfile, partitionTable, t.arch, kernelVer)
pipelines = append(pipelines, *imagePipeline)
qemuPipeline := qemuPipeline(imagePipeline.Name, diskfile, t.filename, "qcow2", "1.1")
qemuPipeline := qemuPipeline(imagePipeline.Name, diskfile, t.filename, osbuild.QEMUFormatQCOW2, "1.1")
pipelines = append(pipelines, *qemuPipeline)
return pipelines, nil
@ -72,7 +72,7 @@ func vhdPipelines(t *imageType, customizations *blueprint.Customizations, option
imagePipeline := liveImagePipeline(treePipeline.Name, diskfile, partitionTable, t.arch, kernelVer)
pipelines = append(pipelines, *imagePipeline)
qemuPipeline := qemuPipeline(imagePipeline.Name, diskfile, t.filename, "vpc", "")
qemuPipeline := qemuPipeline(imagePipeline.Name, diskfile, t.filename, osbuild.QEMUFormatVPC, "")
pipelines = append(pipelines, *qemuPipeline)
return pipelines, nil
}
@ -97,7 +97,7 @@ func vmdkPipelines(t *imageType, customizations *blueprint.Customizations, optio
imagePipeline := liveImagePipeline(treePipeline.Name, diskfile, partitionTable, t.arch, kernelVer)
pipelines = append(pipelines, *imagePipeline)
qemuPipeline := qemuPipeline(imagePipeline.Name, diskfile, t.filename, "vmdk", "")
qemuPipeline := qemuPipeline(imagePipeline.Name, diskfile, t.filename, osbuild.QEMUFormatVMDK, "")
pipelines = append(pipelines, *qemuPipeline)
return pipelines, nil
}
@ -122,7 +122,7 @@ func openstackPipelines(t *imageType, customizations *blueprint.Customizations,
imagePipeline := liveImagePipeline(treePipeline.Name, diskfile, partitionTable, t.arch, kernelVer)
pipelines = append(pipelines, *imagePipeline)
qemuPipeline := qemuPipeline(imagePipeline.Name, diskfile, t.filename, "qcow2", "")
qemuPipeline := qemuPipeline(imagePipeline.Name, diskfile, t.filename, osbuild.QEMUFormatQCOW2, "")
pipelines = append(pipelines, *qemuPipeline)
return pipelines, nil
}
@ -1025,9 +1025,9 @@ func xzArchivePipeline(inputPipelineName, inputFilename, outputFilename string)
return p
}
func qemuPipeline(inputPipelineName, inputFilename, outputFilename, format, qcow2Compat string) *osbuild.Pipeline {
func qemuPipeline(inputPipelineName, inputFilename, outputFilename string, format osbuild.QEMUFormat, qcow2Compat string) *osbuild.Pipeline {
p := new(osbuild.Pipeline)
p.Name = format
p.Name = string(format)
p.Build = "name:build"
qemuStage := osbuild.NewQEMUStage(qemuStageOptions(outputFilename, format, qcow2Compat), osbuild.NewQemuStagePipelineFilesInputs(inputPipelineName, inputFilename))

View file

@ -278,21 +278,21 @@ func xorrisofsStageOptions(filename, isolabel, arch string, isolinux bool) *osbu
return options
}
func qemuStageOptions(filename, format, compat string) *osbuild.QEMUStageOptions {
func qemuStageOptions(filename string, format osbuild.QEMUFormat, compat string) *osbuild.QEMUStageOptions {
var options osbuild.QEMUFormatOptions
switch format {
case "qcow2":
case osbuild.QEMUFormatQCOW2:
options = osbuild.Qcow2Options{
Type: "qcow2",
Type: format,
Compat: compat,
}
case "vpc":
case osbuild.QEMUFormatVPC:
options = osbuild.VPCOptions{
Type: "vpc",
Type: format,
}
case "vmdk":
case osbuild.QEMUFormatVMDK:
options = osbuild.VMDKOptions{
Type: "vmdk",
Type: format,
}
default:
panic("unknown format in qemu stage: " + format)