[lxc-devel] [lxd/master] Instance: Adds Project() to common instance type

tomponline on Github lxc-bot at linuxcontainers.org
Thu Aug 27 12:53:29 UTC 2020


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/20200827/0c85dc41/attachment.bin>
-------------- next part --------------
From 7c2a9c5867671e59377eaa09a518f63bd0498f75 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Mon, 24 Aug 2020 10:23:12 +0100
Subject: [PATCH 1/6] lxd/instance/instance/interface: Moves Project() function
 into ConfigReader interface

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/instance/instance_interface.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lxd/instance/instance_interface.go b/lxd/instance/instance_interface.go
index e03db25bfb..f0c117f6e7 100644
--- a/lxd/instance/instance_interface.go
+++ b/lxd/instance/instance_interface.go
@@ -33,6 +33,7 @@ const (
 
 // ConfigReader is used to read instance config.
 type ConfigReader interface {
+	Project() string
 	Type() instancetype.Type
 	ExpandedConfig() map[string]string
 	ExpandedDevices() deviceConfig.Devices
@@ -99,7 +100,6 @@ type Instance interface {
 	// Properties.
 	ID() int
 	Location() string
-	Project() string
 	Name() string
 	Description() string
 	Architecture() int

From 716ef9bbe88dcbca794f6b71d0ee00a95ca21d9f Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Mon, 24 Aug 2020 10:29:28 +0100
Subject: [PATCH 2/6] lxd/instance/drivers/driver/common: Adds Project function

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/instance/drivers/driver_common.go | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/lxd/instance/drivers/driver_common.go b/lxd/instance/drivers/driver_common.go
index cceb455fc9..27d0fd1c81 100644
--- a/lxd/instance/drivers/driver_common.go
+++ b/lxd/instance/drivers/driver_common.go
@@ -20,6 +20,11 @@ type common struct {
 	state           *state.State
 }
 
+// Project returns instance's project.
+func (c *common) Project() string {
+	return c.project
+}
+
 // Type returns the instance's type.
 func (c *common) Type() instancetype.Type {
 	return c.dbType

From 75cffc9456e907f43829f78b5b292bf8f52642b9 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Mon, 24 Aug 2020 10:24:48 +0100
Subject: [PATCH 3/6] lxd/instance/drivers/driver/lxc: Updates lxc to use
 common fields

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/instance/drivers/driver_lxc.go | 40 ++++++++++++++----------------
 1 file changed, 19 insertions(+), 21 deletions(-)

diff --git a/lxd/instance/drivers/driver_lxc.go b/lxd/instance/drivers/driver_lxc.go
index bc4669a06b..768b536b8b 100644
--- a/lxd/instance/drivers/driver_lxc.go
+++ b/lxd/instance/drivers/driver_lxc.go
@@ -143,22 +143,24 @@ func lxcStatusCode(state liblxc.State) api.StatusCode {
 func lxcCreate(s *state.State, args db.InstanceArgs) (instance.Instance, error) {
 	// Create the container struct
 	c := &lxc{
-		state:        s,
+		common: common{
+			dbType:       args.Type,
+			localConfig:  args.Config,
+			localDevices: args.Devices,
+			project:      args.Project,
+			state:        s,
+			profiles:     args.Profiles,
+		},
 		id:           args.ID,
-		project:      args.Project,
 		name:         args.Name,
 		node:         args.Node,
 		description:  args.Description,
 		ephemeral:    args.Ephemeral,
 		architecture: args.Architecture,
-		dbType:       args.Type,
 		snapshot:     args.Snapshot,
 		stateful:     args.Stateful,
 		creationDate: args.CreationDate,
 		lastUsedDate: args.LastUsedDate,
-		profiles:     args.Profiles,
-		localConfig:  args.Config,
-		localDevices: args.Devices,
 		expiryDate:   args.ExpiryDate,
 	}
 
@@ -399,20 +401,22 @@ func lxcUnload(c *lxc) {
 // Create a container struct without initializing it.
 func lxcInstantiate(s *state.State, args db.InstanceArgs, expandedDevices deviceConfig.Devices) instance.Instance {
 	c := &lxc{
-		state:        s,
+		common: common{
+			dbType:       args.Type,
+			localConfig:  args.Config,
+			localDevices: args.Devices,
+			project:      args.Project,
+			state:        s,
+			profiles:     args.Profiles,
+		},
 		id:           args.ID,
-		project:      args.Project,
 		name:         args.Name,
 		description:  args.Description,
 		ephemeral:    args.Ephemeral,
 		architecture: args.Architecture,
-		dbType:       args.Type,
 		snapshot:     args.Snapshot,
 		creationDate: args.CreationDate,
 		lastUsedDate: args.LastUsedDate,
-		profiles:     args.Profiles,
-		localConfig:  args.Config,
-		localDevices: args.Devices,
 		stateful:     args.Stateful,
 		node:         args.Node,
 		expiryDate:   args.ExpiryDate,
@@ -441,32 +445,26 @@ func lxcInstantiate(s *state.State, args db.InstanceArgs, expandedDevices device
 
 // The LXC container driver.
 type lxc struct {
+	common
+
 	// Properties
 	architecture int
-	dbType       instancetype.Type
 	snapshot     bool
 	creationDate time.Time
 	lastUsedDate time.Time
 	ephemeral    bool
 	id           int
-	project      string
 	name         string
 	description  string
 	stateful     bool
 
 	// Config
-	expandedConfig  map[string]string
-	expandedDevices deviceConfig.Devices
-	fromHook        bool
-	localConfig     map[string]string
-	localDevices    deviceConfig.Devices
-	profiles        []string
+	fromHook bool
 
 	// Cache
 	c       *liblxc.Container
 	cConfig bool
 
-	state    *state.State
 	idmapset *idmap.IdmapSet
 
 	// Storage

From c6fdfccc7e039d9a44f53329ccc4e3fbdebdba10 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Mon, 24 Aug 2020 10:27:11 +0100
Subject: [PATCH 4/6] lxd/instance/drivers/driver/lxc: Removes driver specific
 Project function

Not needed as in common.

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/instance/drivers/driver_lxc.go | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/lxd/instance/drivers/driver_lxc.go b/lxd/instance/drivers/driver_lxc.go
index 768b536b8b..196e70cdbc 100644
--- a/lxd/instance/drivers/driver_lxc.go
+++ b/lxd/instance/drivers/driver_lxc.go
@@ -6727,11 +6727,6 @@ func (c *lxc) Location() string {
 	return c.node
 }
 
-// Project returns instance project.
-func (c *lxc) Project() string {
-	return c.project
-}
-
 // Name returns instance name.
 func (c *lxc) Name() string {
 	return c.name

From 36e40026915a953314ee766f1ed5b8f56d05e0a2 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Mon, 24 Aug 2020 10:28:46 +0100
Subject: [PATCH 5/6] lxd/instance/drivers/driver/qemu: Removes driver specific
 Project function

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/instance/drivers/driver_qemu.go | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/lxd/instance/drivers/driver_qemu.go b/lxd/instance/drivers/driver_qemu.go
index 90cb7045f5..1d14ca7555 100644
--- a/lxd/instance/drivers/driver_qemu.go
+++ b/lxd/instance/drivers/driver_qemu.go
@@ -4282,11 +4282,6 @@ func (vm *qemu) Location() string {
 	return vm.node
 }
 
-// Project returns instance's project.
-func (vm *qemu) Project() string {
-	return vm.project
-}
-
 // Name returns the instance's name.
 func (vm *qemu) Name() string {
 	return vm.name

From 578cfc68b50e223c01febd10465d4b657e8c76a3 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Thu, 27 Aug 2020 13:35:22 +0100
Subject: [PATCH 6/6] lxd/network/network/utils: Improves UpdateDNSMasqStatic
 error message

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/network/network_utils.go | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lxd/network/network_utils.go b/lxd/network/network_utils.go
index b4757742d3..36ea1420b8 100644
--- a/lxd/network/network_utils.go
+++ b/lxd/network/network_utils.go
@@ -324,8 +324,9 @@ func UpdateDNSMasqStatic(s *state.State, networkName string) error {
 
 		n, err := LoadByName(s, network)
 		if err != nil {
-			return err
+			return errors.Wrapf(err, "Failed to load network %q in project %q for dnsmasq update", project.Default, network)
 		}
+
 		config := n.Config()
 
 		// Wipe everything clean.


More information about the lxc-devel mailing list