Re: Programmatically manage no-auto-default.state file?

2022-08-10 Thread Thomas Haller via networkmanager-list
On Wed, 2022-08-10 at 18:44 +0300, Andrei Borzenkov wrote:
> On 10.08.2022 13:09, Thomas Haller wrote:
> > On Wed, 2022-08-10 at 09:01 +0300, Andrei Borzenkov via
> > networkmanager-
> > list wrote:
> > > When automatic connection is deleted/modified, interface is added
> > > to
> > > /var/lib/NetworkManager/no-auto-default.state. Is there any
> > > device
> > > property to show "no-auto-default" state? Is there any command/D-
> > > Bus
> > > API
> > > to remove interface from this list?
> > 
> > 
> > there is no such API.
> > 
> > I guess you can delete the file, or modify it with "sed". That gets
> > complicated, because NetworkManager only loads the file ones and
> > writes
> > it anew at unpredictable times. To get it right, you'd have to stop
> > NM,
> > modify the file, start NM.
> > 
> > Btw, `sudo NetworkManager --print-config` prints the content of the
> > no-
> > auto-default.state flag. Note that as NetworkManager loads the file
> > only once and remembers it, the running NetworkManager may not have
> > cached what --print-config shows.
> > 
> 
> OK, thanks. I overlooked this option.
> 
> > 
> > Why do you want that?
> > 
> 
> Mostly to reset NetworkManager state to clean default. Usually it is
> frowned upon direct editing of internal state files and this file is
> certainly internal state.

That's a good choice to avoid internal state.

In practice, the files in /var/lib/NetworkManager are reasonably
simple. So if you edit them with the current understanding of how it is
structured, also when upgrading to a newer NetworkManager version it
must still work. That is, because when upgrading to a new
NetworkManager version, NetworkManager must cope with the current form
of those files anyway and it cannot break behavior in a bad way anyway.
So while this is not stable API, we must reasonably stick to the
behavior in the future.

The bigger problem is that NetworkManager reads and writes those files
at unpredicatable times. The only really correct way to handle it is by
first stopping NetworkManager, the modifying the files, then
(re)starting NetworkManager.

> 
> If you say that editing it is OK it is fine for me.
> 

To forget the state as if it were a reboot, delete /run/NetworkManager.
To forget the state as if it were a factory reset, delete
/var/lib/NetworkManager and /etc/NetworkManager.

Graned, your distro might install some files in /etc/NetworkManager.
Possibly it should avoid that. But it means you might want to take care
before wiping /etc/NeworkManager. NetworkManager itself is fine to
start without empty /etc/NetworkManager.



Thomas

___
networkmanager-list mailing list
networkmanager-list@gnome.org
https://mail.gnome.org/mailman/listinfo/networkmanager-list


Re: Programmatically manage no-auto-default.state file?

2022-08-10 Thread Andrei Borzenkov via networkmanager-list
On 10.08.2022 13:09, Thomas Haller wrote:
> On Wed, 2022-08-10 at 09:01 +0300, Andrei Borzenkov via networkmanager-
> list wrote:
>> When automatic connection is deleted/modified, interface is added to
>> /var/lib/NetworkManager/no-auto-default.state. Is there any device
>> property to show "no-auto-default" state? Is there any command/D-Bus
>> API
>> to remove interface from this list?
> 
> 
> there is no such API.
> 
> I guess you can delete the file, or modify it with "sed". That gets
> complicated, because NetworkManager only loads the file ones and writes
> it anew at unpredictable times. To get it right, you'd have to stop NM,
> modify the file, start NM.
> 
> Btw, `sudo NetworkManager --print-config` prints the content of the no-
> auto-default.state flag. Note that as NetworkManager loads the file
> only once and remembers it, the running NetworkManager may not have
> cached what --print-config shows.
> 

OK, thanks. I overlooked this option.

> 
> Why do you want that?
> 

Mostly to reset NetworkManager state to clean default. Usually it is
frowned upon direct editing of internal state files and this file is
certainly internal state.

If you say that editing it is OK it is fine for me.
___
networkmanager-list mailing list
networkmanager-list@gnome.org
https://mail.gnome.org/mailman/listinfo/networkmanager-list


Re: Programmatically manage no-auto-default.state file?

2022-08-10 Thread Thomas Haller via networkmanager-list
On Wed, 2022-08-10 at 09:01 +0300, Andrei Borzenkov via networkmanager-
list wrote:
> When automatic connection is deleted/modified, interface is added to
> /var/lib/NetworkManager/no-auto-default.state. Is there any device
> property to show "no-auto-default" state? Is there any command/D-Bus
> API
> to remove interface from this list?


there is no such API.

I guess you can delete the file, or modify it with "sed". That gets
complicated, because NetworkManager only loads the file ones and writes
it anew at unpredictable times. To get it right, you'd have to stop NM,
modify the file, start NM.

Btw, `sudo NetworkManager --print-config` prints the content of the no-
auto-default.state flag. Note that as NetworkManager loads the file
only once and remembers it, the running NetworkManager may not have
cached what --print-config shows.


Why do you want that?

"no-auto-default" flag prevents the creation of the "Wired connection
1" profiles. The "Wired connection 1" profile gets generated for
ethernet (depending on "no-auto-default" setting), so that you could
boot a unconfigured machine, and it would connect automatically. E.g.
if you boot a new VM, that it connects using DHCP.

The device ends up in /var/lib/NetworkManager/no-auto-default.state
because the user manually deleted or modified the generated "Wired
connection 1". If the user did so already, then they are already "on
the machine" and messed with it. At this point, if the user wants a
profile, they can just create one and don't need to rely on "Wired
connection 1". There is no other magic to "Wired connection 1".


Thomas

___
networkmanager-list mailing list
networkmanager-list@gnome.org
https://mail.gnome.org/mailman/listinfo/networkmanager-list


Programmatically manage no-auto-default.state file?

2022-08-10 Thread Andrei Borzenkov via networkmanager-list
When automatic connection is deleted/modified, interface is added to
/var/lib/NetworkManager/no-auto-default.state. Is there any device
property to show "no-auto-default" state? Is there any command/D-Bus API
to remove interface from this list?

___
networkmanager-list mailing list
networkmanager-list@gnome.org
https://mail.gnome.org/mailman/listinfo/networkmanager-list