[lxc-devel] [lxd/master] lxd: Properly set containerArgs in all cases
stgraber on Github
lxc-bot at linuxcontainers.org
Thu Jun 28 19:54:30 UTC 2018
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/20180628/24f8d203/attachment.bin>
-------------- next part --------------
From 9220d724963769132d3e1375c847fd8db92a459c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Thu, 28 Jun 2018 15:52:59 -0400
Subject: [PATCH] lxd: Properly set containerArgs in all cases
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Closes #4706
Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
lxd/api_internal.go | 5 +++--
lxd/container.go | 1 +
lxd/container_lxc.go | 4 ++--
lxd/container_patch.go | 5 +++--
lxd/container_put.go | 5 +++--
lxd/container_snapshot.go | 11 +++++------
lxd/container_state.go | 2 +-
lxd/containers_post.go | 28 ++++++++++++++++------------
lxd/db/containers.go | 16 +++++++++-------
lxd/patches.go | 5 +----
lxd/profiles_utils.go | 4 ++--
lxd/storage_migration.go | 10 +++++-----
lxd/storage_volumes_utils.go | 3 ++-
13 files changed, 53 insertions(+), 46 deletions(-)
diff --git a/lxd/api_internal.go b/lxd/api_internal.go
index b92e976ab..97a973fa1 100644
--- a/lxd/api_internal.go
+++ b/lxd/api_internal.go
@@ -816,10 +816,10 @@ func internalImport(d *Daemon, r *http.Request) Response {
BaseImage: baseImage,
Config: snap.Config,
CreationDate: snap.CreationDate,
- LastUsedDate: snap.LastUsedDate,
Ctype: db.CTypeSnapshot,
Devices: snap.Devices,
Ephemeral: snap.Ephemeral,
+ LastUsedDate: snap.LastUsedDate,
Name: snap.Name,
Profiles: snap.Profiles,
Stateful: snap.Stateful,
@@ -853,10 +853,11 @@ func internalImport(d *Daemon, r *http.Request) Response {
BaseImage: baseImage,
Config: backup.Container.Config,
CreationDate: backup.Container.CreatedAt,
- LastUsedDate: backup.Container.LastUsedAt,
Ctype: db.CTypeRegular,
+ Description: backup.Container.Description,
Devices: backup.Container.Devices,
Ephemeral: backup.Container.Ephemeral,
+ LastUsedDate: backup.Container.LastUsedAt,
Name: backup.Container.Name,
Profiles: backup.Container.Profiles,
Stateful: backup.Container.Stateful,
diff --git a/lxd/container.go b/lxd/container.go
index 7079086d1..b5ee111a8 100644
--- a/lxd/container.go
+++ b/lxd/container.go
@@ -812,6 +812,7 @@ func containerCreateAsCopy(s *state.State, args db.ContainerArgs, sourceContaine
Config: snap.LocalConfig(),
Ctype: db.CTypeSnapshot,
Devices: snapDevices,
+ Description: snap.Description(),
Ephemeral: snap.IsEphemeral(),
Name: newSnapName,
Profiles: snap.Profiles(),
diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go
index 93bd6aa41..55deba5c3 100644
--- a/lxd/container_lxc.go
+++ b/lxd/container_lxc.go
@@ -3180,10 +3180,10 @@ func (c *containerLXC) Restore(sourceContainer container, stateful bool) error {
args := db.ContainerArgs{
Architecture: sourceContainer.Architecture(),
Config: sourceContainer.LocalConfig(),
+ Description: sourceContainer.Description(),
Devices: sourceContainer.LocalDevices(),
Ephemeral: sourceContainer.IsEphemeral(),
Profiles: sourceContainer.Profiles(),
- Description: sourceContainer.Description(),
}
err = c.Update(args, false)
@@ -3557,10 +3557,10 @@ func (c *containerLXC) ConfigKeySet(key string, value string) error {
args := db.ContainerArgs{
Architecture: c.architecture,
Config: c.localConfig,
+ Description: c.description,
Devices: c.localDevices,
Ephemeral: c.ephemeral,
Profiles: c.profiles,
- Description: c.description,
}
return c.Update(args, false)
diff --git a/lxd/container_patch.go b/lxd/container_patch.go
index e39ee6083..1857130b5 100644
--- a/lxd/container_patch.go
+++ b/lxd/container_patch.go
@@ -113,11 +113,12 @@ func containerPatch(d *Daemon, r *http.Request) Response {
// Update container configuration
args := db.ContainerArgs{
Architecture: architecture,
- Description: req.Description,
Config: req.Config,
+ Description: req.Description,
Devices: req.Devices,
Ephemeral: req.Ephemeral,
- Profiles: req.Profiles}
+ Profiles: req.Profiles,
+ }
err = c.Update(args, false)
if err != nil {
diff --git a/lxd/container_put.go b/lxd/container_put.go
index b738b1937..e92469e96 100644
--- a/lxd/container_put.go
+++ b/lxd/container_put.go
@@ -62,11 +62,12 @@ func containerPut(d *Daemon, r *http.Request) Response {
do = func(op *operation) error {
args := db.ContainerArgs{
Architecture: architecture,
- Description: configRaw.Description,
Config: configRaw.Config,
+ Description: configRaw.Description,
Devices: configRaw.Devices,
Ephemeral: configRaw.Ephemeral,
- Profiles: configRaw.Profiles}
+ Profiles: configRaw.Profiles,
+ }
// FIXME: should set to true when not migrating
err = c.Update(args, false)
diff --git a/lxd/container_snapshot.go b/lxd/container_snapshot.go
index 819a4fe76..fcb6eb696 100644
--- a/lxd/container_snapshot.go
+++ b/lxd/container_snapshot.go
@@ -120,14 +120,13 @@ func containerSnapshotsPost(d *Daemon, r *http.Request) Response {
snapshot := func(op *operation) error {
args := db.ContainerArgs{
- Name: fullName,
- Ctype: db.CTypeSnapshot,
- Config: c.LocalConfig(),
- Profiles: c.Profiles(),
- Ephemeral: c.IsEphemeral(),
- BaseImage: c.ExpandedConfig()["volatile.base_image"],
Architecture: c.Architecture(),
+ Config: c.LocalConfig(),
+ Ctype: db.CTypeSnapshot,
Devices: c.LocalDevices(),
+ Ephemeral: c.IsEphemeral(),
+ Name: fullName,
+ Profiles: c.Profiles(),
Stateful: req.Stateful,
}
diff --git a/lxd/container_state.go b/lxd/container_state.go
index 24a988076..e75aa68f7 100644
--- a/lxd/container_state.go
+++ b/lxd/container_state.go
@@ -128,9 +128,9 @@ func containerStatePut(d *Daemon, r *http.Request) Response {
if ephemeral {
// Unset ephemeral flag
args := db.ContainerArgs{
- Description: c.Description(),
Architecture: c.Architecture(),
Config: c.LocalConfig(),
+ Description: c.Description(),
Devices: c.LocalDevices(),
Ephemeral: false,
Profiles: c.Profiles(),
diff --git a/lxd/containers_post.go b/lxd/containers_post.go
index 99957291c..985438977 100644
--- a/lxd/containers_post.go
+++ b/lxd/containers_post.go
@@ -93,12 +93,13 @@ func createFromImage(d *Daemon, req *api.ContainersPost) Response {
run := func(op *operation) error {
args := db.ContainerArgs{
- Config: req.Config,
- Ctype: db.CTypeRegular,
- Devices: req.Devices,
- Ephemeral: req.Ephemeral,
- Name: req.Name,
- Profiles: req.Profiles,
+ Config: req.Config,
+ Ctype: db.CTypeRegular,
+ Description: req.Description,
+ Devices: req.Devices,
+ Ephemeral: req.Ephemeral,
+ Name: req.Name,
+ Profiles: req.Profiles,
}
var info *api.Image
@@ -142,12 +143,13 @@ func createFromImage(d *Daemon, req *api.ContainersPost) Response {
func createFromNone(d *Daemon, req *api.ContainersPost) Response {
args := db.ContainerArgs{
- Config: req.Config,
- Ctype: db.CTypeRegular,
- Devices: req.Devices,
- Ephemeral: req.Ephemeral,
- Name: req.Name,
- Profiles: req.Profiles,
+ Config: req.Config,
+ Ctype: db.CTypeRegular,
+ Description: req.Description,
+ Devices: req.Devices,
+ Ephemeral: req.Ephemeral,
+ Name: req.Name,
+ Profiles: req.Profiles,
}
if req.Architecture != "" {
@@ -195,6 +197,7 @@ func createFromMigration(d *Daemon, req *api.ContainersPost) Response {
Config: req.Config,
Ctype: db.CTypeRegular,
Devices: req.Devices,
+ Description: req.Description,
Ephemeral: req.Ephemeral,
Name: req.Name,
Profiles: req.Profiles,
@@ -507,6 +510,7 @@ func createFromCopy(d *Daemon, req *api.ContainersPost) Response {
BaseImage: req.Source.BaseImage,
Config: req.Config,
Ctype: db.CTypeRegular,
+ Description: req.Description,
Devices: req.Devices,
Ephemeral: req.Ephemeral,
Name: req.Name,
diff --git a/lxd/db/containers.go b/lxd/db/containers.go
index f6f1452c4..fdb6a6f40 100644
--- a/lxd/db/containers.go
+++ b/lxd/db/containers.go
@@ -19,18 +19,20 @@ import (
// container.
type ContainerArgs struct {
// Don't set manually
- ID int
- Node string
+ ID int
+ Node string
+ Ctype ContainerType
- Description string
- Architecture int
+ // Creation only
BaseImage string
- Config map[string]string
CreationDate time.Time
- LastUsedDate time.Time
- Ctype ContainerType
+
+ Architecture int
+ Config map[string]string
+ Description string
Devices types.Devices
Ephemeral bool
+ LastUsedDate time.Time
Name string
Profiles []string
Stateful bool
diff --git a/lxd/patches.go b/lxd/patches.go
index c9d780862..91a4acb0d 100644
--- a/lxd/patches.go
+++ b/lxd/patches.go
@@ -1806,12 +1806,9 @@ func updatePoolPropertyForAllObjects(d *Daemon, poolName string, allcontainers [
args := db.ContainerArgs{
Architecture: c.Architecture(),
Config: c.LocalConfig(),
+ Description: c.Description(),
Ephemeral: c.IsEphemeral(),
- CreationDate: c.CreationDate(),
- LastUsedDate: c.LastUsedDate(),
- Name: c.Name(),
Profiles: c.Profiles(),
- Description: c.Description(),
}
if c.IsSnapshot() {
diff --git a/lxd/profiles_utils.go b/lxd/profiles_utils.go
index c3c332769..c521a8e19 100644
--- a/lxd/profiles_utils.go
+++ b/lxd/profiles_utils.go
@@ -228,11 +228,11 @@ func doProfileUpdateContainer(d *Daemon, name string, old api.ProfilePut, nodeNa
return c.Update(db.ContainerArgs{
Architecture: c.Architecture(),
- Ephemeral: c.IsEphemeral(),
Config: c.LocalConfig(),
+ Description: c.Description(),
Devices: c.LocalDevices(),
+ Ephemeral: c.IsEphemeral(),
Profiles: c.Profiles(),
- Description: c.Description(),
}, true)
}
diff --git a/lxd/storage_migration.go b/lxd/storage_migration.go
index 61c6e2ff0..9fcc5ed6a 100644
--- a/lxd/storage_migration.go
+++ b/lxd/storage_migration.go
@@ -144,13 +144,13 @@ func snapshotProtobufToContainerArgs(containerName string, snap *migration.Snaps
name := containerName + shared.SnapshotDelimiter + snap.GetName()
args := db.ContainerArgs{
- Name: name,
- Ctype: db.CTypeSnapshot,
+ Architecture: int(snap.GetArchitecture()),
Config: config,
- Profiles: snap.Profiles,
- Ephemeral: snap.GetEphemeral(),
+ Ctype: db.CTypeSnapshot,
Devices: devices,
- Architecture: int(snap.GetArchitecture()),
+ Ephemeral: snap.GetEphemeral(),
+ Name: name,
+ Profiles: snap.Profiles,
Stateful: snap.GetStateful(),
}
diff --git a/lxd/storage_volumes_utils.go b/lxd/storage_volumes_utils.go
index 861dc5442..f55297669 100644
--- a/lxd/storage_volumes_utils.go
+++ b/lxd/storage_volumes_utils.go
@@ -267,7 +267,8 @@ func storagePoolVolumeUpdateUsers(d *Daemon, oldPoolName string,
Config: c.LocalConfig(),
Devices: devices,
Ephemeral: c.IsEphemeral(),
- Profiles: c.Profiles()}
+ Profiles: c.Profiles(),
+ }
err = c.Update(args, false)
if err != nil {
More information about the lxc-devel
mailing list