distro/fedora: deduplicate Fedora distribution structs
These are just super-simple to construct using a small helper. It would be great if we can make `distro.go` totally version-agnostic but that's something for the future. Signed-off-by: Ondřej Budai <ondrej@budai.cz>
This commit is contained in:
parent
c88d0255da
commit
ff8af88a24
1 changed files with 26 additions and 32 deletions
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/osbuild/osbuild-composer/internal/blueprint"
|
"github.com/osbuild/osbuild-composer/internal/blueprint"
|
||||||
|
|
@ -38,10 +39,6 @@ const (
|
||||||
// blueprint package set name
|
// blueprint package set name
|
||||||
blueprintPkgsKey = "blueprint"
|
blueprintPkgsKey = "blueprint"
|
||||||
|
|
||||||
// Fedora distribution
|
|
||||||
fedora35Distribution = "fedora-35"
|
|
||||||
fedora36Distribution = "fedora-36"
|
|
||||||
|
|
||||||
//Kernel options for ami, qcow2, openstack, vhd and vmdk types
|
//Kernel options for ami, qcow2, openstack, vhd and vmdk types
|
||||||
defaultKernelOptions = "ro no_timer_check console=ttyS0,115200n8 biosdevname=0 net.ifnames=0"
|
defaultKernelOptions = "ro no_timer_check console=ttyS0,115200n8 biosdevname=0 net.ifnames=0"
|
||||||
)
|
)
|
||||||
|
|
@ -305,30 +302,18 @@ var defaultDistroImageConfig = &distro.ImageConfig{
|
||||||
Locale: common.StringToPtr("en_US"),
|
Locale: common.StringToPtr("en_US"),
|
||||||
}
|
}
|
||||||
|
|
||||||
// distribution objects without the arches > image types
|
func getDistro(version int) distribution {
|
||||||
var distroMap = map[string]distribution{
|
return distribution{
|
||||||
fedora35Distribution: {
|
name: fmt.Sprintf("fedora-%d", version),
|
||||||
name: fedora35Distribution,
|
|
||||||
product: "Fedora",
|
product: "Fedora",
|
||||||
osVersion: "35",
|
osVersion: strconv.Itoa(version),
|
||||||
releaseVersion: "35",
|
releaseVersion: strconv.Itoa(version),
|
||||||
modulePlatformID: "platform:f35",
|
modulePlatformID: fmt.Sprintf("platform:f%d", version),
|
||||||
ostreeRefTmpl: "fedora/35/%s/iot",
|
ostreeRefTmpl: fmt.Sprintf("fedora/%d/%%s/iot", version),
|
||||||
isolabelTmpl: "Fedora-35-BaseOS-%s",
|
isolabelTmpl: fmt.Sprintf("Fedora-%d-BaseOS-%%s", version),
|
||||||
runner: &runner.Fedora{Version: 35},
|
runner: &runner.Fedora{Version: uint64(version)},
|
||||||
defaultImageConfig: defaultDistroImageConfig,
|
defaultImageConfig: defaultDistroImageConfig,
|
||||||
},
|
}
|
||||||
fedora36Distribution: {
|
|
||||||
name: fedora36Distribution,
|
|
||||||
product: "Fedora",
|
|
||||||
osVersion: "36",
|
|
||||||
releaseVersion: "36",
|
|
||||||
modulePlatformID: "platform:f36",
|
|
||||||
ostreeRefTmpl: "fedora/36/%s/iot",
|
|
||||||
isolabelTmpl: "Fedora-36-BaseOS-%s",
|
|
||||||
runner: &runner.Fedora{Version: 36},
|
|
||||||
defaultImageConfig: defaultDistroImageConfig,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *distribution) Name() string {
|
func (d *distribution) Name() string {
|
||||||
|
|
@ -722,20 +707,29 @@ func (t *imageType) checkOptions(customizations *blueprint.Customizations, optio
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHostDistro(name, modulePlatformID, ostreeRef string) distro.Distro {
|
func NewHostDistro(name, modulePlatformID, ostreeRef string) distro.Distro {
|
||||||
return newDistro(name)
|
parts := strings.Split(name, "-")
|
||||||
|
if len(parts) != 2 || parts[0] != "fedora" {
|
||||||
|
panic("invalid distro name: " + name)
|
||||||
|
}
|
||||||
|
|
||||||
|
version, err := strconv.Atoi(parts[1])
|
||||||
|
if err != nil {
|
||||||
|
panic("invalid distro version: " + name + ": " + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
return newDistro(version)
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new distro object, defining the supported architectures and image types
|
// New creates a new distro object, defining the supported architectures and image types
|
||||||
func NewF35() distro.Distro {
|
func NewF35() distro.Distro {
|
||||||
return newDistro(fedora35Distribution)
|
return newDistro(35)
|
||||||
}
|
}
|
||||||
func NewF36() distro.Distro {
|
func NewF36() distro.Distro {
|
||||||
return newDistro(fedora36Distribution)
|
return newDistro(36)
|
||||||
}
|
}
|
||||||
|
|
||||||
func newDistro(distroName string) distro.Distro {
|
func newDistro(version int) distro.Distro {
|
||||||
|
rd := getDistro(version)
|
||||||
rd := distroMap[distroName]
|
|
||||||
|
|
||||||
// Architecture definitions
|
// Architecture definitions
|
||||||
x86_64 := architecture{
|
x86_64 := architecture{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue