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:
parent
c22797ffdb
commit
eb658f5495
9 changed files with 100 additions and 30 deletions
|
|
@ -45,6 +45,9 @@ type Arch interface {
|
||||||
// Returns an object representing a given image format for this architecture,
|
// Returns an object representing a given image format for this architecture,
|
||||||
// on this distro.
|
// on this distro.
|
||||||
GetImageType(imageType string) (ImageType, error)
|
GetImageType(imageType string) (ImageType, error)
|
||||||
|
|
||||||
|
// Returns the parent distro
|
||||||
|
Distro() Distro
|
||||||
}
|
}
|
||||||
|
|
||||||
// An ImageType represents a given distribution's support for a given Image Type
|
// 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.
|
// Returns the name of the image type.
|
||||||
Name() string
|
Name() string
|
||||||
|
|
||||||
|
// Returns the parent architecture
|
||||||
|
Arch() Arch
|
||||||
|
|
||||||
// Returns the canonical filename for the image type.
|
// Returns the canonical filename for the image type.
|
||||||
Filename() string
|
Filename() string
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,14 @@ type imageType struct {
|
||||||
assembler func(uefi bool, size uint64) *osbuild.Assembler
|
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 {
|
func (d *Fedora30) ListArches() []string {
|
||||||
archs := make([]string, 0, len(d.arches))
|
archs := make([]string, 0, len(d.arches))
|
||||||
for name := range d.arches {
|
for name := range d.arches {
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,14 @@ type arch struct {
|
||||||
imageTypes map[string]imageType
|
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 {
|
func (d *Fedora31) ListArches() []string {
|
||||||
archs := make([]string, 0, len(d.arches))
|
archs := make([]string, 0, len(d.arches))
|
||||||
for name := range d.arches {
|
for name := range d.arches {
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,14 @@ type imageType struct {
|
||||||
assembler func(uefi bool, size uint64) *osbuild.Assembler
|
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 {
|
func (d *Fedora32) ListArches() []string {
|
||||||
archs := make([]string, 0, len(d.arches))
|
archs := make([]string, 0, len(d.arches))
|
||||||
for name := range d.arches {
|
for name := range d.arches {
|
||||||
|
|
|
||||||
|
|
@ -14,75 +14,83 @@ const modulePlatformID = "platform:f30"
|
||||||
|
|
||||||
type FedoraTestDistro struct{}
|
type FedoraTestDistro struct{}
|
||||||
|
|
||||||
type fedoraTestDistroArch struct {
|
type arch struct {
|
||||||
name string
|
name string
|
||||||
distro *FedoraTestDistro
|
distro *FedoraTestDistro
|
||||||
}
|
}
|
||||||
|
|
||||||
type fedoraTestDistroImageType struct {
|
type imageType struct {
|
||||||
name string
|
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 {
|
func (d *FedoraTestDistro) ListArches() []string {
|
||||||
return []string{"x86_64"}
|
return []string{"x86_64"}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *FedoraTestDistro) GetArch(arch string) (distro.Arch, error) {
|
func (d *FedoraTestDistro) GetArch(name string) (distro.Arch, error) {
|
||||||
if arch != "x86_64" {
|
if name != "x86_64" {
|
||||||
return nil, errors.New("invalid architecture: " + arch)
|
return nil, errors.New("invalid architecture: " + name)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &fedoraTestDistroArch{
|
return &arch{
|
||||||
name: arch,
|
name: name,
|
||||||
distro: d,
|
distro: d,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *fedoraTestDistroArch) Name() string {
|
func (a *arch) Name() string {
|
||||||
return a.name
|
return a.name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *fedoraTestDistroArch) ListImageTypes() []string {
|
func (a *arch) ListImageTypes() []string {
|
||||||
return []string{"qcow2"}
|
return []string{"qcow2"}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *fedoraTestDistroArch) GetImageType(imageType string) (distro.ImageType, error) {
|
func (a *arch) GetImageType(name string) (distro.ImageType, error) {
|
||||||
if imageType != "qcow2" {
|
if name != "qcow2" {
|
||||||
return nil, errors.New("invalid image type: " + imageType)
|
return nil, errors.New("invalid image type: " + name)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &fedoraTestDistroImageType{
|
return &imageType{
|
||||||
name: imageType,
|
name: name,
|
||||||
arch: a,
|
arch: a,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *fedoraTestDistroImageType) Name() string {
|
func (t *imageType) Name() string {
|
||||||
return t.name
|
return t.name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *fedoraTestDistroImageType) Filename() string {
|
func (t *imageType) Filename() string {
|
||||||
return "test.img"
|
return "test.img"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *fedoraTestDistroImageType) MIMEType() string {
|
func (t *imageType) MIMEType() string {
|
||||||
return "application/x-test"
|
return "application/x-test"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *fedoraTestDistroImageType) Size(size uint64) uint64 {
|
func (t *imageType) Size(size uint64) uint64 {
|
||||||
return size
|
return size
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *fedoraTestDistroImageType) BasePackages() ([]string, []string) {
|
func (t *imageType) BasePackages() ([]string, []string) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *fedoraTestDistroImageType) BuildPackages() []string {
|
func (t *imageType) BuildPackages() []string {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *fedoraTestDistroImageType) Manifest(c *blueprint.Customizations,
|
func (t *imageType) Manifest(c *blueprint.Customizations,
|
||||||
repos []rpmmd.RepoConfig,
|
repos []rpmmd.RepoConfig,
|
||||||
packageSpecs,
|
packageSpecs,
|
||||||
buildPackageSpecs []rpmmd.PackageSpec,
|
buildPackageSpecs []rpmmd.PackageSpec,
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,14 @@ type rhel81ImageType struct {
|
||||||
imageType *imageType
|
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 {
|
func (d *RHEL81) ListArches() []string {
|
||||||
archs := make([]string, 0, len(d.arches))
|
archs := make([]string, 0, len(d.arches))
|
||||||
for name := range d.arches {
|
for name := range d.arches {
|
||||||
|
|
@ -66,14 +74,14 @@ func (d *RHEL81) ListArches() []string {
|
||||||
return archs
|
return archs
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *RHEL81) GetArch(arch string) (distro.Arch, error) {
|
func (d *RHEL81) GetArch(name string) (distro.Arch, error) {
|
||||||
a, exists := d.arches[arch]
|
a, exists := d.arches[name]
|
||||||
if !exists {
|
if !exists {
|
||||||
return nil, errors.New("invalid architecture: " + arch)
|
return nil, errors.New("invalid architecture: " + name)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &rhel81Arch{
|
return &rhel81Arch{
|
||||||
name: arch,
|
name: name,
|
||||||
distro: d,
|
distro: d,
|
||||||
arch: &a,
|
arch: &a,
|
||||||
}, nil
|
}, nil
|
||||||
|
|
@ -92,14 +100,14 @@ func (a *rhel81Arch) ListImageTypes() []string {
|
||||||
return formats
|
return formats
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *rhel81Arch) GetImageType(imageType string) (distro.ImageType, error) {
|
func (a *rhel81Arch) GetImageType(name string) (distro.ImageType, error) {
|
||||||
t, exists := a.distro.imageTypes[imageType]
|
t, exists := a.distro.imageTypes[name]
|
||||||
if !exists {
|
if !exists {
|
||||||
return nil, errors.New("invalid image type: " + imageType)
|
return nil, errors.New("invalid image type: " + name)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &rhel81ImageType{
|
return &rhel81ImageType{
|
||||||
name: imageType,
|
name: name,
|
||||||
arch: a,
|
arch: a,
|
||||||
imageType: &t,
|
imageType: &t,
|
||||||
}, nil
|
}, nil
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,14 @@ type rhel82ImageType struct {
|
||||||
imageType *imageType
|
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 {
|
func (d *RHEL82) ListArches() []string {
|
||||||
archs := make([]string, 0, len(d.arches))
|
archs := make([]string, 0, len(d.arches))
|
||||||
for name := range d.arches {
|
for name := range d.arches {
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,14 @@ type rhel83ImageType struct {
|
||||||
imageType *imageType
|
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 {
|
func (d *RHEL83) ListArches() []string {
|
||||||
archs := make([]string, 0, len(d.arches))
|
archs := make([]string, 0, len(d.arches))
|
||||||
for name := range d.arches {
|
for name := range d.arches {
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,14 @@ func (d *TestDistro) ListArches() []string {
|
||||||
return []string{"test_arch"}
|
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) {
|
func (d *TestDistro) GetArch(arch string) (distro.Arch, error) {
|
||||||
if arch != "test_arch" {
|
if arch != "test_arch" {
|
||||||
return nil, errors.New("invalid arch: " + arch)
|
return nil, errors.New("invalid arch: " + arch)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue