[lxc-devel] [lxd/master] master
cneira on Github
lxc-bot at linuxcontainers.org
Fri Sep 2 18:26:03 UTC 2016
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 429 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160902/e8c9cb1f/attachment.bin>
-------------- next part --------------
From 34452b399c6af371b9eaa369c74cd751d1510885 Mon Sep 17 00:00:00 2001
From: Carlos Neira <cneirabustos at gmail.com>
Date: Fri, 2 Sep 2016 15:24:07 -0300
Subject: [PATCH] Add option for overriding the default compression algorithm
when publishing images. #2296 https://github.com/lxc/lxd/issues/2296
Signed-off-by: Carlos Neira <cneirabustos at gmail.com>
---
client.go | 3 +--
lxc/image.go | 14 ++++++++++++++
lxc/publish.go | 9 ++++++---
lxd/images.go | 10 +++++++++-
4 files changed, 30 insertions(+), 6 deletions(-)
diff --git a/client.go b/client.go
index f7a6c53..d78427b 100644
--- a/client.go
+++ b/client.go
@@ -2418,8 +2418,7 @@ func (c *Client) ImageFromContainer(cname string, public bool, aliases []string,
if c.Remote.Public {
return "", fmt.Errorf("This function isn't supported by public remotes.")
}
-
- source := shared.Jmap{"type": "container", "name": cname}
+ source := shared.Jmap{"type": "container", "name": cname, "compression": properties["compression"]}
if shared.IsSnapshot(cname) {
source["type"] = "snapshot"
}
diff --git a/lxc/image.go b/lxc/image.go
index 488adab..f539707 100644
--- a/lxc/image.go
+++ b/lxc/image.go
@@ -55,11 +55,16 @@ func (a SortImage) Less(i, j int) bool {
}
type aliasList []string
+type algorithm []string
func (f *aliasList) String() string {
return fmt.Sprint(*f)
}
+func (f *algorithm) String() string {
+ return fmt.Sprint(*f)
+}
+
func (f *aliasList) Set(value string) error {
if f == nil {
*f = make(aliasList, 1)
@@ -69,6 +74,15 @@ func (f *aliasList) Set(value string) error {
return nil
}
+func (f *algorithm) Set(value string) error {
+ if f == nil {
+ *f = make(algorithm, 1)
+ } else {
+ *f = append(*f, value)
+ }
+ return nil
+}
+
type imageCmd struct {
addAliases aliasList
publicImage bool
diff --git a/lxc/publish.go b/lxc/publish.go
index b09675c..0236866 100644
--- a/lxc/publish.go
+++ b/lxc/publish.go
@@ -12,9 +12,10 @@ import (
)
type publishCmd struct {
- pAliases aliasList // aliasList defined in lxc/image.go
- makePublic bool
- Force bool
+ pAliases aliasList // aliasList defined in lxc/image.go
+ Compression algorithm
+ makePublic bool
+ Force bool
}
func (c *publishCmd) showByDefault() bool {
@@ -33,6 +34,7 @@ func (c *publishCmd) flags() {
gnuflag.Var(&c.pAliases, "alias", i18n.G("New alias to define at target"))
gnuflag.BoolVar(&c.Force, "force", false, i18n.G("Stop the container if currently running"))
gnuflag.BoolVar(&c.Force, "f", false, i18n.G("Stop the container if currently running"))
+ gnuflag.Var(&c.Compression, "compression", i18n.G("Define a compression algorithm: for image or none"))
}
func (c *publishCmd) run(config *lxd.Config, args []string) error {
@@ -129,6 +131,7 @@ func (c *publishCmd) run(config *lxd.Config, args []string) error {
}
properties[entry[0]] = entry[1]
}
+ properties["compression"] = c.Compression[0]
var fp string
diff --git a/lxd/images.go b/lxd/images.go
index 2fc649b..5b87fdf 100644
--- a/lxd/images.go
+++ b/lxd/images.go
@@ -203,6 +203,7 @@ func imgPostContInfo(d *Daemon, r *http.Request, req imagePostReq,
info.Properties = map[string]string{}
name := req.Source["name"]
ctype := req.Source["type"]
+
if ctype == "" || name == "" {
return info, fmt.Errorf("No source provided")
}
@@ -247,7 +248,14 @@ func imgPostContInfo(d *Daemon, r *http.Request, req imagePostReq,
tarfile.Close()
var compressedPath string
- compress := daemonConfig["images.compression_algorithm"].Get()
+ var compress string
+
+ if compression_algorithm, ok := req.Source["compression"]; ok {
+ compress = compression_algorithm
+ } else {
+ compress = daemonConfig["images.compression_algorithm"].Get()
+ }
+
if compress != "none" {
compressedPath, err = compressFile(tarfile.Name(), compress)
if err != nil {
More information about the lxc-devel
mailing list