[lxc-devel] [lxd/master] Fix base image tracking

stgraber on Github lxc-bot at linuxcontainers.org
Thu Mar 2 21:59:43 UTC 2017


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 370 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170302/a40777a4/attachment.bin>
-------------- next part --------------
From 8ced01c7105317dbc3f0eb72d506f5baa4491bac Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Thu, 2 Mar 2017 16:52:58 -0500
Subject: [PATCH] Fix base image tracking
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Closes #2999

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/container.go       |  3 +++
 lxd/containers_post.go | 13 +++----------
 2 files changed, 6 insertions(+), 10 deletions(-)

diff --git a/lxd/container.go b/lxd/container.go
index bf8d297..06939e5 100644
--- a/lxd/container.go
+++ b/lxd/container.go
@@ -545,6 +545,9 @@ func containerCreateFromImage(d *Daemon, args containerArgs, hash string) (conta
 		}
 	}
 
+	// Set the BaseImage field (regardless of previous value)
+	args.BaseImage = hash
+
 	// Create the container
 	c, err := containerCreateInternal(d, args)
 	if err != nil {
diff --git a/lxd/containers_post.go b/lxd/containers_post.go
index 3425818..96918d4 100644
--- a/lxd/containers_post.go
+++ b/lxd/containers_post.go
@@ -48,8 +48,8 @@ func createFromImage(d *Daemon, req *api.ContainersPost) Response {
 
 		var image *api.Image
 
-		for _, hash := range hashes {
-			_, img, err := dbImageGet(d.db, hash, false, true)
+		for _, imageHash := range hashes {
+			_, img, err := dbImageGet(d.db, imageHash, false, true)
 			if err != nil {
 				continue
 			}
@@ -84,7 +84,6 @@ func createFromImage(d *Daemon, req *api.ContainersPost) Response {
 
 	run := func(op *operation) error {
 		args := containerArgs{
-			BaseImage: hash,
 			Config:    req.Config,
 			Ctype:     cTypeRegular,
 			Devices:   req.Devices,
@@ -94,10 +93,6 @@ func createFromImage(d *Daemon, req *api.ContainersPost) Response {
 		}
 
 		if req.Source.Server != "" {
-			if args.Profiles == nil {
-				args.Profiles = []string{"default"}
-			}
-
 			hash, err = d.ImageDownload(
 				op, req.Source.Server, req.Source.Protocol, req.Source.Certificate, req.Source.Secret,
 				hash, true, daemonConfig["images.auto_update_cached"].GetBool(), "")
@@ -111,14 +106,12 @@ func createFromImage(d *Daemon, req *api.ContainersPost) Response {
 			return err
 		}
 
-		hash = imgInfo.Fingerprint
-
 		args.Architecture, err = osarch.ArchitectureId(imgInfo.Architecture)
 		if err != nil {
 			return err
 		}
 
-		_, err = containerCreateFromImage(d, args, hash)
+		_, err = containerCreateFromImage(d, args, imgInfo.Fingerprint)
 		return err
 	}
 


More information about the lxc-devel mailing list