From 8eb242cba0f8b629253f5e07d8873c0ac9ec1fd6 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Thu, 9 Sep 2021 16:27:59 -0400 Subject: [PATCH] Add ipv6 support to genesis --- .../common/opt/confluent/bin/apiclient | 2 +- .../initramfs/opt/confluent/bin/rungenesis | 19 ++++++++++++++++++- .../confluent/discovery/protocols/ssdp.py | 2 +- confluent_server/confluent/selfservice.py | 12 +++++++++--- 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/confluent_osdeploy/common/opt/confluent/bin/apiclient b/confluent_osdeploy/common/opt/confluent/bin/apiclient index 6bd6a02a..bcb2fae4 100644 --- a/confluent_osdeploy/common/opt/confluent/bin/apiclient +++ b/confluent_osdeploy/common/opt/confluent/bin/apiclient @@ -121,7 +121,7 @@ class HTTPSClient(client.HTTPConnection, object): authed = False rsp.read() with open('/etc/confluent/confluent.apikey', 'w+') as akfile: - akfile.write() + akfile.write('') self.stdheaders['CONFLUENT_APIKEY'] = get_apikey( self.node, self.host) raise Exception(rsp.read()) diff --git a/confluent_osdeploy/genesis/initramfs/opt/confluent/bin/rungenesis b/confluent_osdeploy/genesis/initramfs/opt/confluent/bin/rungenesis index 2c87c5a8..e887feda 100644 --- a/confluent_osdeploy/genesis/initramfs/opt/confluent/bin/rungenesis +++ b/confluent_osdeploy/genesis/initramfs/opt/confluent/bin/rungenesis @@ -99,13 +99,30 @@ tpm2_pcrextend 15:sha256=2fbe96c50dde38ce9cd2764ddb79c216cfbcd3499568b1125450e60 ifidx=$(cat /tmp/confluent.ifidx) ifname=$(ip link |grep ^$ifidx:|awk '{print $2}') ifname=${ifname%:} +autoconfigmethod=$(grep ipv6_method /etc/confluent/confluent.deploycfg |awk '{print $2}') +if [ "$autoconfigmethod" = "static" ]; then + ipaddr=$(grep ^ipv6_address: /etc/confluent/confluent.deploycfg) + ipaddr=${ipaddr#ipv6_address: } + ipgw=$(grep ^ipv6_gateway: /etc/confluent/confluent.deploycfg) + ipgw=${ipgw#ipv6_gateway: } + if [ "$ipgw" = "null" ]; then + ipgw="" + fi + ipnm=$(grep ^prefix: /etc/confluent/confluent.deploycfg) + ipnm=${ipnm#prefix: } + echo "Setting up $ifname as static at $ipaddr/$ipnm" + ip addr add dev $ifname $ipaddr/$ipnm + if [ ! -z "$ipgw" ]; then + ip route add default via $ipgw + fi +fi autoconfigmethod=$(grep ipv4_method /etc/confluent/confluent.deploycfg |awk '{print $2}') if [ "$autoconfigmethod" = "dhcp" ]; then echo -n "Attempting to use dhcp to bring up $ifname..." dhclient $ifname echo "Complete:" ip addr show dev $ifname -else +elif [ "$autocinfigmethtod" = "static" ]; then v4addr=$(grep ^ipv4_address: /etc/confluent/confluent.deploycfg) v4addr=${v4addr#ipv4_address: } v4gw=$(grep ^ipv4_gateway: /etc/confluent/confluent.deploycfg) diff --git a/confluent_server/confluent/discovery/protocols/ssdp.py b/confluent_server/confluent/discovery/protocols/ssdp.py index b257e75a..2f6aa822 100644 --- a/confluent_server/confluent/discovery/protocols/ssdp.py +++ b/confluent_server/confluent/discovery/protocols/ssdp.py @@ -204,7 +204,7 @@ def snoop(handler, byehandler=None, protocol=None, uuidlookup=None): msecs = int(currtime * 1000 % 1000) reply = 'HTTP/1.1 200 OK\r\nNODENAME: {0}\r\nCURRTIME: {1}\r\nCURRMSECS: {2}\r\n'.format(node, seconds, msecs) if '%' in peer[0]: - iface = peer[0].split('%', 1)[1] + iface = socket.getaddrinfo(peer[0], 0, socket.AF_INET6, socket.SOCK_DGRAM)[0][-1][-1] reply += 'MGTIFACE: {0}\r\n'.format( peer[0].split('%', 1)[1]) ncfg = netutil.get_nic_config( diff --git a/confluent_server/confluent/selfservice.py b/confluent_server/confluent/selfservice.py index 4f29c5ad..3b0d2294 100644 --- a/confluent_server/confluent/selfservice.py +++ b/confluent_server/confluent/selfservice.py @@ -110,7 +110,13 @@ def handle_request(env, start_response): yield dumper(res) elif env['PATH_INFO'] == '/self/deploycfg': if 'HTTP_CONFLUENT_MGTIFACE' in env: - ncfg = netutil.get_nic_config(cfg, nodename, ifidx=env['HTTP_CONFLUENT_MGTIFACE']) + nicname = env['HTTP_CONFLUENT_MGTIFACE'] + try: + ifidx = int(nicname) + except ValueError: + with open('/sys/class/net/{}/ifindex'.format(nicname), 'r') as nici: + ifidx = int(nici.read()) + ncfg = netutil.get_nic_config(cfg, nodename, ifidx=ifidx) else: myip = env.get('HTTP_X_FORWARDED_HOST', None) if ']' in myip: @@ -158,7 +164,7 @@ def handle_request(env, start_response): continue k, v = line.split('=', 1) if k == 'KEYMAP': - keymap = v + keymap = v.replace('"', '') needlocalectl = False if not needlocalectl: needlocalectl = True @@ -176,7 +182,7 @@ def handle_request(env, start_response): k, v = line.split('=', 1) if k == 'LANG': needlocalectl = False - currlocale = v + currlocale = v.replace('"', '') except IOError: pass if needlocalectl: