From d385ad1a0a0f62ee8a2e89c936228fd7d47b363d Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Thu, 21 Jul 2022 10:13:00 -0400 Subject: [PATCH] Support explicit prefix in xcc discovery --- confluent_server/confluent/discovery/handlers/xcc.py | 6 +++--- confluent_server/confluent/netutil.py | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/confluent_server/confluent/discovery/handlers/xcc.py b/confluent_server/confluent/discovery/handlers/xcc.py index b405f9fa..fcb4dab1 100644 --- a/confluent_server/confluent/discovery/handlers/xcc.py +++ b/confluent_server/confluent/discovery/handlers/xcc.py @@ -554,13 +554,13 @@ class NodeHandler(immhandler.NodeHandler): cd['hardwaremanagement.manager']['value'] and not cd['hardwaremanagement.manager']['value'].startswith( 'fe80::')): - newip = cd['hardwaremanagement.manager']['value'] - newip = newip.split('/', 1)[0] + rawnewip = cd['hardwaremanagement.manager']['value'] + newip = rawnewip.split('/', 1)[0] newipinfo = getaddrinfo(newip, 0)[0] newip = newipinfo[-1][0] if ':' in newip: raise exc.NotImplementedException('IPv6 remote config TODO') - netconfig = netutil.get_nic_config(self.configmanager, nodename, ip=newip) + netconfig = netutil.get_nic_config(self.configmanager, nodename, ip=rawnewip) newmask = netutil.cidr_to_mask(netconfig['prefix']) currinfo = wc.grab_json_response('/api/providers/logoninfo') currip = currinfo.get('items', [{}])[0].get('ipv4_address', '') diff --git a/confluent_server/confluent/netutil.py b/confluent_server/confluent/netutil.py index c040094a..74876f1b 100644 --- a/confluent_server/confluent/netutil.py +++ b/confluent_server/confluent/netutil.py @@ -606,9 +606,15 @@ def get_my_addresses(idx=0, family=0, matchlla=None): def get_prefix_len_for_ip(ip): + plen = None + if '/' in ip: + ip, plen = ip.split('/', 1) myaddrs = get_my_addresses() found = False for inf in socket.getaddrinfo(ip, 0, 0, socket.SOCK_DGRAM): + if plen: + yield (inf[0], plen) + return for myaddr in myaddrs: if inf[0] != myaddr[0]: continue