[lxc-devel] [lxd/master] Export image last use and cache state

stgraber on Github lxc-bot at linuxcontainers.org
Fri Feb 26 22:41:19 UTC 2016


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 354 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160226/4c64fb82/attachment.bin>
-------------- next part --------------
From 83632e4d1ef69d5ec1fc110d1d48141b23addb4c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Fri, 26 Feb 2016 17:40:36 -0500
Subject: [PATCH] Export image last use and cache state
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/db_images.go  | 20 +++++++++++++-------
 shared/image.go   |  2 ++
 specs/rest-api.md |  2 ++
 3 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/lxd/db_images.go b/lxd/db_images.go
index 70f58d3..c845b46 100644
--- a/lxd/db_images.go
+++ b/lxd/db_images.go
@@ -38,7 +38,7 @@ func dbImagesGet(db *sql.DB, public bool) ([]string, error) {
 // enforced by a UNIQUE constraint in the schema.
 func dbImageGet(db *sql.DB, fingerprint string, public bool, strictMatching bool) (int, *shared.ImageInfo, error) {
 	var err error
-	var create, expire, upload *time.Time // These hold the db-returned times
+	var create, expire, used, upload *time.Time // These hold the db-returned times
 
 	// The object we'll actually return
 	image := shared.ImageInfo{}
@@ -47,8 +47,8 @@ func dbImageGet(db *sql.DB, fingerprint string, public bool, strictMatching bool
 
 	// These two humongous things will be filled by the call to DbQueryRowScan
 	outfmt := []interface{}{&id, &image.Fingerprint, &image.Filename,
-		&image.Size, &image.Public, &arch,
-		&create, &expire, &upload}
+		&image.Size, &image.Cached, &image.Public, &arch,
+		&create, &expire, &used, &upload}
 
 	var query string
 
@@ -57,8 +57,8 @@ func dbImageGet(db *sql.DB, fingerprint string, public bool, strictMatching bool
 		inargs = []interface{}{fingerprint}
 		query = `
         SELECT
-            id, fingerprint, filename, size, public, architecture,
-            creation_date, expiry_date, upload_date
+            id, fingerprint, filename, size, cached, public, architecture,
+            creation_date, expiry_date, last_use_date, upload_date
         FROM
             images
         WHERE fingerprint = ?`
@@ -66,8 +66,8 @@ func dbImageGet(db *sql.DB, fingerprint string, public bool, strictMatching bool
 		inargs = []interface{}{fingerprint + "%"}
 		query = `
         SELECT
-            id, fingerprint, filename, size, public, architecture,
-            creation_date, expiry_date, upload_date
+            id, fingerprint, filename, size, cached, public, architecture,
+            creation_date, expiry_date, last_use_date, upload_date
         FROM
             images
         WHERE fingerprint LIKE ?`
@@ -96,6 +96,12 @@ func dbImageGet(db *sql.DB, fingerprint string, public bool, strictMatching bool
 		image.ExpiryDate = time.Time{}
 	}
 
+	if used != nil {
+		image.LastUsedDate = *used
+	} else {
+		image.LastUsedDate = time.Time{}
+	}
+
 	image.Architecture, _ = shared.ArchitectureName(arch)
 
 	// The upload date is enforced by NOT NULL in the schema, so it can never be nil.
diff --git a/shared/image.go b/shared/image.go
index c56c997..c2feaaa 100644
--- a/shared/image.go
+++ b/shared/image.go
@@ -22,6 +22,7 @@ type ImageAlias struct {
 type ImageInfo struct {
 	Aliases      []ImageAlias      `json:"aliases"`
 	Architecture string            `json:"architecture"`
+	Cached       bool              `json:"cached"`
 	Fingerprint  string            `json:"fingerprint"`
 	Filename     string            `json:"filename"`
 	Properties   map[string]string `json:"properties"`
@@ -29,6 +30,7 @@ type ImageInfo struct {
 	Size         int64             `json:"size"`
 	CreationDate time.Time         `json:"created_at"`
 	ExpiryDate   time.Time         `json:"expires_at"`
+	LastUsedDate time.Time         `json:"last_used_at"`
 	UploadDate   time.Time         `json:"uploaded_at"`
 }
 
diff --git a/specs/rest-api.md b/specs/rest-api.md
index 1c82ea7..945115c 100644
--- a/specs/rest-api.md
+++ b/specs/rest-api.md
@@ -1101,6 +1101,7 @@ Output:
             }
         ],
         "architecture": "x86_64",
+        "cached": false,
         "fingerprint": "54c8caac1f61901ed86c68f24af5f5d3672bdc62c71d04f06df3a59e95684473",
         "filename": "ubuntu-trusty-14.04-amd64-server-20160201.tar.xz",
         "properties": {
@@ -1113,6 +1114,7 @@ Output:
         "size": 123792592,
         "created_at": "2016-02-01T21:07:41Z",
         "expires_at": "1970-01-01T00:00:00Z",
+        "last_used_at": "1970-01-01T00:00:00Z",
         "uploaded_at": "2016-02-16T00:44:47Z"
     }
 


More information about the lxc-devel mailing list