[lxc-devel] [lxd/master] List broken containers (with state set to ERROR)

stgraber on Github lxc-bot at linuxcontainers.org
Thu Mar 24 01:27:45 UTC 2016


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 370 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160324/ec94a243/attachment.bin>
-------------- next part --------------
From 88151da8be5a014545fa8d1492d02203da05399a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Wed, 23 Mar 2016 21:26:29 -0400
Subject: [PATCH] List broken containers (with state set to ERROR)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Closes #1800

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/containers_get.go | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)

diff --git a/lxd/containers_get.go b/lxd/containers_get.go
index 080ece5..750782d 100644
--- a/lxd/containers_get.go
+++ b/lxd/containers_get.go
@@ -45,11 +45,14 @@ func doContainersGet(d *Daemon, recursion bool) (interface{}, error) {
 			url := fmt.Sprintf("/%s/containers/%s", shared.APIVersion, container)
 			resultString = append(resultString, url)
 		} else {
-			container, response := doContainerGet(d, container)
-			if response != nil {
-				continue
+			c, err := doContainerGet(d, container)
+			if err != nil {
+				c = &shared.ContainerInfo{
+					Name:       container,
+					Status:     shared.Error.String(),
+					StatusCode: shared.Error}
 			}
-			resultList = append(resultList, container)
+			resultList = append(resultList, c)
 		}
 	}
 
@@ -60,21 +63,15 @@ func doContainersGet(d *Daemon, recursion bool) (interface{}, error) {
 	return resultList, nil
 }
 
-func doContainerGet(d *Daemon, cname string) (*shared.ContainerInfo, Response) {
+func doContainerGet(d *Daemon, cname string) (*shared.ContainerInfo, error) {
 	c, err := containerLoadByName(d, cname)
 	if err != nil {
-		return nil, SmartError(err)
+		return nil, err
 	}
 
 	cts, err := c.Render()
-	if err == LxcMonitorStateError {
-		return &shared.ContainerInfo{
-			Name:       cname,
-			Status:     shared.Error.String(),
-			StatusCode: shared.Error,
-		}, nil
-	} else if err != nil {
-		return nil, SmartError(err)
+	if err != nil {
+		return nil, err
 	}
 
 	return cts.(*shared.ContainerInfo), nil


More information about the lxc-devel mailing list