From f245f5cac54a34f51f8a7032d401ad5c832a0472 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Mon, 17 Oct 2022 13:07:18 -0400 Subject: [PATCH] Inject a hook for cmdline to specify confulent server This enables a more manual approach to indicate the deployment server. This carries the assumption that a normal OS autonetwork config will get the node to the right network. This is one step toward enabling a scenario where the target is remote and the DHCP is not going to relay, but instead the deployment feeds the DHCP a confluent URL entry point to get going. Using this parameter precludes: -Enhanced NIC auto selection. If the OS auto-selection fails to identify the correct interface, the profile will need nic name baked in. -Auto-select deployment server from several. This will mean that any HA will require IP takeover be externally handled This is of course on top of the manual process of indicating confluent in kernelargs. --- .../dracut/hooks/pre-trigger/01-confluent.sh | 19 +++++++++++++++++++ confluent_server/confluent/netutil.py | 2 ++ confluent_server/confluent/selfservice.py | 16 ++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/confluent_osdeploy/el8/initramfs/usr/lib/dracut/hooks/pre-trigger/01-confluent.sh b/confluent_osdeploy/el8/initramfs/usr/lib/dracut/hooks/pre-trigger/01-confluent.sh index 95b74586..d060a969 100644 --- a/confluent_osdeploy/el8/initramfs/usr/lib/dracut/hooks/pre-trigger/01-confluent.sh +++ b/confluent_osdeploy/el8/initramfs/usr/lib/dracut/hooks/pre-trigger/01-confluent.sh @@ -96,6 +96,25 @@ if [ -e /dev/disk/by-label/CNFLNT_IDNT ]; then fi cd /sys/class/net if ! grep MANAGER: /etc/confluent/confluent.info; then + confluentsrv=$(getarg confluent) + if [ ! -z "$confluentsrv" ]; then + if [[ "$confluentsrv" = *":"* ]]; then + /usr/libexec/nm-initrd-generator ip=:dhcp6 + else + /usr/libexec/nm-initrd-generator ip=:dhcp + fi + NetworkManager --configure-and-quit=initrd --no-daemon + myids=uuid=$(cat /sys/devices/virtual/dmi/id/product_uuid) + for mac in $(ip -br link|grep -v LOOPBACK|awk '{print $3}'); do + myids=$myids"/mac="$mac + done + myname=$(curl -sH "CONFLUENT_IDS: $myids" https://$confluentsrv/confluent-api/self/whoami) + if [ ! -z "$myname" ]; then + echo NODENAME: $myname > /etc/confluent/confluent.info + echo MANAGER: $confluentsrv >> /etc/confluent/confluent.info + echo EXTMGRINFO: $confluentsrv'||1' >> /etc/confluent/confluent.info + fi + fi while ! grep ^EXTMGRINFO: /etc/confluent/confluent.info | awk -F'|' '{print $3}' | grep 1 >& /dev/null && [ "$TRIES" -lt 60 ]; do TRIES=$((TRIES + 1)) for currif in *; do diff --git a/confluent_server/confluent/netutil.py b/confluent_server/confluent/netutil.py index b927ea75..39178613 100644 --- a/confluent_server/confluent/netutil.py +++ b/confluent_server/confluent/netutil.py @@ -237,6 +237,8 @@ class NetManager(object): if ipv6addr: myattribs['ipv6_method'] = 'static' myattribs['ipv6_address'] = ipv6addr + else: + myattribs['ipv6_method'] = 'dhcp' if attribs.get('ipv6_gateway', None) and 'ipv6_method' in myattribs: myattribs['ipv6_gateway'] = attribs['ipv6_gateway'] if 'ipv4_method' not in myattribs and 'ipv6_method' not in myattribs: diff --git a/confluent_server/confluent/selfservice.py b/confluent_server/confluent/selfservice.py index 1e9cc144..e084fff5 100644 --- a/confluent_server/confluent/selfservice.py +++ b/confluent_server/confluent/selfservice.py @@ -71,6 +71,22 @@ def handle_request(env, start_response): cfg = configmanager.ConfigManager(None) nodename = env.get('HTTP_CONFLUENT_NODENAME', None) clientip = env.get('HTTP_X_FORWARDED_FOR', None) + if env['PATH_INFO'] == '/self/whoami': + clientids = env.get('HTTP_CONFLUENT_IDS', None) + if not clientids: + start_response('400 Bad Request', []) + yield 'Bad Request' + return + for ids in clientids.split('/'): + _, v = ids.split('=', 1) + repname = disco.get_node_by_uuid_or_mac(v) + if repname: + start_response('200 OK', []) + yield repname + return + start_response('404 Unknown', []) + yield '' + return if env['PATH_INFO'] == '/self/registerapikey': crypthmac = env.get('HTTP_CONFLUENT_CRYPTHMAC', None) if int(env.get('CONTENT_LENGTH', 65)) > 64: