cli: add NMC_RESULT_ERROR_NOT_FOUND and use as appropriate
This will allow callers to distinguish "no such connection" from "connection failed to activate", etc. https://bugzilla.redhat.com/show_bug.cgi?id=1022256
This commit is contained in:
@@ -536,7 +536,7 @@ do_connections_show (NmCli *nmc, int argc, char **argv)
|
|||||||
printed = nmc_connection_detail (con, nmc);
|
printed = nmc_connection_detail (con, nmc);
|
||||||
} else {
|
} else {
|
||||||
g_string_printf (nmc->return_text, _("Error: %s - no such connection."), *argv);
|
g_string_printf (nmc->return_text, _("Error: %s - no such connection."), *argv);
|
||||||
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
|
nmc->return_value = NMC_RESULT_ERROR_NOT_FOUND;
|
||||||
return nmc->return_value;
|
return nmc->return_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1065,7 +1065,7 @@ do_connections_show_active (NmCli *nmc, int argc, char **argv)
|
|||||||
printed = nmc_active_connection_detail (acon, nmc); /* separate connections by blank line */
|
printed = nmc_active_connection_detail (acon, nmc); /* separate connections by blank line */
|
||||||
} else {
|
} else {
|
||||||
g_string_printf (nmc->return_text, _("Error: '%s' is not an active connection."), *argv);
|
g_string_printf (nmc->return_text, _("Error: '%s' is not an active connection."), *argv);
|
||||||
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
|
nmc->return_value = NMC_RESULT_ERROR_NOT_FOUND;
|
||||||
return nmc->return_value;
|
return nmc->return_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1536,12 +1536,12 @@ nmc_activate_connection (NmCli *nmc,
|
|||||||
} else if (ifname) {
|
} else if (ifname) {
|
||||||
device = nm_client_get_device_by_iface (nmc->client, ifname);
|
device = nm_client_get_device_by_iface (nmc->client, ifname);
|
||||||
if (!device) {
|
if (!device) {
|
||||||
g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_CON_ACTIVATION,
|
g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_NOT_FOUND,
|
||||||
_("unknown device '%s'."), ifname);
|
_("unknown device '%s'."), ifname);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
g_set_error_literal (error, NMCLI_ERROR, NMC_RESULT_ERROR_CON_ACTIVATION,
|
g_set_error_literal (error, NMCLI_ERROR, NMC_RESULT_ERROR_NOT_FOUND,
|
||||||
_("neither a valid connection nor device given"));
|
_("neither a valid connection nor device given"));
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@@ -1662,7 +1662,7 @@ do_connection_up (NmCli *nmc, int argc, char **argv)
|
|||||||
if (!nmc_activate_connection (nmc, connection, ifname, ap, nsp, activate_connection_cb, &error)) {
|
if (!nmc_activate_connection (nmc, connection, ifname, ap, nsp, activate_connection_cb, &error)) {
|
||||||
g_string_printf (nmc->return_text, _("Error: %s."),
|
g_string_printf (nmc->return_text, _("Error: %s."),
|
||||||
error ? error->message : _("unknown error"));
|
error ? error->message : _("unknown error"));
|
||||||
nmc->return_value = NMC_RESULT_ERROR_CON_ACTIVATION;
|
nmc->return_value = error ? error->code : NMC_RESULT_ERROR_CON_ACTIVATION;
|
||||||
g_clear_error (&error);
|
g_clear_error (&error);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
@@ -1734,7 +1734,7 @@ do_connection_down (NmCli *nmc, int argc, char **argv)
|
|||||||
nm_client_deactivate_connection (nmc->client, active);
|
nm_client_deactivate_connection (nmc->client, active);
|
||||||
} else {
|
} else {
|
||||||
g_string_printf (nmc->return_text, _("Error: '%s' is not an active connection."), *arg_ptr);
|
g_string_printf (nmc->return_text, _("Error: '%s' is not an active connection."), *arg_ptr);
|
||||||
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
|
nmc->return_value = NMC_RESULT_ERROR_NOT_FOUND;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -7018,7 +7018,7 @@ do_connection_edit (NmCli *nmc, int argc, char **argv)
|
|||||||
found_con = find_connection (nmc->system_connections, selector, con);
|
found_con = find_connection (nmc->system_connections, selector, con);
|
||||||
if (!found_con) {
|
if (!found_con) {
|
||||||
g_string_printf (nmc->return_text, _("Error: Unknown connection '%s'."), con);
|
g_string_printf (nmc->return_text, _("Error: Unknown connection '%s'."), con);
|
||||||
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
nmc->return_value = NMC_RESULT_ERROR_NOT_FOUND;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -7214,7 +7214,7 @@ do_connection_modify (NmCli *nmc, int argc, char **argv)
|
|||||||
connection = find_connection (nmc->system_connections, selector, name);
|
connection = find_connection (nmc->system_connections, selector, name);
|
||||||
if (!connection) {
|
if (!connection) {
|
||||||
g_string_printf (nmc->return_text, _("Error: Unknown connection '%s'."), name);
|
g_string_printf (nmc->return_text, _("Error: Unknown connection '%s'."), name);
|
||||||
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
nmc->return_value = NMC_RESULT_ERROR_NOT_FOUND;
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
strv = g_strsplit (set_prop, ".", 2);
|
strv = g_strsplit (set_prop, ".", 2);
|
||||||
@@ -7397,7 +7397,7 @@ finish:
|
|||||||
g_string_truncate (invalid_cons, invalid_cons->len-2); /* truncate trailing ", " */
|
g_string_truncate (invalid_cons, invalid_cons->len-2); /* truncate trailing ", " */
|
||||||
g_string_printf (nmc->return_text, _("Error: cannot delete unknown connection(s): %s."),
|
g_string_printf (nmc->return_text, _("Error: cannot delete unknown connection(s): %s."),
|
||||||
invalid_cons->str);
|
invalid_cons->str);
|
||||||
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
nmc->return_value = NMC_RESULT_ERROR_NOT_FOUND;
|
||||||
g_string_free (invalid_cons, TRUE);
|
g_string_free (invalid_cons, TRUE);
|
||||||
}
|
}
|
||||||
return nmc->return_value;
|
return nmc->return_value;
|
||||||
|
@@ -1124,7 +1124,7 @@ do_devices_show (NmCli *nmc, int argc, char **argv)
|
|||||||
}
|
}
|
||||||
if (!device) {
|
if (!device) {
|
||||||
g_string_printf (nmc->return_text, _("Error: Device '%s' not found."), ifname);
|
g_string_printf (nmc->return_text, _("Error: Device '%s' not found."), ifname);
|
||||||
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
|
nmc->return_value = NMC_RESULT_ERROR_NOT_FOUND;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
show_device_info (device, nmc);
|
show_device_info (device, nmc);
|
||||||
@@ -1279,7 +1279,7 @@ do_device_connect (NmCli *nmc, int argc, char **argv)
|
|||||||
|
|
||||||
if (!device) {
|
if (!device) {
|
||||||
g_string_printf (nmc->return_text, _("Error: Device '%s' not found."), ifname);
|
g_string_printf (nmc->return_text, _("Error: Device '%s' not found."), ifname);
|
||||||
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
|
nmc->return_value = NMC_RESULT_ERROR_NOT_FOUND;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1414,7 +1414,7 @@ do_device_disconnect (NmCli *nmc, int argc, char **argv)
|
|||||||
|
|
||||||
if (!device) {
|
if (!device) {
|
||||||
g_string_printf (nmc->return_text, _("Error: Device '%s' not found."), ifname);
|
g_string_printf (nmc->return_text, _("Error: Device '%s' not found."), ifname);
|
||||||
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
|
nmc->return_value = NMC_RESULT_ERROR_NOT_FOUND;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1557,7 +1557,7 @@ do_device_wifi_list (NmCli *nmc, int argc, char **argv)
|
|||||||
}
|
}
|
||||||
if (!device) {
|
if (!device) {
|
||||||
g_string_printf (nmc->return_text, _("Error: Device '%s' not found."), ifname);
|
g_string_printf (nmc->return_text, _("Error: Device '%s' not found."), ifname);
|
||||||
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
|
nmc->return_value = NMC_RESULT_ERROR_NOT_FOUND;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1581,7 +1581,7 @@ do_device_wifi_list (NmCli *nmc, int argc, char **argv)
|
|||||||
if (!ap) {
|
if (!ap) {
|
||||||
g_string_printf (nmc->return_text, _("Error: Access point with bssid '%s' not found."),
|
g_string_printf (nmc->return_text, _("Error: Access point with bssid '%s' not found."),
|
||||||
bssid_user);
|
bssid_user);
|
||||||
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
|
nmc->return_value = NMC_RESULT_ERROR_NOT_FOUND;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
/* Add headers (field names) */
|
/* Add headers (field names) */
|
||||||
@@ -1650,7 +1650,7 @@ do_device_wifi_list (NmCli *nmc, int argc, char **argv)
|
|||||||
if (!ap) {
|
if (!ap) {
|
||||||
g_string_printf (nmc->return_text, _("Error: Access point with bssid '%s' not found."),
|
g_string_printf (nmc->return_text, _("Error: Access point with bssid '%s' not found."),
|
||||||
bssid_user);
|
bssid_user);
|
||||||
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
|
nmc->return_value = NMC_RESULT_ERROR_NOT_FOUND;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -2014,7 +2014,7 @@ do_device_wifi_connect_network (NmCli *nmc, int argc, char **argv)
|
|||||||
g_string_printf (nmc->return_text, _("Error: No network with SSID '%s' found."), param_user);
|
g_string_printf (nmc->return_text, _("Error: No network with SSID '%s' found."), param_user);
|
||||||
else
|
else
|
||||||
g_string_printf (nmc->return_text, _("Error: No access point with BSSID '%s' found."), param_user);
|
g_string_printf (nmc->return_text, _("Error: No access point with BSSID '%s' found."), param_user);
|
||||||
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
|
nmc->return_value = NMC_RESULT_ERROR_NOT_FOUND;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2301,7 +2301,7 @@ do_device_wimax_list (NmCli *nmc, int argc, char **argv)
|
|||||||
|
|
||||||
if (!device) {
|
if (!device) {
|
||||||
g_string_printf (nmc->return_text, _("Error: Device '%s' not found."), ifname);
|
g_string_printf (nmc->return_text, _("Error: Device '%s' not found."), ifname);
|
||||||
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
|
nmc->return_value = NMC_RESULT_ERROR_NOT_FOUND;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2324,7 +2324,7 @@ do_device_wimax_list (NmCli *nmc, int argc, char **argv)
|
|||||||
}
|
}
|
||||||
if (!nsp) {
|
if (!nsp) {
|
||||||
g_string_printf (nmc->return_text, _("Error: NSP with name '%s' not found."), nsp_user);
|
g_string_printf (nmc->return_text, _("Error: NSP with name '%s' not found."), nsp_user);
|
||||||
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
|
nmc->return_value = NMC_RESULT_ERROR_NOT_FOUND;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
/* Add headers (field names) */
|
/* Add headers (field names) */
|
||||||
@@ -2375,7 +2375,7 @@ do_device_wimax_list (NmCli *nmc, int argc, char **argv)
|
|||||||
}
|
}
|
||||||
if (!nsp) {
|
if (!nsp) {
|
||||||
g_string_printf (nmc->return_text, _("Error: Access point with nsp '%s' not found."), nsp_user);
|
g_string_printf (nmc->return_text, _("Error: Access point with nsp '%s' not found."), nsp_user);
|
||||||
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
|
nmc->return_value = NMC_RESULT_ERROR_NOT_FOUND;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@@ -55,7 +55,10 @@ typedef enum {
|
|||||||
NMC_RESULT_ERROR_NM_NOT_RUNNING = 8,
|
NMC_RESULT_ERROR_NM_NOT_RUNNING = 8,
|
||||||
|
|
||||||
/* nmcli and NetworkManager versions mismatch */
|
/* nmcli and NetworkManager versions mismatch */
|
||||||
NMC_RESULT_ERROR_VERSIONS_MISMATCH = 9
|
NMC_RESULT_ERROR_VERSIONS_MISMATCH = 9,
|
||||||
|
|
||||||
|
/* Connection/Device/AP not found */
|
||||||
|
NMC_RESULT_ERROR_NOT_FOUND = 10
|
||||||
} NMCResultCode;
|
} NMCResultCode;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
@@ -755,6 +755,8 @@ Connection deletion failed
|
|||||||
NetworkManager is not running
|
NetworkManager is not running
|
||||||
.IP "9" 4
|
.IP "9" 4
|
||||||
\fInmcli\fP and \fINetworkManager\fP versions mismatch
|
\fInmcli\fP and \fINetworkManager\fP versions mismatch
|
||||||
|
.IP "10" 4
|
||||||
|
Connection, device, or access point does not exist.
|
||||||
|
|
||||||
.SH EXAMPLES
|
.SH EXAMPLES
|
||||||
.PP
|
.PP
|
||||||
|
Reference in New Issue
Block a user