diff options
author | Jiří Klimeš <jklimes@redhat.com> | 2014-01-24 11:04:17 +0100 |
---|---|---|
committer | Jiří Klimeš <jklimes@redhat.com> | 2014-01-30 10:49:51 +0100 |
commit | 2d523bd8001231766488c65358e87f5f1433722e (patch) | |
tree | 299900ec4868f374930c91703133232cf1edac45 /cli | |
parent | 97ededafd9ee510c492722cc7b86489714335430 (diff) | |
download | NetworkManager-2d523bd8001231766488c65358e87f5f1433722e.tar.gz |
cli: allow creating temporary (unsaved) connection with 'nmcli con add'
Diffstat (limited to 'cli')
-rw-r--r-- | cli/src/connections.c | 36 |
1 files changed, 32 insertions, 4 deletions
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 <interface name> | \"*\"\n" " [con-name <connection name>]\n" " [autoconnect yes|no]\n\n" + " [save yes|no]\n\n" " TYPE_SPECIFIC_OPTIONS:\n" " ethernet: [mac <MAC address>]\n" " [cloned-mac <cloned MAC address>]\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); |