diff options
author | Thomas Haller <thaller@redhat.com> | 2017-07-17 13:57:16 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2017-07-17 14:49:31 +0200 |
commit | f42b4960f8a43ad6ef67c48e9c30b00660546682 (patch) | |
tree | 224187ecc0b5a4d1b21862b0cd76cef2fc9a7abf | |
parent | 45a58c38117bf6e5e13adc77caaef3661b759b00 (diff) |
cli: warn when adding connection with a name that already exists
As far as NetworkManager is concerned, the "connection.id" (also called
"con-name" in nmcli) is a pretty name and does not need to be unique.
UI components usually show the "connection.id" instead of the
"connection.uuid" identifier. It is hence likely, that the user
would not intentionally re-use the same name for multiple connection
profiles.
Print a warning to stderr when the user adds such a connection.
This only affects `nmcli connection add` and `nmcli connection import`,
but not `nmcli connection clone` and not interactive edit mode.
https://bugzilla.redhat.com/show_bug.cgi?id=1460796
-rw-r--r-- | clients/cli/connections.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/clients/cli/connections.c b/clients/cli/connections.c index 26900bd8e1..7f69dddf92 100644 --- a/clients/cli/connections.c +++ b/clients/cli/connections.c @@ -4431,6 +4431,8 @@ add_connection_cb (GObject *client, NmCli *nmc = info->nmc; NMRemoteConnection *connection; GError *error = NULL; + const GPtrArray *connections; + guint i, found; connection = nm_client_add_connection_finish (NM_CLIENT (client), result, &error); if (error) { @@ -4440,6 +4442,28 @@ add_connection_cb (GObject *client, g_error_free (error); nmc->return_value = NMC_RESULT_ERROR_CON_ACTIVATION; } else { + connections = nm_client_get_connections (nmc->client); + if (connections) { + found = 0; + for (i = 0; i < connections->len; i++) { + NMConnection *candidate = NM_CONNECTION (connections->pdata[i]); + + if ((NMConnection *) connection == candidate) + continue; + if (nm_streq0 (nm_connection_get_id (candidate), info->con_name)) + found++; + } + if (found > 0) { + g_printerr (g_dngettext (GETTEXT_PACKAGE, + "Warning: There is another connection with the name '%1$s'. Reference the connection by its uuid '%2$s'\n", + "Warning: There are %3$u other connections with the name '%1$s'. Reference the connection by its uuid '%2$s'\n", + found), + info->con_name, + nm_connection_get_uuid (NM_CONNECTION (connection)), + found); + } + } + g_print (_("Connection '%s' (%s) successfully added.\n"), nm_connection_get_id (NM_CONNECTION (connection)), nm_connection_get_uuid (NM_CONNECTION (connection))); |