topologies: handle `enable_v4` attribute for links

This commit is contained in:
Théophile Bastian 2020-04-01 18:46:14 +02:00
parent a6ba43c838
commit 458dc08d9c
4 changed files with 16 additions and 5 deletions

View File

@ -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.

View File

@ -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(

View File

@ -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)

View File

@ -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"]: