@@ -176,9 +176,12 @@ def command_apply(self, run_generate=True, sync=False, exit_on_error=True, state
176176 else :
177177 logging .debug ('no netplan generated networkd configuration exists' )
178178
179+ loopback_connection = ''
179180 if restart_nm :
180181 logging .debug ('netplan generated NM configuration changed, restarting NM' )
181182 if utils .nm_running ():
183+ if 'lo' in nm_ifaces :
184+ loopback_connection = utils .nm_get_connection_for_interface ('lo' )
182185 # restarting NM does not cause new config to be applied, need to shut down devices first
183186 for device in devices :
184187 if device not in nm_ifaces :
@@ -293,8 +296,10 @@ def command_apply(self, run_generate=True, sync=False, exit_on_error=True, state
293296 # re-set via an udev rule setting "NM_UNMANAGED=1"
294297 shutil .rmtree ('/run/NetworkManager/devices' , ignore_errors = True )
295298 utils .systemctl_network_manager ('start' , sync = sync )
296- # If 'lo' is in the nm_interfaces set we flushed it's IPs (see above) and will need to bring it
297- # back manually. For that, we need NM up and ready to accept commands
299+
300+ # If 'lo' is in the nm_interfaces set we flushed it's IPs (see above) and disconnected it.
301+ # NM will not bring it back automatically after restarting and we need to do that manually.
302+ # For that, we need NM up and ready to accept commands
298303 if 'lo' in nm_interfaces :
299304 sync = True
300305
@@ -315,13 +320,12 @@ def command_apply(self, run_generate=True, sync=False, exit_on_error=True, state
315320 break
316321 time .sleep (0.5 )
317322
318- # If "lo" is managed by NM through Netplan, apply will flush its addresses and NM
319- # will not bring it back automatically like other connections .
323+ # If "lo" is managed by NM through Netplan, apply will flush its addresses and disconnect it.
324+ # NM will not bring it back automatically.
320325 # This is a possible scenario with netplan-everywhere. If a user tries to change the 'lo'
321326 # connection with nmcli for example, NM will create a persistent nmconnection file and emit a YAML for it.
322- if 'lo' in nm_interfaces :
323- cmd = ['nmcli' , 'con' , 'up' , 'lo' ]
324- subprocess .call (cmd , stdout = subprocess .DEVNULL , stderr = subprocess .DEVNULL )
327+ if 'lo' in nm_interfaces and loopback_connection :
328+ utils .nm_bring_interface_up (loopback_connection )
325329
326330 @staticmethod
327331 def is_composite_member (composites , phy ):
0 commit comments