[lxc-devel] [python3-lxc/master] Fix ContainerNetworkList throwing KeyError

chang-andrew on Github lxc-bot at linuxcontainers.org
Thu Sep 17 22:21:39 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 505 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200917/04dd23be/attachment.bin>
-------------- next part --------------
From 1e64954badb5c63390a31ea2f18cb68fc59dd75b Mon Sep 17 00:00:00 2001
From: Andrew Chang <chang331006 at gmail.com>
Date: Thu, 17 Sep 2020 17:13:12 -0500
Subject: [PATCH] python3-lxc: Change ContainerNetworkList len function to not
 throw KeyError

Signed-off-by: Andrew Chang <chang331006 at gmail.com>
---
 lxc/__init__.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/lxc/__init__.py b/lxc/__init__.py
index ccc4d18..e73c843 100644
--- a/lxc/__init__.py
+++ b/lxc/__init__.py
@@ -124,7 +124,10 @@ def __getitem__(self, index):
         return ContainerNetwork(self.container, index)
 
     def __len__(self):
-        values = self.container.get_config_item("lxc.net")
+        try:
+            values = self.container.get_config_item("lxc.net")
+        except KeyError:
+            values = None
 
         if values:
             return len(values)


More information about the lxc-devel mailing list