[lxc-devel] [lxd/master] lxd: Updates snapshotProtobufToInstanceArgs to support instance type

tomponline on Github lxc-bot at linuxcontainers.org
Wed Apr 22 15:36:01 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 557 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200422/3dda5484/attachment.bin>
-------------- next part --------------
From d4751753fe396b8da0025886a0237fd495365a5b Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Wed, 22 Apr 2020 16:34:46 +0100
Subject: [PATCH] lxd: Updates snapshotProtobufToInstanceArgs to support
 instance type

Although I don't believe that instance type in snapshots is used by the database layer anymore, it shouldn't be hardcoded to container in case the struct is used in other places in the future.

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/migrate_instance.go  |  2 +-
 lxd/storage_migration.go | 11 +++++------
 2 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/lxd/migrate_instance.go b/lxd/migrate_instance.go
index 3c63cc2ae5..a370d52b1e 100644
--- a/lxd/migrate_instance.go
+++ b/lxd/migrate_instance.go
@@ -885,7 +885,7 @@ func (c *migrationSink) Do(state *state.State, migrateOp *operations.Operation)
 			volTargetArgs.Snapshots = make([]string, 0, len(args.Snapshots))
 			for _, snap := range args.Snapshots {
 				volTargetArgs.Snapshots = append(volTargetArgs.Snapshots, *snap.Name)
-				snapArgs := snapshotProtobufToInstanceArgs(args.Instance.Project(), args.Instance.Name(), snap)
+				snapArgs := snapshotProtobufToInstanceArgs(args.Instance, snap)
 
 				// Ensure that snapshot and parent container have the same
 				// storage pool in their local root disk device. If the root
diff --git a/lxd/storage_migration.go b/lxd/storage_migration.go
index 46ad741639..5ff3e38896 100644
--- a/lxd/storage_migration.go
+++ b/lxd/storage_migration.go
@@ -5,12 +5,12 @@ import (
 
 	"github.com/lxc/lxd/lxd/db"
 	deviceConfig "github.com/lxc/lxd/lxd/device/config"
-	"github.com/lxc/lxd/lxd/instance/instancetype"
+	"github.com/lxc/lxd/lxd/instance"
 	"github.com/lxc/lxd/lxd/migration"
 	"github.com/lxc/lxd/shared"
 )
 
-func snapshotProtobufToInstanceArgs(project string, containerName string, snap *migration.Snapshot) db.InstanceArgs {
+func snapshotProtobufToInstanceArgs(inst instance.Instance, snap *migration.Snapshot) db.InstanceArgs {
 	config := map[string]string{}
 
 	for _, ent := range snap.LocalConfig {
@@ -27,18 +27,17 @@ func snapshotProtobufToInstanceArgs(project string, containerName string, snap *
 		devices[ent.GetName()] = props
 	}
 
-	name := containerName + shared.SnapshotDelimiter + snap.GetName()
 	args := db.InstanceArgs{
 		Architecture: int(snap.GetArchitecture()),
 		Config:       config,
-		Type:         instancetype.Container,
+		Type:         inst.Type(),
 		Snapshot:     true,
 		Devices:      devices,
 		Ephemeral:    snap.GetEphemeral(),
-		Name:         name,
+		Name:         inst.Name() + shared.SnapshotDelimiter + snap.GetName(),
 		Profiles:     snap.Profiles,
 		Stateful:     snap.GetStateful(),
-		Project:      project,
+		Project:      inst.Project(),
 	}
 
 	if snap.GetCreationDate() != 0 {


More information about the lxc-devel mailing list