From ceba83dccae353dfc715d2ed852a4f343fd9d660 Mon Sep 17 00:00:00 2001 From: Achilleas Koutsou Date: Wed, 7 Jul 2021 19:29:36 +0200 Subject: [PATCH] distro/rhel85: introduce the vmdk image type --- internal/distro/rhel85/distro.go | 16 ++++++++++- internal/distro/rhel85/package_sets.go | 13 +++++++++ internal/distro/rhel85/pipelines.go | 37 +++++++++++++++++++++++++ internal/distro/rhel85/stage_options.go | 4 +++ internal/osbuild2/qemu_stage.go | 13 ++++++++- 5 files changed, 81 insertions(+), 2 deletions(-) diff --git a/internal/distro/rhel85/distro.go b/internal/distro/rhel85/distro.go index 04ed4e9f5..d0dcd77c2 100644 --- a/internal/distro/rhel85/distro.go +++ b/internal/distro/rhel85/distro.go @@ -461,6 +461,20 @@ func newDistro(name, modulePlatformID, ostreeRef string) distro.Distro { exports: []string{"vhd"}, } + vmdkImgType := imageType{ + name: "vmdk", + filename: "disk.vmdk", + mimeType: "application/x-vmdk", + packageSets: map[string]rpmmd.PackageSet{ + "packages": vmdkCommonPackageSet(), + }, + kernelOptions: "ro net.ifnames=0", + bootable: true, + defaultSize: 4 * GigaByte, + pipelines: vmdkPipelines, + exports: []string{"vmdk"}, + } + tarImgType := imageType{ name: "tar", filename: "root.tar.xz", @@ -520,7 +534,7 @@ func newDistro(name, modulePlatformID, ostreeRef string) distro.Distro { exports: []string{"container"}, } - x86_64.addImageTypes(qcow2ImgType, vhdImgType, tarImgType, tarInstallerImgTypeX86_64, edgeCommitImgTypeX86_64, edgeInstallerImgTypeX86_64, edgeOCIImgTypeX86_64) + x86_64.addImageTypes(qcow2ImgType, vhdImgType, vmdkImgType, tarImgType, tarInstallerImgTypeX86_64, edgeCommitImgTypeX86_64, edgeInstallerImgTypeX86_64, edgeOCIImgTypeX86_64) aarch64.addImageTypes(qcow2ImgType, tarImgType, edgeCommitImgTypeAarch64, edgeOCIImgTypeAarch64) ppc64le.addImageTypes(qcow2ImgType, tarImgType) s390x.addImageTypes(qcow2ImgType, tarImgType) diff --git a/internal/distro/rhel85/package_sets.go b/internal/distro/rhel85/package_sets.go index e1ec78ea7..ce52d8972 100644 --- a/internal/distro/rhel85/package_sets.go +++ b/internal/distro/rhel85/package_sets.go @@ -171,6 +171,19 @@ func vhdCommonPackageSet() rpmmd.PackageSet { } } +func vmdkCommonPackageSet() rpmmd.PackageSet { + return rpmmd.PackageSet{ + Include: []string{ + "@core", "chrony", "firewalld", "langpacks-en", "open-vm-tools", + "selinux-policy-targeted", + }, + Exclude: []string{ + "dracut-config-rescue", "rng-tools", + }, + } + +} + // edge commit OS package set func edgeCommitCommonPackageSet() rpmmd.PackageSet { return rpmmd.PackageSet{ diff --git a/internal/distro/rhel85/pipelines.go b/internal/distro/rhel85/pipelines.go index 831d22984..05e8e43bb 100644 --- a/internal/distro/rhel85/pipelines.go +++ b/internal/distro/rhel85/pipelines.go @@ -98,6 +98,43 @@ func vhdPipelines(t *imageType, customizations *blueprint.Customizations, option return pipelines, nil } +func vmdkPipelines(t *imageType, customizations *blueprint.Customizations, options distro.ImageOptions, repos []rpmmd.RepoConfig, packageSetSpecs map[string][]rpmmd.PackageSpec, rng *rand.Rand) ([]osbuild.Pipeline, error) { + pipelines := make([]osbuild.Pipeline, 0) + pipelines = append(pipelines, *buildPipeline(repos, packageSetSpecs["build"])) + treePipeline, err := osPipeline(repos, packageSetSpecs["packages"], customizations, options, t.enabledServices, t.disabledServices, t.defaultTarget) + if err != nil { + return nil, err + } + if options.Subscription != nil { + commands := []string{ + fmt.Sprintf("/usr/sbin/subscription-manager register --org=%d --activationkey=%s --serverurl %s --baseurl %s", options.Subscription.Organization, options.Subscription.ActivationKey, options.Subscription.ServerUrl, options.Subscription.BaseUrl), + } + if options.Subscription.Insights { + commands = append(commands, "/usr/bin/insights-client --register") + } + treePipeline.AddStage(osbuild.NewFirstBootStage(&osbuild.FirstBootStageOptions{ + Commands: commands, + WaitForNetwork: true, + }, + )) + } + partitionTable := defaultPartitionTable(options, t.arch, rng) + treePipeline.AddStage(osbuild.NewFSTabStage(partitionTable.FSTabStageOptionsV2())) + treePipeline.AddStage(osbuild.NewGRUB2Stage(grub2StageOptions(&partitionTable, t.kernelOptions, customizations.GetKernel(), packageSetSpecs["packages"], t.arch.uefi, t.arch.legacy))) + pipelines = append(pipelines, *treePipeline) + + diskfile := "disk.img" + imagePipeline := liveImagePipeline(treePipeline.Name, diskfile, &partitionTable, t.arch.legacy) + pipelines = append(pipelines, *imagePipeline) + if err != nil { + return nil, err + } + + qemuPipeline := qemuPipeline(imagePipeline.Name, diskfile, t.filename, "vmdk", "") + pipelines = append(pipelines, *qemuPipeline) + return pipelines, nil +} + func tarPipelines(t *imageType, customizations *blueprint.Customizations, options distro.ImageOptions, repos []rpmmd.RepoConfig, packageSetSpecs map[string][]rpmmd.PackageSpec, rng *rand.Rand) ([]osbuild.Pipeline, error) { pipelines := make([]osbuild.Pipeline, 0) pipelines = append(pipelines, *buildPipeline(repos, packageSetSpecs["build"])) diff --git a/internal/distro/rhel85/stage_options.go b/internal/distro/rhel85/stage_options.go index cbd0a6d7b..a30bae545 100644 --- a/internal/distro/rhel85/stage_options.go +++ b/internal/distro/rhel85/stage_options.go @@ -477,6 +477,10 @@ func qemuStageOptions(filename, format, compat string) *osbuild.QEMUStageOptions options = osbuild.VPCOptions{ Type: "vpc", } + case "vmdk": + options = osbuild.VMDKOptions{ + Type: "vmdk", + } default: panic("unknown format in qemu stage: " + format) } diff --git a/internal/osbuild2/qemu_stage.go b/internal/osbuild2/qemu_stage.go index 4b1d85ea9..be863cdbe 100644 --- a/internal/osbuild2/qemu_stage.go +++ b/internal/osbuild2/qemu_stage.go @@ -18,6 +18,8 @@ type QEMUStageOptions struct { Format QEMUFormatOptions `json:"format"` } +func (QEMUStageOptions) isStageOptions() {} + type QEMUFormatOptions interface { isQEMUFormatOptions() } @@ -39,7 +41,12 @@ type VPCOptions struct { func (VPCOptions) isQEMUFormatOptions() {} -func (QEMUStageOptions) isStageOptions() {} +type VMDKOptions struct { + // The type of the format must be 'vpc' + Type string `json:"type"` +} + +func (VMDKOptions) isQEMUFormatOptions() {} type QEMUStageInputs struct { Image *QEMUStageInput `json:"image"` @@ -88,6 +95,10 @@ func (options QEMUStageOptions) MarshalJSON() ([]byte, error) { if o.Type != "vpc" { return nil, fmt.Errorf("invalid format type %q for vpc options", o.Type) } + case VMDKOptions: + if o.Type != "vmdk" { + return nil, fmt.Errorf("invalid format type %q for vmdk options", o.Type) + } default: return nil, fmt.Errorf("unknown format options in QEMU stage: %#v", options.Format) }