[lxc-devel] [lxd/master] add filtering of lxc aliases
akshaykarle on Github
lxc-bot at linuxcontainers.org
Wed Mar 30 07:18:46 UTC 2016
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 349 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160330/731b6da9/attachment.bin>
-------------- next part --------------
From 48c4e777b7aa614cebc8a58cea9877c93f1e864e Mon Sep 17 00:00:00 2001
From: Akshay Karle <akshay.a.karle at gmail.com>
Date: Tue, 29 Mar 2016 19:54:10 -0700
Subject: [PATCH] add filtering of lxc aliases
* similar to lxc image filter
* resolves #1798
---
lxc/image.go | 40 ++++++++++++++++++++++++++++++++++++----
1 file changed, 36 insertions(+), 4 deletions(-)
diff --git a/lxc/image.go b/lxc/image.go
index 8ba1941..ce87d9b 100644
--- a/lxc/image.go
+++ b/lxc/image.go
@@ -161,12 +161,26 @@ func (c *imageCmd) doImageAlias(config *lxd.Config, args []string) error {
var remote string
switch args[1] {
case "list":
- /* alias list [<remote>:] */
+ filters := []string{}
+
if len(args) > 2 {
- remote, _ = config.ParseRemoteAndContainer(args[2])
+ result := strings.SplitN(args[2], ":", 2)
+ if len(result) == 1 {
+ filters = append(filters, args[2])
+ remote, _ = config.ParseRemoteAndContainer("")
+ } else {
+ remote, _ = config.ParseRemoteAndContainer(args[2])
+ }
} else {
remote, _ = config.ParseRemoteAndContainer("")
}
+
+ if len(args) > 3 {
+ for _, filter := range args[3:] {
+ filters = append(filters, filter)
+ }
+ }
+
d, err := lxd.NewClient(config, remote)
if err != nil {
return err
@@ -177,7 +191,7 @@ func (c *imageCmd) doImageAlias(config *lxd.Config, args []string) error {
return err
}
- c.showAliases(resp)
+ c.showAliases(resp, filters)
return nil
case "create":
@@ -601,9 +615,13 @@ func (c *imageCmd) showImages(images []shared.ImageInfo, filters []string) error
return nil
}
-func (c *imageCmd) showAliases(aliases shared.ImageAliases) error {
+func (c *imageCmd) showAliases(aliases shared.ImageAliases, filters []string) error {
data := [][]string{}
for _, alias := range aliases {
+ if !c.aliasShouldShow(filters, &alias) {
+ continue
+ }
+
data = append(data, []string{alias.Name, alias.Target[0:12], alias.Description})
}
@@ -743,3 +761,17 @@ func (c *imageCmd) imageShouldShow(filters []string, state *shared.ImageInfo) bo
return true
}
+
+func (c *imageCmd) aliasShouldShow(filters []string, state *shared.ImageAliasesEntry) bool {
+ if len(filters) == 0 {
+ return true
+ }
+
+ for _, filter := range filters {
+ if strings.Contains(state.Name, filter) || strings.Contains(state.Target[0:12], filter) {
+ return true
+ }
+ }
+
+ return false
+}
More information about the lxc-devel
mailing list