From 458dc08d9c04febacd1f69c4c98e2df04640c8e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophile=20Bastian?= Date: Wed, 1 Apr 2020 18:46:14 +0200 Subject: [PATCH] topologies: handle `enable_v4` attribute for links --- README.md | 10 ++++++++-- lxc_net/container.py | 4 +++- lxc_net/network.py | 3 ++- lxc_net/parse_network.py | 4 +++- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 0ed1fa6..5c92b57 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,7 @@ looking like this: --- links: - domains: ['a', 'b'] + enable_v4: false - domains: ['b', 'c'] domains: b: @@ -75,8 +76,13 @@ attribute, the list of domains (containers) connected to it. A domain is described by an arbitrary name. Domains will be spawned (and indexed) in alphabetical order. +The valid options for links are: +* `enable_v4`: boolean, specifies whether the NICs connected to this link have + an IPv4 address. + A `domains` root element is optional, and may be used to specify domain-specific options. -The valid options are: -* `enable_v4`: boolean, specifies whether the domain has an IPv4 address. +The valid options for domains are: +* `enable_v4`: boolean, specifies whether the domain has IPv4 addresses on its + NICs. diff --git a/lxc_net/container.py b/lxc_net/container.py index b2f60c0..49951f0 100644 --- a/lxc_net/container.py +++ b/lxc_net/container.py @@ -174,7 +174,9 @@ class Container(util.LibvirtObject): for net in self.networks: net_config = net_config_templ.inst( mac=util.MACAddress(net.id, self.id), - ipv4=util.Addrv4(net.id, self.id) if self.enable_v4 else None, + ipv4=util.Addrv4(net.id, self.id) + if self.enable_v4 and net.enable_v4 + else None, ipv6=util.Addrv6(net.id, self.id), ) net_config_path = net_conf_dir / "11-{link:02d}-{name}.network".format( diff --git a/lxc_net/network.py b/lxc_net/network.py index c1ec5e7..ca52166 100644 --- a/lxc_net/network.py +++ b/lxc_net/network.py @@ -12,13 +12,14 @@ class Network(util.LibvirtObject): def __str__(self): return "This network is already instanciated" - def __init__(self, conn, name=None): + def __init__(self, conn, name=None, enable_v4=True): super().__init__(conn) if not name: name = str(self.id) self.name = settings.PREFIX + "_link_" + name + self.enable_v4 = enable_v4 self.bridge_id = settings.NETWORK_ID * 0xFF + self.id self.bridge_mac = util.MACAddress(self.id, None) self.ipv4 = util.Addrv4(self.id, None, host_address=True) diff --git a/lxc_net/parse_network.py b/lxc_net/parse_network.py index 803f875..58f3b3f 100644 --- a/lxc_net/parse_network.py +++ b/lxc_net/parse_network.py @@ -214,7 +214,9 @@ class YamlTopology(Topology): "a 'domains' attribute is mandatory for each link" ) - cur_link = network.Network(self.conn) + cur_link = network.Network( + self.conn, enable_v4=link_conf.get("enable_v4", True), + ) self.links.append(cur_link) for dom in link_conf["domains"]: