The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/2018
This e-mail was sent by the LXC bot, direct replies will not reach the author unless they happen to be subscribed to this list. === Description (from pull-request) ===
From 04932a2d05265f2f2c6b5bb15f6ea8491825ebbb Mon Sep 17 00:00:00 2001 From: Tycho Andersen <tycho.ander...@canonical.com> Date: Wed, 11 May 2016 17:37:51 +0000 Subject: [PATCH 1/2] propagate snapshot config when copying a snapshot Closes #2017 Signed-off-by: Tycho Andersen <tycho.ander...@canonical.com> --- client.go | 25 +++++++++++++++++++++++++ lxc/copy.go | 37 +++++++++++++++++++++++++++++-------- 2 files changed, 54 insertions(+), 8 deletions(-) diff --git a/client.go b/client.go index 6338017..b7740c1 100644 --- a/client.go +++ b/client.go @@ -1821,6 +1821,31 @@ func (c *Client) ListSnapshots(container string) ([]shared.SnapshotInfo, error) return result, nil } +func (c *Client) SnapshotInfo(snapName string) (*shared.SnapshotInfo, error) { + if c.Remote.Public { + return nil, fmt.Errorf("This function isn't supported by public remotes.") + } + + pieces := strings.SplitN(snapName, shared.SnapshotDelimiter, 2) + if len(pieces) != 2 { + return nil, fmt.Errorf("invalid snapshot name %s", snapName) + } + + qUrl := fmt.Sprintf("containers/%s/snapshots/%s", pieces[0], pieces[1]) + resp, err := c.get(qUrl) + if err != nil { + return nil, err + } + + var result shared.SnapshotInfo + + if err := json.Unmarshal(resp.Metadata, &result); err != nil { + return nil, err + } + + return &result, nil +} + func (c *Client) GetServerConfigString() ([]string, error) { var resp []string diff --git a/lxc/copy.go b/lxc/copy.go index a451919..74631c4 100644 --- a/lxc/copy.go +++ b/lxc/copy.go @@ -47,7 +47,12 @@ func (c *copyCmd) copyContainer(config *lxd.Config, sourceResource string, destR return err } - status := &shared.ContainerInfo{} + var status struct { + Architecture string + Devices shared.Devices + Config map[string]string + Profiles []string + } // TODO: presumably we want to do this for copying snapshots too? We // need to think a bit more about how we track the baseImage in the @@ -56,18 +61,34 @@ func (c *copyCmd) copyContainer(config *lxd.Config, sourceResource string, destR baseImage := "" if !shared.IsSnapshot(sourceName) { - status, err = source.ContainerInfo(sourceName) + result, err := source.ContainerInfo(sourceName) + if err != nil { + return err + } + + status.Architecture = result.Architecture + status.Devices = result.Devices + status.Config = result.Config + status.Profiles = result.Profiles + + } else { + result, err := source.SnapshotInfo(sourceName) if err != nil { return err } - baseImage = status.Config["volatile.base_image"] + status.Architecture = result.Architecture + status.Devices = result.Devices + status.Config = result.Config + status.Profiles = result.Profiles + } + + baseImage = status.Config["volatile.base_image"] - if !keepVolatile { - for k := range status.Config { - if strings.HasPrefix(k, "volatile") { - delete(status.Config, k) - } + if !keepVolatile { + for k := range status.Config { + if strings.HasPrefix(k, "volatile") { + delete(status.Config, k) } } } From 8fbf9c7fe0640b3d171f8a85f4bc84391c50181d Mon Sep 17 00:00:00 2001 From: Tycho Andersen <tycho.ander...@canonical.com> Date: Wed, 11 May 2016 11:49:50 -0600 Subject: [PATCH 2/2] implement `lxc config show` for snapshots Signed-off-by: Tycho Andersen <tycho.ander...@canonical.com> --- lxc/config.go | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/lxc/config.go b/lxc/config.go index 4bf7cc5..e824b4e 100644 --- a/lxc/config.go +++ b/lxc/config.go @@ -341,16 +341,43 @@ func (c *configCmd) run(config *lxd.Config, args []string) error { brief := config.Brief() data, err = yaml.Marshal(&brief) } else { - config, err := d.ContainerInfo(container) - if err != nil { - return err - } + var brief shared.BriefContainerInfo + if shared.IsSnapshot(container) { + config, err := d.SnapshotInfo(container) + if err != nil { + return err + } - brief := config.Brief() - if c.expanded { - brief = config.BriefExpanded() + brief = shared.BriefContainerInfo{ + Profiles: config.Profiles, + Config: config.Config, + Devices: config.Devices, + Ephemeral: config.Ephemeral, + } + if c.expanded { + brief = shared.BriefContainerInfo{ + Profiles: config.Profiles, + Config: config.ExpandedConfig, + Devices: config.ExpandedDevices, + Ephemeral: config.Ephemeral, + } + } + } else { + config, err := d.ContainerInfo(container) + if err != nil { + return err + } + + brief = config.Brief() + if c.expanded { + brief = config.BriefExpanded() + } } + data, err = yaml.Marshal(&brief) + if err != nil { + return err + } } fmt.Printf("%s", data)
_______________________________________________ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel