From 585988b22a42cf0e4645c37c0f15eeafff468829 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Mon, 3 Aug 2020 11:42:27 -0400 Subject: [PATCH] Add firmwaredhcp method In a case where static is desired for the OS, but PXE or HTTP boot will receive an IP address from a DHCP server, offer firmwaredhcp. This tells confluent to refrain from offering an IP during firmware, but still telling the OS to use static. --- confluent_server/confluent/config/attributes.py | 6 ++++-- confluent_server/confluent/discovery/protocols/pxe.py | 2 +- confluent_server/confluent/netutil.py | 10 +++++++--- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/confluent_server/confluent/config/attributes.py b/confluent_server/confluent/config/attributes.py index 392ff11b..28ff23c1 100644 --- a/confluent_server/confluent/config/attributes.py +++ b/confluent_server/confluent/config/attributes.py @@ -413,8 +413,10 @@ node = { }, 'net.ipv4_method': { 'description': 'Whether to use static or dhcp when configuring this ' - 'interface for IPv4.', - 'validvalues': ('dhcp', 'static', 'none') + 'interface for IPv4. "firmwaredhcp" means to defer to ' + 'external DHCP server during firmware execution, but ' + 'use static for OS', + 'validvalues': ('dhcp', 'static', 'firmwaredhcp', 'none') }, 'net.ipv4_gateway': { 'description': 'The IPv4 gateway to use if applicable. As is the ' diff --git a/confluent_server/confluent/discovery/protocols/pxe.py b/confluent_server/confluent/discovery/protocols/pxe.py index f60f26e5..e099b5c3 100644 --- a/confluent_server/confluent/discovery/protocols/pxe.py +++ b/confluent_server/confluent/discovery/protocols/pxe.py @@ -482,7 +482,7 @@ def check_reply(node, info, packet, sock, cfg, reqview): # Received a request over a nic with no ipv4 configured, ignore it return clipn = None - if niccfg['ipv4_address']: + if niccfg['ipv4_address'] and niccfg['ipv4_method'] != 'firmwaredhcp': clipn = socket.inet_aton(niccfg['ipv4_address']) repview[16:20] = clipn gateway = niccfg['ipv4_gateway'] diff --git a/confluent_server/confluent/netutil.py b/confluent_server/confluent/netutil.py index 9130d6a6..8fae677a 100644 --- a/confluent_server/confluent/netutil.py +++ b/confluent_server/confluent/netutil.py @@ -184,17 +184,21 @@ def get_nic_config(configmanager, node, ip=None, mac=None, ifidx=None, needsvrip = True dhcprequested = False nets = list(myiptonets(serverip)) + genericmethod = 'static' if nets is not None: candgws = [] candsrvs = [] for net in nets: net, prefix, svrip = net + ipmethod = cfgbyname[candidate].get('ipv4_method', 'static') candsrvs.append(svrip) cfgdata['deploy_server'] = svrip for candidate in cfgbyname: - if cfgbyname[candidate].get('ipv4_method', None) == 'dhcp': + if ipmethod == 'dhcp': dhcprequested = True continue + if ipmethod == 'firmwaredhcp': + genericmethod = ipmethod candip = cfgbyname[candidate].get('ipv4_address', None) if candip and '/' in candip: candip, candprefix = candip.split('/') @@ -205,7 +209,7 @@ def get_nic_config(configmanager, node, ip=None, mac=None, ifidx=None, try: if ip_on_same_subnet(net, candip, prefix): cfgdata['ipv4_address'] = candip - cfgdata['ipv4_method'] = 'static' + cfgdata['ipv4_method'] = ipmethod cfgdata['ipv4_gateway'] = cfgbyname[candidate].get( 'ipv4_gateway', None) cfgdata['prefix'] = prefix @@ -228,7 +232,7 @@ def get_nic_config(configmanager, node, ip=None, mac=None, ifidx=None, if ip_on_same_subnet(net, ipbynodename, prefix): cfgdata['matchesnodename'] = True cfgdata['ipv4_address'] = ipbynodename - cfgdata['ipv4_method'] = 'static' + cfgdata['ipv4_method'] = genericmethod cfgdata['prefix'] = prefix break for svr in candsrvs: