Skip to content

Commit af825aa

Browse files
committed
plugins: force IP version depending on static HE IP
When a Static Hosted Engine IP is provided, we automatically set the he_force_ip6 or he_force_ip4 variables. This because otherwise we end up in situations where the hosted engine has an IPv6 address, but tries to connect to the host via IPv4 or the other way around. If we start hosted-engine-setup and we specify a static IP address for the Hosted Engine. We need to handle this better. Cause now the following could happen: - A static IPv6 is passed to hosted-engine-setup for the HE - he_host_ip is not defined - No he_force_ip6/he_force_ip4 specified -> As no he_host_ip is passed, this is defined within the playbook -> he_host_ip is derived from the intersection of IPs the he_host_address resolves to and the output of `hostname -I`. The first IP from that intersect is chosen as he_host_ip. -> This host is added to /etc/hosts on the HE. But now, if you specify a static IP for the HE, this will get configured independently from what was set as he_host_ip. This means that if your host has both IPv4 and IPv6, the he_host_ip could be an IPv4, and thus the /etc/hosts in the HE contains the IPv4 address of the host. But if you then specified an IPv6 address for the HE, the HE will be configured with an IPv6-only address. And in the final stages the HE will try to connect to your host, it resolves to IPv4 address, and this will fail, because the HE only has an IPv6 address. Therefor we set he_force_ip6 or he_force_ip4 depending on the address version you specify as HE IP. Signed-off-by: Jean-Louis Dupond <jean-louis@dupond.be>
1 parent bfbd656 commit af825aa

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

  • src/plugins/gr-he-ansiblesetup/core

src/plugins/gr-he-ansiblesetup/core/misc.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323

2424
import gettext
25+
import netaddr
2526
import re
2627
import uuid
2728

@@ -434,6 +435,25 @@ def _closeup(self):
434435
]
435436
}
436437

438+
# If a static CIDR is provided for the Hosted Engine VM,
439+
# then we force connection to the host with same IP version
440+
# Otherwise we end up in a situation where the IPv6 only
441+
# HE VM tries to connect to the host with an IPv4 address
442+
if self.environment[ohostedcons.CloudInit.VM_STATIC_CIDR]:
443+
ip = netaddr.IPNetwork(
444+
self.environment[ohostedcons.CloudInit.VM_STATIC_CIDR]
445+
)
446+
if ip.version == 6:
447+
if self.environment[ohostedcons.NetworkEnv.FORCE_IPV4]:
448+
raise RuntimeError(
449+
_('Cannot force IPv4 when HE static IP is IPv6'))
450+
bootstrap_vars['he_force_ip6'] = True
451+
else:
452+
if self.environment[ohostedcons.NetworkEnv.FORCE_IPV6]:
453+
raise RuntimeError(
454+
_('Cannot force IPv6 when HE static IP is IPv4'))
455+
bootstrap_vars['he_force_ip4'] = True
456+
437457
if self.environment[
438458
ohostedcons.CoreEnv.RENEW_PKI_ON_RESTORE
439459
] is not None:

0 commit comments

Comments
 (0)