[lxc-devel] [lxd/master] Changes instance.Type to int

tomponline on Github lxc-bot at linuxcontainers.org
Tue Sep 10 09:01:01 UTC 2019


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/20190910/c2582f0e/attachment.bin>
-------------- next part --------------
From 3b6bceb9360f7ef9671ab5b760ce0cf1b28443df Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Fri, 6 Sep 2019 14:29:22 +0100
Subject: [PATCH 1/2] lxd/instance/instance: Changes instance types to own int
 type

 - Adds constants for Any and Container types

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

diff --git a/lxd/instance/instance.go b/lxd/instance/instance.go
index 1dff9a626d..10952e4821 100644
--- a/lxd/instance/instance.go
+++ b/lxd/instance/instance.go
@@ -1,4 +1,11 @@
 package instance
 
-// TypeContainer represents a container instance type.
-const TypeContainer = "container"
+// Type indicates the type of instance.
+type Type int
+
+const (
+	// TypeAny represents any type of instance.
+	TypeAny = Type(-1)
+	// TypeContainer represents a container instance type.
+	TypeContainer = Type(0)
+)

From 3379c6be1d69dbcdb228d0c10000170fb86bca66 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <tomp at tomp.uk>
Date: Tue, 10 Sep 2019 09:59:17 +0100
Subject: [PATCH 2/2] lxd: Updates use of string instance.Type to int type

Signed-off-by: Thomas Parrott <tomp at tomp.uk>
---
 lxd/container.go                 | 3 ++-
 lxd/container_lxc.go             | 2 +-
 lxd/device/device_instance_id.go | 3 ++-
 3 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/lxd/container.go b/lxd/container.go
index dba6aea933..666e0a8fe9 100644
--- a/lxd/container.go
+++ b/lxd/container.go
@@ -20,6 +20,7 @@ import (
 	"github.com/lxc/lxd/lxd/db"
 	"github.com/lxc/lxd/lxd/device"
 	"github.com/lxc/lxd/lxd/device/config"
+	"github.com/lxc/lxd/lxd/instance"
 	"github.com/lxc/lxd/lxd/state"
 	"github.com/lxc/lxd/lxd/sys"
 	"github.com/lxc/lxd/lxd/task"
@@ -292,7 +293,7 @@ type container interface {
 	Location() string
 	Project() string
 	Name() string
-	Type() string
+	Type() instance.Type
 	Description() string
 	Architecture() int
 	CreationDate() time.Time
diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go
index 425b5e53da..6ab80d9dcc 100644
--- a/lxd/container_lxc.go
+++ b/lxd/container_lxc.go
@@ -630,7 +630,7 @@ type containerLXC struct {
 	expiryDate time.Time
 }
 
-func (c *containerLXC) Type() string {
+func (c *containerLXC) Type() instance.Type {
 	return instance.TypeContainer
 }
 
diff --git a/lxd/device/device_instance_id.go b/lxd/device/device_instance_id.go
index f1923aa17e..c92bb6ae95 100644
--- a/lxd/device/device_instance_id.go
+++ b/lxd/device/device_instance_id.go
@@ -2,6 +2,7 @@ package device
 
 import (
 	"github.com/lxc/lxd/lxd/device/config"
+	"github.com/lxc/lxd/lxd/instance"
 )
 
 // InstanceIdentifier is an interface that allows us to identify an Instance and its properties.
@@ -9,7 +10,7 @@ import (
 // independent of when they're called in the instance lifecycle.
 type InstanceIdentifier interface {
 	Name() string
-	Type() string
+	Type() instance.Type
 	Project() string
 	DevicesPath() string
 	RootfsPath() string


More information about the lxc-devel mailing list