[lxc-devel] [lxd/master] lxc/action: skip containers with intended state

brauner on Github lxc-bot at linuxcontainers.org
Tue Mar 26 15:39:40 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 456 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190326/e33fba84/attachment.bin>
-------------- next part --------------
From f6814cdcc2b296bb3ce34887f0ebb3e2cd6ae435 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 26 Mar 2019 16:38:18 +0100
Subject: [PATCH] lxc/action: skip containers with intended state

If a container is already stopped or running skip it so we don't report
useless errors.

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 lxc/action.go | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/lxc/action.go b/lxc/action.go
index 98c811f825..e41e5f530e 100644
--- a/lxc/action.go
+++ b/lxc/action.go
@@ -222,6 +222,16 @@ func (c *cmdAction) Run(cmd *cobra.Command, args []string) error {
 		}
 
 		for _, ct := range ctslist {
+			switch cmd.Name() {
+			case "start":
+				if ct.StatusCode == api.Running {
+					continue
+				}
+			case "stop":
+				if ct.StatusCode == api.Stopped {
+					continue
+				}
+			}
 			names = append(names, ct.Name)
 		}
 	} else {


More information about the lxc-devel mailing list