[lxc-devel] [python3-lxc/master] Allows setting of multiple network devices at creation.

michaelsatanovsky on Github lxc-bot at linuxcontainers.org
Wed Dec 9 16:12:34 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 727 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20201209/980c770e/attachment.bin>
-------------- next part --------------
From e480c63805d7f8a8cad2762fa9a2b7f5b3a8c730 Mon Sep 17 00:00:00 2001
From: Michael Satanovsky <michael.satanovsky at gmail.com>
Date: Wed, 9 Dec 2020 08:00:32 -0800
Subject: [PATCH 1/2] Added logic to add new network device when needed.

---
 lxc/__init__.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/lxc/__init__.py b/lxc/__init__.py
index 8c51f70..c45e292 100644
--- a/lxc/__init__.py
+++ b/lxc/__init__.py
@@ -118,8 +118,12 @@ def __init__(self, container):
         self.container = container
 
     def __getitem__(self, index):
+        print("getting item")
         if index >= len(self):
-            raise IndexError("list index out of range")
+
+            # If index of network is out of bounds, create a new network.
+            print("Network index out of range. Creating new network at index %d." % index)
+            self.add("temp_type")
 
         return ContainerNetwork(self.container, index)
 
@@ -130,6 +134,7 @@ def __len__(self):
             values = None
 
         if values:
+            #print(values)
             return len(values)
         else:
             return 0

From faad5b1de8d612a0f3bd3d12ea8a30d361842d2f Mon Sep 17 00:00:00 2001
From: Michael Satanovsky <michael.satanovsky at gmail.com>
Date: Wed, 9 Dec 2020 08:02:50 -0800
Subject: [PATCH 2/2] Got rid of some extraneous lines

---
 lxc/__init__.py | 2 --
 1 file changed, 2 deletions(-)

diff --git a/lxc/__init__.py b/lxc/__init__.py
index c45e292..957d7df 100644
--- a/lxc/__init__.py
+++ b/lxc/__init__.py
@@ -118,7 +118,6 @@ def __init__(self, container):
         self.container = container
 
     def __getitem__(self, index):
-        print("getting item")
         if index >= len(self):
 
             # If index of network is out of bounds, create a new network.
@@ -134,7 +133,6 @@ def __len__(self):
             values = None
 
         if values:
-            #print(values)
             return len(values)
         else:
             return 0


More information about the lxc-devel mailing list