for subnet, ifaces in self.mgr.cache.networks.get(host, {}).items():
if ifaces and ipaddress.ip_address(bare_ip) in ipaddress.ip_network(subnet):
interface = list(ifaces.keys())[0]
- host_ip = ifaces[interface][0]
+ for ip_addr in ifaces[interface]:
+ if ip_addr != str(bare_ip):
+ host_ip = ip_addr
+ break
logger.info(
f'{bare_ip} is in {subnet} on {host} interface {interface}'
)
for subnet, ifaces in self.mgr.cache.networks.get(host, {}).items():
if subnet in spec.virtual_interface_networks:
interface = list(ifaces.keys())[0]
- host_ip = ifaces[interface][0]
+ for ip_addr in ifaces[interface]:
+ if ip_addr != str(bare_ip):
+ host_ip = ip_addr
+ break
logger.info(
f'{spec.virtual_ip} will be configured on {host} interface '
f'{interface} (which is in subnet {subnet})'
with with_host(cephadm_module, 'test', addr='1.2.3.7'):
cephadm_module.cache.update_host_networks('test', {
'1.2.3.0/24': {
- 'if0': ['1.2.3.4']
+ 'if0': [
+ '1.2.3.4', # simulate already assigned VIP
+ '1.2.3.1', # simulate interface IP
+ ]
}
})
'auth_type PASS\n '
'auth_pass 12345\n '
'}\n '
- 'unicast_src_ip 1.2.3.4\n '
+ 'unicast_src_ip 1.2.3.1\n '
'unicast_peer {\n '
'}\n '
'virtual_ipaddress {\n '