[lxc-devel] [lxd/master] lxc/list: add new column "BASE IMAGE" for both short and long image fingerprint variants

TerraTech on Github lxc-bot at linuxcontainers.org
Tue Sep 25 06:15:59 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 920 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180925/81d5a718/attachment.bin>
-------------- next part --------------
From 0c420c51c241cf20c2670825bd02f28ba3b8c157 Mon Sep 17 00:00:00 2001
From: fqbuild <TerraTech at users.noreply.github.com>
Date: Tue, 25 Sep 2018 01:12:23 -0400
Subject: [PATCH] lxc/list: add new column "BASE IMAGE" for both short and long
 image fingerprint variants

  $ lxc list alpine-34 -cnfF
  +-----------+--------------+------------------------------------------------------------------+
  |   NAME    |  BASE IMAGE  |                            BASE IMAGE                            |
  +-----------+--------------+------------------------------------------------------------------+
  | alpine-34 | cc8b58012122 | cc8b580121227c92e05123e00cc52046b0139253db2c7a034234915f05a43eeb |
  +-----------+--------------+------------------------------------------------------------------+

Signed-off-by: fqbuild <TerraTech at users.noreply.github.com>
---
 lxc/list.go      | 27 ++++++++++++++++++++++++++-
 lxc/list_test.go |  2 +-
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/lxc/list.go b/lxc/list.go
index 4c73756d13..c28cab0a1d 100644
--- a/lxc/list.go
+++ b/lxc/list.go
@@ -91,6 +91,8 @@ Pre-defined column shorthand chars:
   S - Number of snapshots
   t - Type (persistent or ephemeral)
   L - Location of the container (e.g. its cluster member)
+  f - Base Image Fingerprint (short)
+  F - Base Image Fingerprint (long)
 
 Custom columns are defined with "key[:name][:maxWidth]":
   KEY: The (extended) config key to display
@@ -101,7 +103,7 @@ Custom columns are defined with "key[:name][:maxWidth]":
   Defaults to -1 (unlimited). Use 0 to limit to the column header size.`))
 
 	cmd.Example = cli.FormatSection("", i18n.G(
-		`lxc list -c n,volatile.base_image:"BASE IMAGE":0,s46,volatile.eth0.hwaddr:MAC
+		`lxc list -c nFs46,volatile.eth0.hwaddr:MAC
   Show containers using the "NAME", "BASE IMAGE", "STATE", "IPV4", "IPV6" and "MAC" columns.
   "BASE IMAGE" and "MAC" are custom columns generated from container configuration keys.
 
@@ -464,6 +466,8 @@ func (c *cmdList) parseColumns(clustered bool) ([]column, bool, error) {
 		's': {i18n.G("STATE"), c.statusColumnData, false, false},
 		't': {i18n.G("TYPE"), c.typeColumnData, false, false},
 		'b': {i18n.G("STORAGE POOL"), c.StoragePoolColumnData, false, false},
+		'f': {i18n.G("BASE IMAGE"), c.baseImageColumnData, false, false},
+		'F': {i18n.G("BASE IMAGE"), c.baseImageFullColumnData, false, false},
 	}
 
 	if c.flagFast {
@@ -570,6 +574,27 @@ func (c *cmdList) parseColumns(clustered bool) ([]column, bool, error) {
 	return columns, needsData, nil
 }
 
+func getBaseImage(cInfo api.ContainerFull, long bool) string {
+	v, ok := cInfo.Config["volatile.base_image"]
+	if !ok {
+		return "-Not Found-"
+	}
+
+	if !long && len(v) >= 12 {
+		v = v[:12]
+	}
+
+	return v
+}
+
+func (c *cmdList) baseImageColumnData(cInfo api.ContainerFull) string {
+	return getBaseImage(cInfo, false)
+}
+
+func (c *cmdList) baseImageFullColumnData(cInfo api.ContainerFull) string {
+	return getBaseImage(cInfo, true)
+}
+
 func (c *cmdList) nameColumnData(cInfo api.ContainerFull) string {
 	return cInfo.Name
 }
diff --git a/lxc/list_test.go b/lxc/list_test.go
index a7fe3857a2..71f50b0cbb 100644
--- a/lxc/list_test.go
+++ b/lxc/list_test.go
@@ -52,7 +52,7 @@ func TestShouldShow(t *testing.T) {
 }
 
 // Used by TestColumns and TestInvalidColumns
-const shorthand = "46abcdlnNpPsStL"
+const shorthand = "46abcdfFlnNpPsStL"
 const alphanum = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
 
 func TestColumns(t *testing.T) {


More information about the lxc-devel mailing list