[lxc-devel] [lxd/master] lxd/db: Add missing criteria for querying a specific public image

freeekanayaka on Github lxc-bot at linuxcontainers.org
Tue Jun 23 08:36:48 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 454 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200623/e9332229/attachment.bin>
-------------- next part --------------
From 4d80d66b18c04126d79ac5f04713703872957731 Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Tue, 23 Jun 2020 10:34:12 +0200
Subject: [PATCH] lxd/db: Add missing criteria for querying a specific public
 image

Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
 lxd/db/images.go        |  1 +
 lxd/db/images.mapper.go | 15 ++++++++++++++-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/lxd/db/images.go b/lxd/db/images.go
index b35a2ee82c..37f676d151 100644
--- a/lxd/db/images.go
+++ b/lxd/db/images.go
@@ -25,6 +25,7 @@ import (
 //go:generate mapper stmt -p db -e image objects-by-Project
 //go:generate mapper stmt -p db -e image objects-by-Project-and-Public
 //go:generate mapper stmt -p db -e image objects-by-Project-and-Fingerprint
+//go:generate mapper stmt -p db -e image objects-by-Project-and-Fingerprint-and-Public
 //go:generate mapper stmt -p db -e image objects-by-Fingerprint
 //go:generate mapper stmt -p db -e image objects-by-Cached
 //
diff --git a/lxd/db/images.mapper.go b/lxd/db/images.mapper.go
index 8eb456837d..d656884b1e 100644
--- a/lxd/db/images.mapper.go
+++ b/lxd/db/images.mapper.go
@@ -39,6 +39,12 @@ SELECT images.id, projects.name AS project, images.fingerprint, images.type, ima
   WHERE project = ? AND images.fingerprint LIKE ? ORDER BY projects.id, images.fingerprint
 `)
 
+var imageObjectsByProjectAndFingerprintAndPublic = cluster.RegisterStmt(`
+SELECT images.id, projects.name AS project, images.fingerprint, images.type, images.filename, images.size, images.public, images.architecture, images.creation_date, images.expiry_date, images.upload_date, images.cached, images.last_use_date, images.auto_update
+  FROM images JOIN projects ON images.project_id = projects.id
+  WHERE project = ? AND images.fingerprint LIKE ? AND images.public = ? ORDER BY projects.id, images.fingerprint
+`)
+
 var imageObjectsByFingerprint = cluster.RegisterStmt(`
 SELECT images.id, projects.name AS project, images.fingerprint, images.type, images.filename, images.size, images.public, images.architecture, images.creation_date, images.expiry_date, images.upload_date, images.cached, images.last_use_date, images.auto_update
   FROM images JOIN projects ON images.project_id = projects.id
@@ -75,7 +81,14 @@ func (c *ClusterTx) GetImages(filter ImageFilter) ([]Image, error) {
 	var stmt *sql.Stmt
 	var args []interface{}
 
-	if criteria["Project"] != nil && criteria["Public"] != nil {
+	if criteria["Project"] != nil && criteria["Fingerprint"] != nil && criteria["Public"] != nil {
+		stmt = c.stmt(imageObjectsByProjectAndFingerprintAndPublic)
+		args = []interface{}{
+			filter.Project,
+			filter.Fingerprint,
+			filter.Public,
+		}
+	} else if criteria["Project"] != nil && criteria["Public"] != nil {
 		stmt = c.stmt(imageObjectsByProjectAndPublic)
 		args = []interface{}{
 			filter.Project,


More information about the lxc-devel mailing list