On Mon, 2021-04-19 at 10:32 -0700, Abu Rasheda wrote:
Thanks, for the reply! So I have to check manually? no way nmcli saying file exits and quit. (because it will still make a file with name ifcfg-xxx-1 if ifcfg-xxx exist).
Hi, not sure why you ask so much about the filename. If you create the profile via D-Bus API (nmcli, or any of the client tools), then the filename is not well defined. It will be "something" suitable. If you care about the filename, create the file yourself, with the desired name (followed by `nmcli connection reload`). This seems to be more about the name of the connection profile ("connection.id"). But yes, the resulting filename is based on the profile name, with a numeric suffix ("-1") if the name already exists. But more to your question: no, `nmcli connection add` will not fail if a profile with the chosen "connection.id" already exits. It will print a warning about that. If you are an interactive user, then check yourself the existing profiles (and their names) via `nmcli connection`. If you write a script, then script it. E.g. nmcli connection show id "$NAME" &>/dev/null ||nmcli connection add con-name "$NAME" type ... best, Thomas
On Fri, Apr 16, 2021 at 11:27 PM Thomas Haller <thaller redhat com> wrote:On Fri, 2021-04-16 at 17:57 -0700, Abu Rasheda via networkmanager- list wrote:E.g. running the following command multiple times nmcli conn add type ethernet will create multiple files -rw-r--r--. 1 root root 270 Apr 16 20:53 ifcfg-ethernet -rw-r--r--. 1 root root 272 Apr 16 20:54 ifcfg-ethernet-1 Is it possible for nmcli to see that ifcfg-ethernet already existandnot create ifcfg-ethernet-1 How can I pass this message to nmcli ThanksHi, The NetworkManager client tool (like nmcli, or a GUI) in general does not know which file name will be chosen. In the NetworkManager API you can see the file name (like - `nmcli -f all connection` - `nmcli connection up filename "$FILENAME"` - `nmcli connection load "$FILENAME"` but the client tool cannot pre-determine which file name will be used when adding a profile. If you care about the filename, create the file instead of using `nmcli connection add` (followed by `nmcli connection reload`) But is your problem really the filename here? It seems, when you add a new profile, it would be good to choose a name for it, and don't let nmcli automatically choose "ethernet" and "ethernet-1". Just do: nmcli connection add type ethernet con-name xxx "con-name" is an alias for "connection.id", and contrary to what one might reasonably expect, the "id" is not enforced to be unique: $ nmcli connection add type ethernet con-name xxx Connection 'xxx' (7f23f5cd-90f3-4cd8-8612-cf5d0856b130) successfully added. $ nmcli connection add type ethernet con-name xxx Warning: There is another connection with the name 'xxx'. Reference the connection by its uuid '8811722f-d662-48c5-9271-c8aa764d8f4a' Connection 'xxx' (8811722f-d662-48c5-9271-c8aa764d8f4a) successfully added. It's a good idea to ensure yourself that the connection.id is unique. That means, before you add a new profile, check the existing names in `nmcli connection` output and choose a different name. best, Thomas
Attachment:
signature.asc
Description: This is a digitally signed message part