Skip to content

Commit

Permalink
Cable-guy: set ipv4 method to shared and may-fail to true to ensure w…
Browse files Browse the repository at this point in the history
…e always have ips even if DHCP fails
  • Loading branch information
Williangalvani authored and patrickelectric committed Jan 10, 2025
1 parent 154d685 commit 9f56821
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions core/services/cable_guy/networksetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def add_static_ip(self, interface_name: str, ip: str) -> None:
logger.info(f"IP {ip} already exists for {interface_name}")
continue
new_ip = AddressData(address=ip, prefix=24)
settings["ipv4"]["method"] = ("s", "shared")
data.ipv4.address_data.append(new_ip)
settings.update_profile(data)
network_manager.activate_connection(connection_path)
Expand All @@ -90,13 +91,18 @@ def add_static_ip(self, interface_name: str, ip: str) -> None:
def enable_dhcp_client(self, interface_name: str) -> None:
networkmanager_settings = NetworkManagerSettings()
for connection_path in networkmanager_settings.connections:
settings = NetworkConnectionSettings(connection_path)
properties = settings.get_settings()
if properties["connection"]["interface-name"][1] != interface_name:
continue
properties["ipv4"]["method"] = ("s", "auto")
settings.update(properties)
network_manager.activate_connection(connection_path)
try:
settings = NetworkConnectionSettings(connection_path)
properties = settings.get_settings()
if properties["connection"]["interface-name"][1] != interface_name:
continue
properties["ipv4"]["method"] = ("s", "shared")
properties["ipv4"]["may-fail"] = ("b", True)
settings.update(properties)
settings.save()
network_manager.activate_connection(connection_path)
except Exception as e:
logger.error(f"Failed to enable DHCP client for {interface_name}: {e}")

def get_interfaces_priority(self) -> List[NetworkInterfaceMetric]:
interfaces = []
Expand Down

0 comments on commit 9f56821

Please sign in to comment.