@@ -80,6 +80,7 @@ def add_static_ip(self, interface_name: str, ip: str) -> None:
8080 logger .info (f"IP { ip } already exists for { interface_name } " )
8181 continue
8282 new_ip = AddressData (address = ip , prefix = 24 )
83+ settings ["ipv4" ]["method" ] = ("s" , "shared" )
8384 data .ipv4 .address_data .append (new_ip )
8485 settings .update_profile (data )
8586 network_manager .activate_connection (connection_path )
@@ -90,13 +91,18 @@ def add_static_ip(self, interface_name: str, ip: str) -> None:
9091 def enable_dhcp_client (self , interface_name : str ) -> None :
9192 networkmanager_settings = NetworkManagerSettings ()
9293 for connection_path in networkmanager_settings .connections :
93- settings = NetworkConnectionSettings (connection_path )
94- properties = settings .get_settings ()
95- if properties ["connection" ]["interface-name" ][1 ] != interface_name :
96- continue
97- properties ["ipv4" ]["method" ] = ("s" , "auto" )
98- settings .update (properties )
99- network_manager .activate_connection (connection_path )
94+ try :
95+ settings = NetworkConnectionSettings (connection_path )
96+ properties = settings .get_settings ()
97+ if properties ["connection" ]["interface-name" ][1 ] != interface_name :
98+ continue
99+ properties ["ipv4" ]["method" ] = ("s" , "shared" )
100+ properties ["ipv4" ]["may-fail" ] = ("b" , True )
101+ settings .update (properties )
102+ settings .save ()
103+ network_manager .activate_connection (connection_path )
104+ except Exception as e :
105+ logger .error (f"Failed to enable DHCP client for { interface_name } : { e } " )
100106
101107 def get_interfaces_priority (self ) -> List [NetworkInterfaceMetric ]:
102108 interfaces = []
0 commit comments