From 41cc06ecfd0e596c526f7dea184f49d9a87025f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= Date: Mon, 27 Oct 2014 11:03:19 +0100 Subject: cli: add 'verify fix' command for nmcli connection editor Some connection verification errors are normalizable by NetworkManager. Allow users to normalize the connection using one command. --- clients/cli/connections.c | 33 ++++++++++++++++++++++++++------- 1 file 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 [. ] :: set property value\n" "describe [.] :: describe property\n" "print [all | [.]] :: 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 [] [/|] :: 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; -- cgit v1.2.1