The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/python3-lxc/pull/24
This e-mail was sent by the LXC bot, direct replies will not reach the author unless they happen to be subscribed to this list. === Description (from pull-request) === [Work in progress PR] Fixes [#17 ](https://github.com/lxc/python3-lxc/issues/17) > Crash when attempting to set multiple network devices using Python bindings during container creation. Changes: `ContainerNetworkList.__getitem__()' will create a new network by calling 'ContainerNetworkList.add()' if the requested index is not in bounds. Signed-off-by: Michael Satanovsky michael.satanov...@gmail.com
From e480c63805d7f8a8cad2762fa9a2b7f5b3a8c730 Mon Sep 17 00:00:00 2001 From: Michael Satanovsky <michael.satanov...@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.satanov...@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
_______________________________________________ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel