Use our own len() function for network interfaces as doing
len(container.get_config_item("lxc.network")) will fail when the
list is empty.

Signed-off-by: Stéphane Graber <stgra...@ubuntu.com>
---
 src/python-lxc/lxc/__init__.py | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/src/python-lxc/lxc/__init__.py b/src/python-lxc/lxc/__init__.py
index c572e10..78852ec 100644
--- a/src/python-lxc/lxc/__init__.py
+++ b/src/python-lxc/lxc/__init__.py
@@ -115,23 +115,27 @@ class ContainerNetworkList():
         self.container = container
 
     def __getitem__(self, index):
-        count = len(self.container.get_config_item("lxc.network"))
-        if index >= count:
+        if index >= len(self):
             raise IndexError("list index out of range")
 
         return ContainerNetwork(self.container, index)
 
     def __len__(self):
-        return len(self.container.get_config_item("lxc.network"))
+        values = self.container.get_config_item("lxc.network")
+
+        if values:
+            return len(values)
+        else:
+            return 0
 
     def add(self, network_type):
-        index = len(self.container.get_config_item("lxc.network"))
+        index = len(self)
 
         return self.container.set_config_item("lxc.network.%s.type" % index,
                                               network_type)
 
     def remove(self, index):
-        count = len(self.container.get_config_item("lxc.network"))
+        count = len(self)
         if index >= count:
             raise IndexError("list index out of range")
 
-- 
1.8.0


------------------------------------------------------------------------------
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
_______________________________________________
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel

Reply via email to