Commit 2cdb945b by Stéphane Graber

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: 's avatarStéphane Graber <stgraber@ubuntu.com> Acked-by: 's avatarSerge E. Hallyn <serge.hallyn@ubuntu.com>
parent bde18539
......@@ -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")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment