diff --git a/cli/src/connections.c b/cli/src/connections.c index 9e4cefe57f..656d6c9a6a 100644 --- a/cli/src/connections.c +++ b/cli/src/connections.c @@ -344,6 +344,7 @@ usage_connection_add (void) " ifname | \"*\"\n" " [con-name ]\n" " [autoconnect yes|no]\n\n" + " [save yes|no]\n\n" " TYPE_SPECIFIC_OPTIONS:\n" " ethernet: [mac ]\n" " [cloned-mac ]\n" @@ -4930,6 +4931,19 @@ add_connection_cb (NMRemoteSettings *settings, quit (); } +static gboolean +add_new_connection (gboolean persistent, + NMRemoteSettings *settings, + NMConnection *connection, + NMRemoteSettingsAddConnectionFunc callback, + gpointer user_data) +{ + if (persistent) + return nm_remote_settings_add_connection (settings, connection, callback, user_data); + else + return nm_remote_settings_add_connection_unsaved (settings, connection, callback, user_data); +} + static NMCResultCode do_connection_add (NmCli *nmc, int argc, char **argv) { @@ -4945,6 +4959,8 @@ do_connection_add (NmCli *nmc, int argc, char **argv) const char *ifname = NULL; char *ifname_ask = NULL; gboolean ifname_mandatory = TRUE; + const char *save = NULL; + gboolean save_bool = TRUE; AddConnectionInfo *info = NULL; const char *setting_name; GError *error = NULL; @@ -4952,6 +4968,7 @@ do_connection_add (NmCli *nmc, int argc, char **argv) {"con-name", TRUE, &con_name, FALSE}, {"autoconnect", TRUE, &autoconnect, FALSE}, {"ifname", TRUE, &ifname, FALSE}, + {"save", TRUE, &save, FALSE}, {NULL} }; nmc->return_value = NMC_RESULT_SUCCESS; @@ -4992,6 +5009,16 @@ do_connection_add (NmCli *nmc, int argc, char **argv) goto error; } } + if (save) { + GError *tmp_err = NULL; + if (!nmc_string_to_bool (save, &save_bool, &tmp_err)) { + g_string_printf (nmc->return_text, _("Error: 'save': %s."), + tmp_err->message); + nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; + g_clear_error (&tmp_err); + goto error; + } + } /* ifname is mandatory for all connection types except virtual ones (bond, team, bridge, vlan) */ if ( strcmp (type, NM_SETTING_BOND_SETTING_NAME) == 0 @@ -5069,10 +5096,11 @@ do_connection_add (NmCli *nmc, int argc, char **argv) info->con_name = g_strdup (nm_connection_get_id (connection)); /* Tell the settings service to add the new connection */ - nm_remote_settings_add_connection (nmc->system_settings, - connection, - add_connection_cb, - info); + add_new_connection (save_bool, + nmc->system_settings, + connection, + add_connection_cb, + info); if (connection) g_object_unref (connection); diff --git a/man/nmcli.1.in b/man/nmcli.1.in index ad3ea656f1..856ebc5158 100644 --- a/man/nmcli.1.in +++ b/man/nmcli.1.in @@ -389,6 +389,8 @@ Note: use quotes around \fB*\fP to suppress shell expansion. \(en connection name (when not provided a default name is generated: [-][-]) .IP "\fI[autoconnect yes|no]\fP" 42 \(en whether the connection profile can be automatically activated (default: yes) +.IP "\fI[save yes|no]\fP" 42 +\(en whether the connection should be persistent, i.e. NetworkManager should store it on disk (default: yes) .RE .RS .TP