Support basic IPv6

This commit is contained in:
Pascal Vizeli 2022-08-09 08:07:52 +00:00
parent 29b2de6998
commit 9f1ab99265
2 changed files with 17 additions and 4 deletions

View File

@ -38,6 +38,7 @@ SYSTEMD_JOURNAL_VOLATILE = Path("/run/log/journal")
DOCKER_NETWORK = "hassio" DOCKER_NETWORK = "hassio"
DOCKER_NETWORK_MASK = ip_network("172.30.32.0/23") DOCKER_NETWORK_MASK = ip_network("172.30.32.0/23")
DOCKER_NETWORK_RANGE = ip_network("172.30.33.0/24") DOCKER_NETWORK_RANGE = ip_network("172.30.33.0/24")
DOCKER_NETWORK_LINK_LOCAL = ip_network("fd00:172:30:32::/64")
# This needs to match the dockerd --cpu-rt-runtime= argument. # This needs to match the dockerd --cpu-rt-runtime= argument.
DOCKER_CPU_RUNTIME_TOTAL = 950_000 DOCKER_CPU_RUNTIME_TOTAL = 950_000

View File

@ -7,7 +7,12 @@ from typing import Optional
import docker import docker
import requests import requests
from ..const import DOCKER_NETWORK, DOCKER_NETWORK_MASK, DOCKER_NETWORK_RANGE from ..const import (
DOCKER_NETWORK,
DOCKER_NETWORK_LINK_LOCAL,
DOCKER_NETWORK_MASK,
DOCKER_NETWORK_RANGE,
)
from ..exceptions import DockerError from ..exceptions import DockerError
_LOGGER: logging.Logger = logging.getLogger(__name__) _LOGGER: logging.Logger = logging.getLogger(__name__)
@ -80,19 +85,26 @@ class DockerNetwork:
except docker.errors.NotFound: except docker.errors.NotFound:
_LOGGER.info("Can't find Supervisor network, creating a new network") _LOGGER.info("Can't find Supervisor network, creating a new network")
ipam_pool = docker.types.IPAMPool( # IP configuration
ipam_pool_v4 = docker.types.IPAMPool(
subnet=str(DOCKER_NETWORK_MASK), subnet=str(DOCKER_NETWORK_MASK),
gateway=str(self.gateway), gateway=str(self.gateway),
iprange=str(DOCKER_NETWORK_RANGE), iprange=str(DOCKER_NETWORK_RANGE),
) )
ipam_pool_v6 = docker.types.IPAMPool(
subnet=str(DOCKER_NETWORK_LINK_LOCAL),
gateway=str(self.gateway),
iprange=str(DOCKER_NETWORK_LINK_LOCAL),
)
ipam_config = docker.types.IPAMConfig(pool_configs=[ipam_pool]) ipam_config = docker.types.IPAMConfig(pool_configs=[ipam_pool_v4, ipam_pool_v6])
# Create Network
return self.docker.networks.create( return self.docker.networks.create(
DOCKER_NETWORK, DOCKER_NETWORK,
driver="bridge", driver="bridge",
ipam=ipam_config, ipam=ipam_config,
enable_ipv6=False, enable_ipv6=True,
options={"com.docker.network.bridge.name": DOCKER_NETWORK}, options={"com.docker.network.bridge.name": DOCKER_NETWORK},
) )