[lxc-devel] [lxd/master] Bugfixes
stgraber on Github
lxc-bot at linuxcontainers.org
Fri Mar 10 01:45:49 UTC 2017
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 301 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170310/4d177fba/attachment.bin>
-------------- next part --------------
From f9ca1a74938164f17603b66f30d53801457f7ba5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Thu, 9 Mar 2017 20:36:50 -0500
Subject: [PATCH 1/3] lxc: Properly clear transfer stats on error
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>
---
lxc/image.go | 1 +
lxc/launch.go | 6 ++++++
2 files changed, 7 insertions(+)
diff --git a/lxc/image.go b/lxc/image.go
index b996f32..69af5b7 100644
--- a/lxc/image.go
+++ b/lxc/image.go
@@ -249,6 +249,7 @@ func (c *imageCmd) run(config *lxd.Config, args []string) error {
if err == nil {
progress.Done(i18n.G("Image copied successfully!"))
}
+ progress.Done("")
return err
diff --git a/lxc/launch.go b/lxc/launch.go
index 2a5b35e..0689706 100644
--- a/lxc/launch.go
+++ b/lxc/launch.go
@@ -111,11 +111,13 @@ func (c *launchCmd) run(config *lxd.Config, args []string) error {
if name == "" {
op, err := resp.MetadataAsOperation()
if err != nil {
+ progress.Done("")
return fmt.Errorf(i18n.G("didn't get any affected image, container or snapshot from server"))
}
containers, ok := op.Resources["containers"]
if !ok || len(containers) == 0 {
+ progress.Done("")
return fmt.Errorf(i18n.G("didn't get any affected image, container or snapshot from server"))
}
@@ -123,20 +125,24 @@ func (c *launchCmd) run(config *lxd.Config, args []string) error {
toScan := strings.Replace(containers[0], "/", " ", -1)
count, err := fmt.Sscanf(toScan, " %s containers %s", &restVersion, &name)
if err != nil {
+ progress.Done("")
return err
}
if count != 2 {
+ progress.Done("")
return fmt.Errorf(i18n.G("bad number of things scanned from image, container or snapshot"))
}
if restVersion != version.APIVersion {
+ progress.Done("")
return fmt.Errorf(i18n.G("got bad version"))
}
}
fmt.Printf(i18n.G("Creating %s")+"\n", name)
if err = d.WaitForSuccess(resp.Operation); err != nil {
+ progress.Done("")
return err
}
progress.Done("")
From c92e29571660d1c1b6793e82609144887d8328c9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Thu, 9 Mar 2017 20:32:05 -0500
Subject: [PATCH 2/3] zfs: Create a volume entry for re-used images
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>
---
lxd/storage_zfs.go | 1 +
1 file changed, 1 insertion(+)
diff --git a/lxd/storage_zfs.go b/lxd/storage_zfs.go
index c76cc07..1d3cc86 100644
--- a/lxd/storage_zfs.go
+++ b/lxd/storage_zfs.go
@@ -1296,6 +1296,7 @@ func (s *storageZfs) ImageCreate(fingerprint string) error {
}
revert = false
+ subrevert = false
return nil
}
From 1ea0a2064b3628d76e6b6028c938467e50c512bb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Thu, 9 Mar 2017 14:36:46 -0500
Subject: [PATCH 3/3] shared/simplestreams: Export image file list
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>
---
shared/simplestreams/simplestreams.go | 66 +++++++++++++++++++++++++----------
1 file changed, 47 insertions(+), 19 deletions(-)
diff --git a/shared/simplestreams/simplestreams.go b/shared/simplestreams/simplestreams.go
index e4251e8..0615fe0 100644
--- a/shared/simplestreams/simplestreams.go
+++ b/shared/simplestreams/simplestreams.go
@@ -10,6 +10,7 @@ import (
"os"
"path/filepath"
"sort"
+ "strconv"
"strings"
"time"
@@ -137,8 +138,10 @@ func (s *SimpleStreamsManifest) ToLXD() ([]api.Image, map[string][][]string) {
metaPath := meta.Path
metaHash := meta.HashSha256
+ metaSize := meta.Size
rootfsPath := ""
rootfsHash := ""
+ rootfsSize := int64(0)
fields := strings.Split(meta.Path, "/")
filename := fields[len(fields)-1]
size := meta.Size
@@ -153,6 +156,7 @@ func (s *SimpleStreamsManifest) ToLXD() ([]api.Image, map[string][][]string) {
size += rootSquash.Size
rootfsPath = rootSquash.Path
rootfsHash = rootSquash.HashSha256
+ rootfsSize = rootSquash.Size
} else {
if meta.LXDHashSha256RootXz != "" {
fingerprint = meta.LXDHashSha256RootXz
@@ -162,6 +166,7 @@ func (s *SimpleStreamsManifest) ToLXD() ([]api.Image, map[string][][]string) {
size += rootTar.Size
rootfsPath = rootTar.Path
rootfsHash = rootTar.HashSha256
+ rootfsSize = rootTar.Size
}
if size == 0 || filename == "" || fingerprint == "" {
@@ -218,7 +223,9 @@ func (s *SimpleStreamsManifest) ToLXD() ([]api.Image, map[string][][]string) {
}
}
- downloads[fingerprint] = [][]string{{metaPath, metaHash, "meta"}, {rootfsPath, rootfsHash, "root"}}
+ downloads[fingerprint] = [][]string{
+ {metaPath, metaHash, "meta", fmt.Sprintf("%d", metaSize)},
+ {rootfsPath, rootfsHash, "root", fmt.Sprintf("%d", rootfsSize)}}
images = append(images, image)
}
}
@@ -269,6 +276,12 @@ type SimpleStreamsIndexStream struct {
Products []string `json:"products"`
}
+type SimpleStreamsFile struct {
+ Path string
+ Sha256 string
+ Size int64
+}
+
func NewClient(url string, httpClient http.Client, useragent string) *SimpleStreams {
return &SimpleStreams{
http: &httpClient,
@@ -484,7 +497,7 @@ func (s *SimpleStreams) getImages() ([]api.Image, map[string]*api.ImageAliasesEn
return images, aliases, nil
}
-func (s *SimpleStreams) getPaths(fingerprint string) ([][]string, error) {
+func (s *SimpleStreams) GetFiles(fingerprint string) (map[string]SimpleStreamsFile, error) {
// Load the main index
ssIndex, err := s.parseIndex()
if err != nil {
@@ -512,11 +525,21 @@ func (s *SimpleStreams) getPaths(fingerprint string) ([][]string, error) {
for _, image := range manifestImages {
if strings.HasPrefix(image.Fingerprint, fingerprint) {
- urls := [][]string{}
+ files := map[string]SimpleStreamsFile{}
+
for _, path := range downloads[image.Fingerprint] {
- urls = append(urls, []string{path[0], path[1], path[2]})
+ size, err := strconv.ParseInt(path[3], 10, 64)
+ if err != nil {
+ return nil, err
+ }
+
+ files[path[2]] = SimpleStreamsFile{
+ Path: path[0],
+ Sha256: path[1],
+ Size: size}
}
- return urls, nil
+
+ return files, nil
}
}
}
@@ -630,13 +653,21 @@ func (s *SimpleStreams) GetImage(fingerprint string) (*api.Image, error) {
return nil, err
}
+ matches := []api.Image{}
+
for _, image := range images {
if strings.HasPrefix(image.Fingerprint, fingerprint) {
- return &image, nil
+ matches = append(matches, image)
}
}
- return nil, fmt.Errorf("The requested image couldn't be found.")
+ if len(matches) == 0 {
+ return nil, fmt.Errorf("The requested image couldn't be found.")
+ } else if len(matches) > 1 {
+ return nil, fmt.Errorf("More than one match for the provided partial fingerprint.")
+ }
+
+ return &matches[0], nil
}
func (s *SimpleStreams) ExportImage(image string, target string) (string, error) {
@@ -644,16 +675,16 @@ func (s *SimpleStreams) ExportImage(image string, target string) (string, error)
return "", fmt.Errorf("Split images can only be written to a directory.")
}
- paths, err := s.getPaths(image)
+ files, err := s.GetFiles(image)
if err != nil {
return "", err
}
- for _, path := range paths {
- fields := strings.Split(path[0], "/")
+ for _, file := range files {
+ fields := strings.Split(file.Path, "/")
targetFile := filepath.Join(target, fields[len(fields)-1])
- err := s.downloadFile(path[0], path[1], targetFile, nil)
+ err := s.downloadFile(file.Path, file.Sha256, targetFile, nil)
if err != nil {
return "", err
}
@@ -662,18 +693,15 @@ func (s *SimpleStreams) ExportImage(image string, target string) (string, error)
return target, nil
}
-func (s *SimpleStreams) Download(image string, file string, target string, progress func(int64, int64)) error {
- paths, err := s.getPaths(image)
+func (s *SimpleStreams) Download(image string, fileType string, target string, progress func(int64, int64)) error {
+ files, err := s.GetFiles(image)
if err != nil {
return err
}
- for _, path := range paths {
- if file != path[2] {
- continue
- }
-
- return s.downloadFile(path[0], path[1], target, progress)
+ file, ok := files[fileType]
+ if ok {
+ return s.downloadFile(file.Path, file.Sha256, target, progress)
}
return fmt.Errorf("The file couldn't be found.")
More information about the lxc-devel
mailing list