[lxc-devel] [lxd/master] lxc/list: Reduce number of API calls
stgraber on Github
lxc-bot at linuxcontainers.org
Thu Apr 26 17:27:12 UTC 2018
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/20180426/fe31b573/attachment.bin>
-------------- next part --------------
From 905d24aa8216832a84b02737f3fd2bcd440b765b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Thu, 26 Apr 2018 13:26:51 -0400
Subject: [PATCH] lxc/list: Reduce number of API calls
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/list.go | 25 ++-----------------------
1 file changed, 2 insertions(+), 23 deletions(-)
diff --git a/lxc/list.go b/lxc/list.go
index a4d590bf1..68b497e29 100644
--- a/lxc/list.go
+++ b/lxc/list.go
@@ -201,7 +201,7 @@ func (c *cmdList) shouldShow(filters []string, state *api.Container) bool {
return true
}
-func (c *cmdList) listContainers(conf *config.Config, remote string, cinfos []api.Container, filters []string, columns []column) error {
+func (c *cmdList) listContainers(conf *config.Config, d lxd.ContainerServer, cinfos []api.Container, filters []string, columns []column) error {
headers := []string{}
for _, column := range columns {
headers = append(headers, column.Name)
@@ -225,22 +225,12 @@ func (c *cmdList) listContainers(conf *config.Config, remote string, cinfos []ap
for i := 0; i < threads; i++ {
cStatesWg.Add(1)
go func() {
- var d lxd.ContainerServer
- var err error
for {
cName, more := <-cStatesQueue
if !more {
break
}
- if d == nil {
- d, err = conf.GetContainerServer(remote)
- if err != nil {
- cStatesWg.Done()
- return
- }
- }
-
state, _, err := d.GetContainerState(cName)
if err != nil {
continue
@@ -255,23 +245,12 @@ func (c *cmdList) listContainers(conf *config.Config, remote string, cinfos []ap
cSnapshotsWg.Add(1)
go func() {
- var d lxd.ContainerServer
- var err error
for {
cName, more := <-cSnapshotsQueue
if !more {
break
}
- if d == nil {
- d, err = conf.GetContainerServer(remote)
- if err != nil {
- cSnapshotsWg.Done()
- return
- }
-
- }
-
snaps, err := d.GetContainerSnapshots(cName)
if err != nil {
continue
@@ -460,7 +439,7 @@ func (c *cmdList) Run(cmd *cobra.Command, args []string) error {
}
// Fetch any remaining data and render the table
- return c.listContainers(conf, remote, cts, filters, columns)
+ return c.listContainers(conf, d, cts, filters, columns)
}
func (c *cmdList) parseColumns(clustered bool) ([]column, error) {
More information about the lxc-devel
mailing list