summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJiří Klimeš <jklimes@redhat.com>2014-10-27 11:03:19 +0100
committerJiří Klimeš <jklimes@redhat.com>2014-10-27 13:02:53 +0100
commit41cc06ecfd0e596c526f7dea184f49d9a87025f9 (patch)
tree852806be5789cd3c248eaf8d9d19f79ab22206d8
parent21245d1be3df8e257ff7f3c8eb29b28c297de52b (diff)
downloadNetworkManager-jk/nmcli-editor-normalize.tar.gz
cli: add 'verify fix' command for nmcli connection editorjk/nmcli-editor-normalize
Some connection verification errors are normalizable by NetworkManager. Allow users to normalize the connection using one command.
-rw-r--r--clients/cli/connections.c33
1 files changed, 26 insertions, 7 deletions
diff --git a/clients/cli/connections.c b/clients/cli/connections.c
index 4358e08386..bedd5ba766 100644
--- a/clients/cli/connections.c
+++ b/clients/cli/connections.c
@@ -5388,7 +5388,7 @@ gen_func_bool_values (const char *text, int state)
static char *
gen_cmd_verify0 (const char *text, int state)
{
- const char *words[] = { "all", NULL };
+ const char *words[] = { "all", "fix", NULL };
return nmc_rl_gen_func_basic (text, state, words);
}
@@ -6105,7 +6105,7 @@ editor_main_usage (void)
"set [<setting>.<prop> <value>] :: set property value\n"
"describe [<setting>.<prop>] :: describe property\n"
"print [all | <setting>[.<prop>]] :: print the connection\n"
- "verify [all] :: verify the connection\n"
+ "verify [all | fix] :: verify the connection\n"
"save [persistent|temporary] :: save the connection\n"
"activate [<ifname>] [/<ap>|<nsp>] :: activate the connection\n"
"back :: go one level up (back)\n"
@@ -6155,10 +6155,12 @@ editor_main_help (const char *command)
"Example: nmcli ipv4> print all\n"));
break;
case NMC_EDITOR_MAIN_CMD_VERIFY:
- g_print (_("verify [all] :: verify setting or connection validity\n\n"
- "Verifies whether the setting or connection is valid and can "
- "be saved later. It indicates invalid values on error.\n\n"
+ g_print (_("verify [all | fix] :: verify setting or connection validity\n\n"
+ "Verifies whether the setting or connection is valid and can be saved later.\n"
+ "It indicates invalid values on error. Some errors may be fixed automatically\n"
+ "by 'fix' option.\n\n"
"Examples: nmcli> verify\n"
+ " nmcli> verify fix\n"
" nmcli bond> verify\n"));
break;
case NMC_EDITOR_MAIN_CMD_SAVE:
@@ -7397,6 +7399,11 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
case NMC_EDITOR_MAIN_CMD_VERIFY:
/* Verify current setting or the whole connection */
+ if (cmd_arg && strcmp (cmd_arg, "all") && strcmp (cmd_arg, "fix")) {
+ g_print (_("Invalid verify option: %s\n"), cmd_arg);
+ break;
+ }
+
if ( menu_ctx.curr_setting
&& (!cmd_arg || strcmp (cmd_arg, "all") != 0)) {
GError *tmp_err = NULL;
@@ -7407,9 +7414,19 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
g_clear_error (&tmp_err);
} else {
GError *tmp_err = NULL;
- (void) nm_connection_verify (connection, &tmp_err);
+ gboolean valid, modified;
+ gboolean fixed = TRUE;
+
+ valid = nm_connection_verify (connection, &tmp_err);
+ if (!valid && (g_strcmp0 (cmd_arg, "fix") == 0)) {
+ /* Try to fix normalizable errors */
+ g_clear_error (&tmp_err);
+ fixed = nm_connection_normalize (connection, NULL, &modified, &tmp_err);
+ }
g_print (_("Verify connection: %s\n"),
tmp_err ? tmp_err->message : "OK");
+ if (!fixed)
+ g_print (_("The error cannot be fixed automatically.\n"));
g_clear_error (&tmp_err);
}
break;
@@ -7499,9 +7516,11 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
nmc_editor_cb_called = FALSE;
nmc_editor_error = NULL;
g_mutex_unlock (&nmc_editor_mutex);
- } else
+ } else {
g_print (_("Error: connection verification failed: %s\n"),
err1 ? err1->message : _("(unknown error)"));
+ g_print (_("You may try running 'verify fix' to fix errors.\n"));
+ }
g_clear_error (&err1);
break;