[lxc-devel] [lxd/master] Lxc list display number of processes inside of container

dnegreira on Github lxc-bot at linuxcontainers.org
Sat Jan 6 14:59:49 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 503 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180106/4c1702bf/attachment.bin>
-------------- next part --------------
From 1f90bc8a722ace1546e5a071e97577c1cbdd84d1 Mon Sep 17 00:00:00 2001
From: David Negreira <David at otherreality.net>
Date: Sat, 6 Jan 2018 15:53:03 +0100
Subject: [PATCH 1/2] lxc_list: Option to display number of processes

Signed-off-by: David Negreira <David at otherreality.net>
---
 lxc/list.go | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/lxc/list.go b/lxc/list.go
index 9599e61e1..4796af0d4 100644
--- a/lxc/list.go
+++ b/lxc/list.go
@@ -93,6 +93,8 @@ Pre-defined column shorthand chars:
 
 	n - Name
 
+	N - Number of Processes
+
 	p - PID of the container's init process
 
 	P - Profiles
@@ -463,6 +465,7 @@ func (c *listCmd) parseColumns() ([]column, error) {
 		'd': {i18n.G("DESCRIPTION"), c.descriptionColumnData, false, false},
 		'l': {i18n.G("LAST USED AT"), c.LastUsedColumnData, false, false},
 		'n': {i18n.G("NAME"), c.nameColumnData, false, false},
+		'N': {i18n.G("PROCESSES"), c.NumberOfProcessesColumnData, true, false},
 		'p': {i18n.G("PID"), c.PIDColumnData, true, false},
 		'P': {i18n.G("PROFILES"), c.ProfilesColumnData, false, false},
 		'S': {i18n.G("SNAPSHOTS"), c.numberSnapshotsColumnData, false, true},
@@ -675,3 +678,12 @@ func (c *listCmd) LastUsedColumnData(cInfo api.Container, cState *api.ContainerS
 
 	return ""
 }
+
+func (c *listCmd) NumberOfProcessesColumnData(cInfo api.Container, cState *api.ContainerState, cSnaps []api.ContainerSnapshot) string {
+	if cInfo.IsActive() && cState != nil {
+		return fmt.Sprintf("%d", cState.Processes)
+	}
+
+	return ""
+
+}

From a0c232174b36fb882105de2643754b6f091329ad Mon Sep 17 00:00:00 2001
From: David Negreira <David at otherreality.net>
Date: Sat, 6 Jan 2018 15:54:30 +0100
Subject: [PATCH 2/2] lxc_list_test: added N option to tests

Signed-off-by: David Negreira <David at otherreality.net>
---
 lxc/list_test.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lxc/list_test.go b/lxc/list_test.go
index 6bdf62e0d..915f985fd 100644
--- a/lxc/list_test.go
+++ b/lxc/list_test.go
@@ -52,7 +52,7 @@ func TestShouldShow(t *testing.T) {
 }
 
 // Used by TestColumns and TestInvalidColumns
-const shorthand = "46abcdlnpPsSt"
+const shorthand = "46abcdlnNpPsSt"
 const alphanum = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
 
 func TestColumns(t *testing.T) {


More information about the lxc-devel mailing list