[lxc-devel] [distrobuilder/master] definition: Set ArchitectureMapped, ArchitectureKernel and Architectu…
stgraber on Github
lxc-bot at linuxcontainers.org
Wed Mar 21 19:25:30 UTC 2018
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 382 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180321/59c6a39e/attachment.bin>
-------------- next part --------------
From 0d314ab5753dcc3006090d12f779053058d609d1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Wed, 21 Mar 2018 15:25:09 -0400
Subject: [PATCH] definition: Set ArchitectureMapped, ArchitectureKernel and
ArchitecturePersonality
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
image/lxd.go | 2 +-
shared/definition.go | 49 ++++++++++++++++++++++++++++++++++++-----------
sources/alpine-http.go | 4 ++--
sources/archlinux-http.go | 6 +++---
sources/centos-http.go | 4 ++--
sources/debootstrap.go | 4 ++--
sources/ubuntu-http.go | 4 ++--
7 files changed, 50 insertions(+), 23 deletions(-)
diff --git a/image/lxd.go b/image/lxd.go
index a818b89..ac8b21d 100644
--- a/image/lxd.go
+++ b/image/lxd.go
@@ -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
diff --git a/shared/definition.go b/shared/definition.go
index 023db6a..26ea871 100644
--- a/shared/definition.go
+++ b/shared/definition.go
@@ -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
}
diff --git a/sources/alpine-http.go b/sources/alpine-http.go
index e52354c..5be670b 100644
--- a/sources/alpine-http.go
+++ b/sources/alpine-http.go
@@ -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 {
diff --git a/sources/archlinux-http.go b/sources/archlinux-http.go
index df96cea..59fdc79 100644
--- a/sources/archlinux-http.go
+++ b/sources/archlinux-http.go
@@ -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))
}
diff --git a/sources/centos-http.go b/sources/centos-http.go
index 9c3f7c3..43779ef 100644
--- a/sources/centos-http.go
+++ b/sources/centos-http.go
@@ -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")
}
diff --git a/sources/debootstrap.go b/sources/debootstrap.go
index 468bda0..f7fbb14 100644
--- a/sources/debootstrap.go
+++ b/sources/debootstrap.go
@@ -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 {
diff --git a/sources/ubuntu-http.go b/sources/ubuntu-http.go
index 14cb6e2..1e7d71f 100644
--- a/sources/ubuntu-http.go
+++ b/sources/ubuntu-http.go
@@ -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")
}
More information about the lxc-devel
mailing list