distro: add Distro() and Arch() accessors

These return the parent object of the Arch and ImageType, respectively.

Not a functional change.

Signed-off-by: Tom Gundersen <teg@jklm.no>
This commit is contained in:
Tom Gundersen 2020-05-11 22:47:54 +02:00
parent c22797ffdb
commit eb658f5495
9 changed files with 100 additions and 30 deletions

View file

@ -45,6 +45,9 @@ type Arch interface {
// Returns an object representing a given image format for this architecture,
// on this distro.
GetImageType(imageType string) (ImageType, error)
// Returns the parent distro
Distro() Distro
}
// An ImageType represents a given distribution's support for a given Image Type
@ -53,6 +56,9 @@ type ImageType interface {
// Returns the name of the image type.
Name() string
// Returns the parent architecture
Arch() Arch
// Returns the canonical filename for the image type.
Filename() string

View file

@ -48,6 +48,14 @@ type imageType struct {
assembler func(uefi bool, size uint64) *osbuild.Assembler
}
func (a *arch) Distro() distro.Distro {
return a.distro
}
func (t *imageType) Arch() distro.Arch {
return t.arch
}
func (d *Fedora30) ListArches() []string {
archs := make([]string, 0, len(d.arches))
for name := range d.arches {

View file

@ -47,6 +47,14 @@ type arch struct {
imageTypes map[string]imageType
}
func (a *arch) Distro() distro.Distro {
return a.distro
}
func (t *imageType) Arch() distro.Arch {
return t.arch
}
func (d *Fedora31) ListArches() []string {
archs := make([]string, 0, len(d.arches))
for name := range d.arches {

View file

@ -48,6 +48,14 @@ type imageType struct {
assembler func(uefi bool, size uint64) *osbuild.Assembler
}
func (a *arch) Distro() distro.Distro {
return a.distro
}
func (t *imageType) Arch() distro.Arch {
return t.arch
}
func (d *Fedora32) ListArches() []string {
archs := make([]string, 0, len(d.arches))
for name := range d.arches {

View file

@ -14,75 +14,83 @@ const modulePlatformID = "platform:f30"
type FedoraTestDistro struct{}
type fedoraTestDistroArch struct {
type arch struct {
name string
distro *FedoraTestDistro
}
type fedoraTestDistroImageType struct {
type imageType struct {
name string
arch *fedoraTestDistroArch
arch *arch
}
func (a *arch) Distro() distro.Distro {
return a.distro
}
func (t *imageType) Arch() distro.Arch {
return t.arch
}
func (d *FedoraTestDistro) ListArches() []string {
return []string{"x86_64"}
}
func (d *FedoraTestDistro) GetArch(arch string) (distro.Arch, error) {
if arch != "x86_64" {
return nil, errors.New("invalid architecture: " + arch)
func (d *FedoraTestDistro) GetArch(name string) (distro.Arch, error) {
if name != "x86_64" {
return nil, errors.New("invalid architecture: " + name)
}
return &fedoraTestDistroArch{
name: arch,
return &arch{
name: name,
distro: d,
}, nil
}
func (a *fedoraTestDistroArch) Name() string {
func (a *arch) Name() string {
return a.name
}
func (a *fedoraTestDistroArch) ListImageTypes() []string {
func (a *arch) ListImageTypes() []string {
return []string{"qcow2"}
}
func (a *fedoraTestDistroArch) GetImageType(imageType string) (distro.ImageType, error) {
if imageType != "qcow2" {
return nil, errors.New("invalid image type: " + imageType)
func (a *arch) GetImageType(name string) (distro.ImageType, error) {
if name != "qcow2" {
return nil, errors.New("invalid image type: " + name)
}
return &fedoraTestDistroImageType{
name: imageType,
return &imageType{
name: name,
arch: a,
}, nil
}
func (t *fedoraTestDistroImageType) Name() string {
func (t *imageType) Name() string {
return t.name
}
func (t *fedoraTestDistroImageType) Filename() string {
func (t *imageType) Filename() string {
return "test.img"
}
func (t *fedoraTestDistroImageType) MIMEType() string {
func (t *imageType) MIMEType() string {
return "application/x-test"
}
func (t *fedoraTestDistroImageType) Size(size uint64) uint64 {
func (t *imageType) Size(size uint64) uint64 {
return size
}
func (t *fedoraTestDistroImageType) BasePackages() ([]string, []string) {
func (t *imageType) BasePackages() ([]string, []string) {
return nil, nil
}
func (t *fedoraTestDistroImageType) BuildPackages() []string {
func (t *imageType) BuildPackages() []string {
return nil
}
func (t *fedoraTestDistroImageType) Manifest(c *blueprint.Customizations,
func (t *imageType) Manifest(c *blueprint.Customizations,
repos []rpmmd.RepoConfig,
packageSpecs,
buildPackageSpecs []rpmmd.PackageSpec,

View file

@ -57,6 +57,14 @@ type rhel81ImageType struct {
imageType *imageType
}
func (a *rhel81Arch) Distro() distro.Distro {
return a.distro
}
func (t *rhel81ImageType) Arch() distro.Arch {
return t.arch
}
func (d *RHEL81) ListArches() []string {
archs := make([]string, 0, len(d.arches))
for name := range d.arches {
@ -66,14 +74,14 @@ func (d *RHEL81) ListArches() []string {
return archs
}
func (d *RHEL81) GetArch(arch string) (distro.Arch, error) {
a, exists := d.arches[arch]
func (d *RHEL81) GetArch(name string) (distro.Arch, error) {
a, exists := d.arches[name]
if !exists {
return nil, errors.New("invalid architecture: " + arch)
return nil, errors.New("invalid architecture: " + name)
}
return &rhel81Arch{
name: arch,
name: name,
distro: d,
arch: &a,
}, nil
@ -92,14 +100,14 @@ func (a *rhel81Arch) ListImageTypes() []string {
return formats
}
func (a *rhel81Arch) GetImageType(imageType string) (distro.ImageType, error) {
t, exists := a.distro.imageTypes[imageType]
func (a *rhel81Arch) GetImageType(name string) (distro.ImageType, error) {
t, exists := a.distro.imageTypes[name]
if !exists {
return nil, errors.New("invalid image type: " + imageType)
return nil, errors.New("invalid image type: " + name)
}
return &rhel81ImageType{
name: imageType,
name: name,
arch: a,
imageType: &t,
}, nil

View file

@ -57,6 +57,14 @@ type rhel82ImageType struct {
imageType *imageType
}
func (a *rhel82Arch) Distro() distro.Distro {
return a.distro
}
func (t *rhel82ImageType) Arch() distro.Arch {
return t.arch
}
func (d *RHEL82) ListArches() []string {
archs := make([]string, 0, len(d.arches))
for name := range d.arches {

View file

@ -57,6 +57,14 @@ type rhel83ImageType struct {
imageType *imageType
}
func (a *rhel83Arch) Distro() distro.Distro {
return a.distro
}
func (t *rhel83ImageType) Arch() distro.Arch {
return t.arch
}
func (d *RHEL83) ListArches() []string {
archs := make([]string, 0, len(d.arches))
for name := range d.arches {

View file

@ -20,6 +20,14 @@ func (d *TestDistro) ListArches() []string {
return []string{"test_arch"}
}
func (a *testArch) Distro() distro.Distro {
return &TestDistro{}
}
func (t *testImageType) Arch() distro.Arch {
return &testArch{}
}
func (d *TestDistro) GetArch(arch string) (distro.Arch, error) {
if arch != "test_arch" {
return nil, errors.New("invalid arch: " + arch)