Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cable-guy: set ipv4 method to shared and may-fail to true to ensure we always have ips even if DHCP fails #3036

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading