mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-06-11 23:59:44 +00:00
python: Use builtin len() function for network interfaces
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 <stgraber@ubuntu.com> Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
This commit is contained in:
parent
bde1853954
commit
2cdb945b13
@ -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")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user