[lxc-devel] [lxd/master] storage: Sort volume list by type and name

stgraber on Github lxc-bot at linuxcontainers.org
Thu Feb 16 01:56:41 UTC 2017


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/20170216/db3fb29e/attachment.bin>
-------------- next part --------------
From 9480eb3cbe4bfb578bf26a96695e08c1761856fd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Wed, 15 Feb 2017 20:56:14 -0500
Subject: [PATCH] storage: Sort volume list by type and name
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>
---
 lxc/storage.go | 32 +++++++++++++++++++++++++++++---
 po/lxd.pot     | 40 ++++++++++++++++++++--------------------
 2 files changed, 49 insertions(+), 23 deletions(-)

diff --git a/lxc/storage.go b/lxc/storage.go
index 809adcc..49057fc 100644
--- a/lxc/storage.go
+++ b/lxc/storage.go
@@ -19,6 +19,32 @@ import (
 	"github.com/lxc/lxd/shared/termios"
 )
 
+type byNameAndType [][]string
+
+func (a byNameAndType) Len() int {
+	return len(a)
+}
+
+func (a byNameAndType) Swap(i, j int) {
+	a[i], a[j] = a[j], a[i]
+}
+
+func (a byNameAndType) Less(i, j int) bool {
+	if a[i][0] != a[j][0] {
+		return a[i][0] < a[j][0]
+	}
+
+	if a[i][1] == "" {
+		return false
+	}
+
+	if a[j][1] == "" {
+		return true
+	}
+
+	return a[i][1] < a[j][1]
+}
+
 type storageCmd struct {
 }
 
@@ -642,7 +668,7 @@ func (c *storageCmd) doStoragePoolVolumesList(config *lxd.Config, remote string,
 	data := [][]string{}
 	for _, volume := range volumes {
 		usedby := strconv.Itoa(len(volume.UsedBy))
-		data = append(data, []string{volume.Name, volume.Type, usedby})
+		data = append(data, []string{volume.Type, volume.Name, usedby})
 	}
 
 	table := tablewriter.NewWriter(os.Stdout)
@@ -650,10 +676,10 @@ func (c *storageCmd) doStoragePoolVolumesList(config *lxd.Config, remote string,
 	table.SetAlignment(tablewriter.ALIGN_LEFT)
 	table.SetRowLine(true)
 	table.SetHeader([]string{
-		i18n.G("NAME"),
 		i18n.G("TYPE"),
+		i18n.G("NAME"),
 		i18n.G("USED BY")})
-	sort.Sort(byName(data))
+	sort.Sort(byNameAndType(data))
 	table.AppendBulk(data)
 	table.Render()
 
diff --git a/po/lxd.pot b/po/lxd.pot
index f2dd720..428c451 100644
--- a/po/lxd.pot
+++ b/po/lxd.pot
@@ -7,7 +7,7 @@
 msgid   ""
 msgstr  "Project-Id-Version: lxd\n"
         "Report-Msgid-Bugs-To: lxc-devel at lists.linuxcontainers.org\n"
-        "POT-Creation-Date: 2017-02-15 01:06-0500\n"
+        "POT-Creation-Date: 2017-02-15 20:56-0500\n"
         "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
         "Last-Translator: FULL NAME <EMAIL at ADDRESS>\n"
         "Language-Team: LANGUAGE <LL at li.org>\n"
@@ -16,7 +16,7 @@ msgstr  "Project-Id-Version: lxd\n"
         "Content-Type: text/plain; charset=CHARSET\n"
         "Content-Transfer-Encoding: 8bit\n"
 
-#: lxc/storage.go:30
+#: lxc/storage.go:56
 msgid   "### This is a yaml representation of a storage pool.\n"
         "### Any line starting with a '# will be ignored.\n"
         "###\n"
@@ -32,7 +32,7 @@ msgid   "### This is a yaml representation of a storage pool.\n"
         "###   zfs.pool_name: default"
 msgstr  ""
 
-#: lxc/storage.go:47
+#: lxc/storage.go:73
 msgid   "### This is a yaml representation of a storage volume.\n"
         "### Any line starting with a '# will be ignored.\n"
         "###\n"
@@ -199,7 +199,7 @@ msgstr  ""
 msgid   "Can't unset key '%s', it's not currently set."
 msgstr  ""
 
-#: lxc/network.go:398 lxc/profile.go:424 lxc/storage.go:541
+#: lxc/network.go:398 lxc/profile.go:424 lxc/storage.go:567
 msgid   "Cannot provide container name to list"
 msgstr  ""
 
@@ -233,7 +233,7 @@ msgstr  ""
 msgid   "Config key/value to apply to the new container"
 msgstr  ""
 
-#: lxc/config.go:535 lxc/config.go:600 lxc/image.go:737 lxc/network.go:354 lxc/profile.go:218 lxc/storage.go:497 lxc/storage.go:812
+#: lxc/config.go:535 lxc/config.go:600 lxc/image.go:737 lxc/network.go:354 lxc/profile.go:218 lxc/storage.go:523 lxc/storage.go:838
 #, c-format
 msgid   "Config parsing error: %s"
 msgstr  ""
@@ -318,7 +318,7 @@ msgstr  ""
 msgid   "DESCRIPTION"
 msgstr  ""
 
-#: lxc/storage.go:570
+#: lxc/storage.go:596
 msgid   "DRIVER"
 msgstr  ""
 
@@ -765,7 +765,7 @@ msgid   "Manage remote LXD servers.\n"
         "lxc remote get-default                                                      Print the default remote."
 msgstr  ""
 
-#: lxc/storage.go:61
+#: lxc/storage.go:87
 msgid   "Manage storage.\n"
         "\n"
         "lxc storage list [<remote>:]                           List available storage pools.\n"
@@ -907,7 +907,7 @@ msgid   "Monitor activity on the LXD server.\n"
         "    lxc monitor --type=logging"
 msgstr  ""
 
-#: lxc/network.go:224 lxc/network.go:273 lxc/storage.go:324 lxc/storage.go:424
+#: lxc/network.go:224 lxc/network.go:273 lxc/storage.go:350 lxc/storage.go:450
 msgid   "More than one device matches, specify the device name."
 msgstr  ""
 
@@ -932,7 +932,7 @@ msgstr  ""
 msgid   "Must supply container name for: "
 msgstr  ""
 
-#: lxc/list.go:431 lxc/network.go:434 lxc/profile.go:451 lxc/remote.go:380 lxc/storage.go:569 lxc/storage.go:653
+#: lxc/list.go:431 lxc/network.go:434 lxc/profile.go:451 lxc/remote.go:380 lxc/storage.go:595 lxc/storage.go:680
 msgid   "NAME"
 msgstr  ""
 
@@ -975,7 +975,7 @@ msgstr  ""
 msgid   "No device found for this network"
 msgstr  ""
 
-#: lxc/storage.go:333 lxc/storage.go:433
+#: lxc/storage.go:359 lxc/storage.go:459
 msgid   "No device found for this storage volume."
 msgstr  ""
 
@@ -983,7 +983,7 @@ msgstr  ""
 msgid   "No fingerprint specified."
 msgstr  ""
 
-#: lxc/storage.go:285 lxc/storage.go:369
+#: lxc/storage.go:311 lxc/storage.go:395
 msgid   "Only \"custom\" volumes can be attached to containers."
 msgstr  ""
 
@@ -1057,7 +1057,7 @@ msgstr  ""
 msgid   "Pid: %d"
 msgstr  ""
 
-#: lxc/network.go:355 lxc/profile.go:219 lxc/storage.go:498 lxc/storage.go:813
+#: lxc/network.go:355 lxc/profile.go:219 lxc/storage.go:524 lxc/storage.go:839
 msgid   "Press enter to open the editor again"
 msgstr  ""
 
@@ -1200,7 +1200,7 @@ msgstr  ""
 msgid   "SNAPSHOTS"
 msgstr  ""
 
-#: lxc/storage.go:571
+#: lxc/storage.go:597
 msgid   "SOURCE"
 msgstr  ""
 
@@ -1287,12 +1287,12 @@ msgstr  ""
 msgid   "Stopping container failed!"
 msgstr  ""
 
-#: lxc/storage.go:398
+#: lxc/storage.go:424
 #, c-format
 msgid   "Storage pool %s created"
 msgstr  ""
 
-#: lxc/storage.go:448
+#: lxc/storage.go:474
 #, c-format
 msgid   "Storage pool %s deleted"
 msgstr  ""
@@ -1301,12 +1301,12 @@ msgstr  ""
 msgid   "Storage pool name"
 msgstr  ""
 
-#: lxc/storage.go:677
+#: lxc/storage.go:703
 #, c-format
 msgid   "Storage volume %s created"
 msgstr  ""
 
-#: lxc/storage.go:687
+#: lxc/storage.go:713
 #, c-format
 msgid   "Storage volume %s deleted"
 msgstr  ""
@@ -1323,7 +1323,7 @@ msgstr  ""
 msgid   "Swap (peak)"
 msgstr  ""
 
-#: lxc/list.go:436 lxc/network.go:435 lxc/storage.go:654
+#: lxc/list.go:436 lxc/network.go:435 lxc/storage.go:679
 msgid   "TYPE"
 msgstr  ""
 
@@ -1352,7 +1352,7 @@ msgstr  ""
 msgid   "The opposite of `lxc pause` is `lxc start`."
 msgstr  ""
 
-#: lxc/network.go:238 lxc/network.go:287 lxc/storage.go:338 lxc/storage.go:438
+#: lxc/network.go:238 lxc/network.go:287 lxc/storage.go:364 lxc/storage.go:464
 msgid   "The specified device doesn't exist"
 msgstr  ""
 
@@ -1410,7 +1410,7 @@ msgstr  ""
 msgid   "URL"
 msgstr  ""
 
-#: lxc/network.go:437 lxc/profile.go:452 lxc/storage.go:572 lxc/storage.go:655
+#: lxc/network.go:437 lxc/profile.go:452 lxc/storage.go:598 lxc/storage.go:681
 msgid   "USED BY"
 msgstr  ""
 


More information about the lxc-devel mailing list