summaryrefslogtreecommitdiff
path: root/cloudinit
diff options
context:
space:
mode:
authorWaleed Mousa <32266980+wmousa@users.noreply.github.com>2023-03-22 18:45:33 +0200
committerGitHub <noreply@github.com>2023-03-22 10:45:33 -0600
commit7f91bdea4c684fb0ae12489751a1343261a9ca93 (patch)
tree7e2551add9751ebe7061b61571636d694d810d6f /cloudinit
parent85b2fbc2a811d6efb703284bea93b35c5cdd4135 (diff)
downloadcloud-init-git-7f91bdea4c684fb0ae12489751a1343261a9ca93.tar.gz
Send dhcp-client-identifier for InfiniBand ports (#2043)
Sending dhclient command failed for InfiniBand ports because dhcp-client-identifier is not specified. So, providing this patch to allow send dhcp-client-identifier hardware with the dhclient command for InfiniBand ports. Signed-off-by: waleedm <waleedm@nvidia.com>
Diffstat (limited to 'cloudinit')
-rw-r--r--cloudinit/net/__init__.py4
-rw-r--r--cloudinit/net/dhcp.py24
2 files changed, 26 insertions, 2 deletions
diff --git a/cloudinit/net/__init__.py b/cloudinit/net/__init__.py
index 244305d1..65d45edf 100644
--- a/cloudinit/net/__init__.py
+++ b/cloudinit/net/__init__.py
@@ -167,6 +167,10 @@ def master_is_openvswitch(devname):
return os.path.exists(ovs_path)
+def is_ib_interface(devname):
+ return read_sys_net_safe(devname, "type") == "32"
+
+
@functools.lru_cache(maxsize=None)
def openvswitch_is_installed() -> bool:
"""Return a bool indicating if Open vSwitch is installed in the system."""
diff --git a/cloudinit/net/dhcp.py b/cloudinit/net/dhcp.py
index 661b9848..a8949ebc 100644
--- a/cloudinit/net/dhcp.py
+++ b/cloudinit/net/dhcp.py
@@ -14,8 +14,13 @@ from io import StringIO
import configobj
-from cloudinit import subp, util
-from cloudinit.net import find_fallback_nic, get_devicelist
+from cloudinit import subp, temp_utils, util
+from cloudinit.net import (
+ find_fallback_nic,
+ get_devicelist,
+ get_interface_mac,
+ is_ib_interface,
+)
LOG = logging.getLogger(__name__)
@@ -136,6 +141,9 @@ def dhcp_discovery(dhclient_cmd_path, interface, dhcp_log_func=None):
# link up before attempting discovery. Since we are using -sf /bin/true,
# we need to do that "link up" ourselves first.
subp.subp(["ip", "link", "set", "dev", interface, "up"], capture=True)
+ # For INFINIBAND port the dhlient must be sent with dhcp-client-identifier.
+ # So here we are checking if the interface is INFINIBAND or not.
+ # If yes, we are generating the the client-id to be used with the dhclient
cmd = [
dhclient_cmd_path,
"-1",
@@ -148,6 +156,18 @@ def dhcp_discovery(dhclient_cmd_path, interface, dhcp_log_func=None):
"-sf",
"/bin/true",
]
+ if is_ib_interface(interface):
+ dhcp_client_identifier = "20:%s" % get_interface_mac(interface)[36:]
+ interface_dhclient_content = (
+ 'interface "%s" '
+ "{send dhcp-client-identifier %s;}"
+ % (interface, dhcp_client_identifier)
+ )
+ tmp_dir = temp_utils.get_tmp_ancestor(needs_exe=True)
+ file_name = os.path.join(tmp_dir, interface + "-dhclient.conf")
+ util.write_file(file_name, interface_dhclient_content)
+ cmd.append("-cf")
+ cmd.append(file_name)
out, err = subp.subp(cmd, capture=True)
# Wait for pid file and lease file to appear, and for the process