Merge pull request #75 from stgraber/master

definition: Set ArchitectureMapped, ArchitectureKernel and Architectu…
This commit is contained in:
Thomas Hipp 2018-03-21 20:40:58 +01:00 committed by GitHub
commit 2e325862b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 50 additions and 23 deletions

View File

@ -114,7 +114,7 @@ func (l *LXDImage) createMetadata() error {
l.Metadata.Architecture = l.definition.Image.Architecture
l.Metadata.CreationDate = time.Now().UTC().Unix()
l.Metadata.Properties["architecture"] = l.definition.Image.MappedArchitecture
l.Metadata.Properties["architecture"] = l.definition.Image.ArchitectureMapped
l.Metadata.Properties["os"] = l.definition.Image.Distribution
l.Metadata.Properties["release"] = l.definition.Image.Release
l.Metadata.Properties["variant"] = l.definition.Image.Variant

View File

@ -9,6 +9,7 @@ import (
"time"
lxd "github.com/lxc/lxd/shared"
lxdarch "github.com/lxc/lxd/shared/osarch"
"github.com/lxc/lxd/shared"
)
@ -24,15 +25,19 @@ type DefinitionPackages struct {
// A DefinitionImage represents the image.
type DefinitionImage struct {
Description string `yaml:"description"`
Distribution string `yaml:"distribution"`
Release string `yaml:"release,omitempty"`
Architecture string `yaml:"architecture,omitempty"`
Expiry string `yaml:"expiry,omitempty"`
Variant string `yaml:"variant,omitempty"`
Name string `yaml:"name,omitempty"`
Serial string `yaml:"serial,omitempty"`
MappedArchitecture string `yaml:"mapped_architecture,omitempty"`
Description string `yaml:"description"`
Distribution string `yaml:"distribution"`
Release string `yaml:"release,omitempty"`
Architecture string `yaml:"architecture,omitempty"`
Expiry string `yaml:"expiry,omitempty"`
Variant string `yaml:"variant,omitempty"`
Name string `yaml:"name,omitempty"`
Serial string `yaml:"serial,omitempty"`
// Internal fields (YAML input ignored)
ArchitectureMapped string `yaml:"architecture_mapped,omitempty"`
ArchitectureKernel string `yaml:"architecture_kernel,omitempty"`
ArchitecturePersonality string `yaml:"architecture_personality,omitempty"`
}
// A DefinitionSource specifies the download type and location
@ -224,12 +229,34 @@ func (d *Definition) Validate() error {
}
}
var err error
d.Image.MappedArchitecture, err = d.getMappedArchitecture()
// Mapped architecture (distro name)
archMapped, err := d.getMappedArchitecture()
if err != nil {
return err
}
d.Image.ArchitectureMapped = archMapped
// Kernel architecture and personality
archID, err := lxdarch.ArchitectureId(d.Image.Architecture)
if err != nil {
return err
}
archName, err := lxdarch.ArchitectureName(archID)
if err != nil {
return err
}
d.Image.ArchitectureMapped = archName
archPersonality, err := lxdarch.ArchitecturePersonality(archID)
if err != nil {
return err
}
d.Image.ArchitecturePersonality = archPersonality
return nil
}

View File

@ -24,10 +24,10 @@ func NewAlpineLinuxHTTP() *AlpineLinuxHTTP {
// Run downloads an Alpine Linux mini root filesystem.
func (s *AlpineLinuxHTTP) Run(definition shared.Definition, rootfsDir string) error {
fname := fmt.Sprintf("alpine-minirootfs-%s-%s.tar.gz", definition.Image.Release,
definition.Image.MappedArchitecture)
definition.Image.ArchitectureMapped)
tarball := fmt.Sprintf("%s/v%s/releases/%s/%s", definition.Source.URL,
strings.Join(strings.Split(definition.Image.Release, ".")[0:2], "."),
definition.Image.MappedArchitecture, fname)
definition.Image.ArchitectureMapped, fname)
url, err := url.Parse(tarball)
if err != nil {

View File

@ -24,7 +24,7 @@ func NewArchLinuxHTTP() *ArchLinuxHTTP {
// Run downloads an Arch Linux tarball.
func (s *ArchLinuxHTTP) Run(definition shared.Definition, rootfsDir string) error {
fname := fmt.Sprintf("archlinux-bootstrap-%s-%s.tar.gz",
definition.Image.Release, definition.Image.MappedArchitecture)
definition.Image.Release, definition.Image.ArchitectureMapped)
tarball := fmt.Sprintf("%s/%s/%s", definition.Source.URL,
definition.Image.Release, fname)
@ -68,7 +68,7 @@ func (s *ArchLinuxHTTP) Run(definition shared.Definition, rootfsDir string) erro
// Move everything inside 'root.x86_64' (which was is the tarball) to its
// parent directory
files, err := filepath.Glob(fmt.Sprintf("%s/*", filepath.Join(rootfsDir,
"root", definition.Image.MappedArchitecture)))
"root", definition.Image.ArchitectureMapped)))
if err != nil {
return err
}
@ -81,5 +81,5 @@ func (s *ArchLinuxHTTP) Run(definition shared.Definition, rootfsDir string) erro
}
return os.RemoveAll(filepath.Join(rootfsDir, "root",
definition.Image.MappedArchitecture))
definition.Image.ArchitectureMapped))
}

View File

@ -30,10 +30,10 @@ func NewCentOSHTTP() *CentOSHTTP {
func (s *CentOSHTTP) Run(definition shared.Definition, rootfsDir string) error {
baseURL := fmt.Sprintf("%s/%s/isos/%s/", definition.Source.URL,
strings.Split(definition.Image.Release, ".")[0],
definition.Image.MappedArchitecture)
definition.Image.ArchitectureMapped)
s.fname = getRelease(definition.Source.URL, definition.Image.Release,
definition.Source.Variant, definition.Image.MappedArchitecture)
definition.Source.Variant, definition.Image.ArchitectureMapped)
if s.fname == "" {
return fmt.Errorf("Couldn't get name of iso")
}

View File

@ -27,8 +27,8 @@ func (s *Debootstrap) Run(definition shared.Definition, rootfsDir string) error
args = append(args, "--variant", definition.Source.Variant)
}
if definition.Image.MappedArchitecture != "" {
args = append(args, "--arch", definition.Image.MappedArchitecture)
if definition.Image.ArchitectureMapped != "" {
args = append(args, "--arch", definition.Image.ArchitectureMapped)
}
if len(definition.Source.Keys) > 0 {

View File

@ -34,11 +34,11 @@ func (s *UbuntuHTTP) Run(definition shared.Definition, rootfsDir string) error {
if strings.ContainsAny(definition.Image.Release, "0123456789") {
s.fname = fmt.Sprintf("ubuntu-base-%s-base-%s.tar.gz",
definition.Image.Release, definition.Image.MappedArchitecture)
definition.Image.Release, definition.Image.ArchitectureMapped)
} else {
// if release is non-numerical, find the latest release
s.fname = getLatestRelease(definition.Source.URL,
definition.Image.Release, definition.Image.MappedArchitecture)
definition.Image.Release, definition.Image.ArchitectureMapped)
if s.fname == "" {
return fmt.Errorf("Couldn't find latest release")
}