distro: add ListArchs() to Distro interface

Similar to ListImageTypes() add a helper to enumerate the supported
architectures.

Signed-off-by: Tom Gundersen <teg@jklm.no>
This commit is contained in:
Tom Gundersen 2020-03-24 13:46:19 +01:00 committed by msehnout
parent 4a7519807e
commit f903601ec4
8 changed files with 57 additions and 0 deletions

View file

@ -24,6 +24,10 @@ type Distro interface {
// for modularity support.
ModulePlatformID() string
// Returns a sorted list of the names of the architectures this distro
// supports.
ListArchs() []string
// Returns an object representing the given architecture as support
// by this distro.
GetArch(arch string) (Arch, error)

View file

@ -56,6 +56,15 @@ type fedora30ImageType struct {
imageType *imageType
}
func (d *Fedora30) ListArchs() []string {
archs := make([]string, 0, len(d.arches))
for name := range d.arches {
archs = append(archs, name)
}
sort.Strings(archs)
return archs
}
func (d *Fedora30) GetArch(arch string) (distro.Arch, error) {
a, exists := d.arches[arch]
if !exists {

View file

@ -56,6 +56,15 @@ type fedora31ImageType struct {
imageType *imageType
}
func (d *Fedora31) ListArchs() []string {
archs := make([]string, 0, len(d.arches))
for name := range d.arches {
archs = append(archs, name)
}
sort.Strings(archs)
return archs
}
func (d *Fedora31) GetArch(arch string) (distro.Arch, error) {
a, exists := d.arches[arch]
if !exists {

View file

@ -56,6 +56,15 @@ type fedora32ImageType struct {
imageType *imageType
}
func (d *Fedora32) ListArchs() []string {
archs := make([]string, 0, len(d.arches))
for name := range d.arches {
archs = append(archs, name)
}
sort.Strings(archs)
return archs
}
func (d *Fedora32) GetArch(arch string) (distro.Arch, error) {
a, exists := d.arches[arch]
if !exists {

View file

@ -24,6 +24,10 @@ type fedoraTestDistroImageType struct {
arch *fedoraTestDistroArch
}
func (d *FedoraTestDistro) ListArchs() []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)

View file

@ -57,6 +57,15 @@ type rhel81ImageType struct {
imageType *imageType
}
func (d *RHEL81) ListArchs() []string {
archs := make([]string, 0, len(d.arches))
for name := range d.arches {
archs = append(archs, name)
}
sort.Strings(archs)
return archs
}
func (d *RHEL81) GetArch(arch string) (distro.Arch, error) {
a, exists := d.arches[arch]
if !exists {

View file

@ -57,6 +57,15 @@ type rhel82ImageType struct {
imageType *imageType
}
func (d *RHEL82) ListArchs() []string {
archs := make([]string, 0, len(d.arches))
for name := range d.arches {
archs = append(archs, name)
}
sort.Strings(archs)
return archs
}
func (d *RHEL82) GetArch(arch string) (distro.Arch, error) {
a, exists := d.arches[arch]
if !exists {

View file

@ -16,6 +16,10 @@ type testImageType struct{}
const name = "test-distro"
const modulePlatformID = "platform:test"
func (d *TestDistro) ListArchs() []string {
return []string{"test_arch"}
}
func (d *TestDistro) GetArch(arch string) (distro.Arch, error) {
if arch != "test_arch" {
return nil, errors.New("invalid arch: " + arch)