[lxc-devel] [lxd/master] lxd/db: Rename ContainerNames to InstanceNames

stgraber on Github lxc-bot at linuxcontainers.org
Wed Dec 11 21:39:11 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 466 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20191211/b74b42d7/attachment.bin>
-------------- next part --------------
From b85ca4b42de28851e16972bd4c4d49fb847b94a0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Wed, 11 Dec 2019 16:38:29 -0500
Subject: [PATCH] lxd/db: Rename ContainerNames to InstanceNames
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

We're dealing with a single namespace for both containers and VMs, so we
need to extract the combined list.

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/containers_post.go | 5 +++--
 lxd/db/containers.go   | 6 +++---
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/lxd/containers_post.go b/lxd/containers_post.go
index ab9daf5544..d2d78fcf63 100644
--- a/lxd/containers_post.go
+++ b/lxd/containers_post.go
@@ -876,7 +876,7 @@ func containersPost(d *Daemon, r *http.Request) response.Response {
 		var names []string
 		err := d.cluster.Transaction(func(tx *db.ClusterTx) error {
 			var err error
-			names, err = tx.ContainerNames(project)
+			names, err = tx.InstanceNames(project)
 			return err
 		})
 		if err != nil {
@@ -892,9 +892,10 @@ func containersPost(d *Daemon, r *http.Request) response.Response {
 			}
 
 			if i > 100 {
-				return response.InternalError(fmt.Errorf("couldn't generate a new unique name after 100 tries"))
+				return response.InternalError(fmt.Errorf("Couldn't generate a new unique name after 100 tries"))
 			}
 		}
+
 		logger.Debugf("No name provided, creating %s", req.Name)
 	}
 
diff --git a/lxd/db/containers.go b/lxd/db/containers.go
index dd9b8e4644..351a37b6ab 100644
--- a/lxd/db/containers.go
+++ b/lxd/db/containers.go
@@ -170,14 +170,14 @@ type InstanceBackupArgs struct {
 	CompressionAlgorithm string
 }
 
-// ContainerNames returns the names of all containers the given project.
-func (c *ClusterTx) ContainerNames(project string) ([]string, error) {
+// InstanceNames returns the names of all containers the given project.
+func (c *ClusterTx) InstanceNames(project string) ([]string, error) {
 	stmt := `
 SELECT instances.name FROM instances
   JOIN projects ON projects.id = instances.project_id
   WHERE projects.name = ? AND instances.type = ?
 `
-	return query.SelectStrings(c.tx, stmt, project, instancetype.Container)
+	return query.SelectStrings(c.tx, stmt, project, instancetype.Any)
 }
 
 // ContainerNodeAddress returns the address of the node hosting the container


More information about the lxc-devel mailing list