Commit 3560024d authored by Jiří Klimeš's avatar Jiří Klimeš

cli: remove obsolete 'nmcli nm'

The functionality is present in 'general', 'networking' and 'radio'.
We changed syntax anyway, so it doesn't make much sense to keep 'nm'.
parent 3bf97faf
......@@ -61,33 +61,6 @@ static NmcOutputField nmc_fields_nm_status[] = {
#define NMC_FIELDS_NM_WWAN "WWAN"
#define NMC_FIELDS_NM_WIMAX "WIMAX"
/* --- Legacy stuff - kept for backward compatibility only */
/* Available fields for 'nm status' */
static NmcOutputField nmc_fields_nm_status_old[] = {
{"RUNNING", N_("RUNNING"), 15, NULL, 0}, /* 0 */
{"VERSION", N_("VERSION"), 10, NULL, 0}, /* 1 */
{"STATE", N_("STATE"), 15, NULL, 0}, /* 2 */
{"NET-ENABLED", N_("NET-ENABLED"), 13, NULL, 0}, /* 3 */
{"WIFI-HARDWARE", N_("WIFI-HARDWARE"), 15, NULL, 0}, /* 4 */
{"WIFI", N_("WIFI"), 10, NULL, 0}, /* 5 */
{"WWAN-HARDWARE", N_("WWAN-HARDWARE"), 15, NULL, 0}, /* 6 */
{"WWAN", N_("WWAN"), 10, NULL, 0}, /* 7 */
{"WIMAX-HARDWARE", N_("WIMAX-HARDWARE"), 15, NULL, 0}, /* 8 */
{"WIMAX", N_("WIMAX"), 10, NULL, 0}, /* 9 */
{NULL, NULL, 0, NULL, 0}
};
#if WITH_WIMAX
#define NMC_FIELDS_NM_STATUS_ALL_OLD "RUNNING,VERSION,STATE,NET-ENABLED,WIFI-HARDWARE,WIFI,WWAN-HARDWARE,WWAN,WIMAX-HARDWARE,WIMAX"
#else
#define NMC_FIELDS_NM_STATUS_ALL_OLD "RUNNING,VERSION,STATE,NET-ENABLED,WIFI-HARDWARE,WIFI,WWAN-HARDWARE,WWAN"
#endif
#define NMC_FIELDS_NM_STATUS_COMMON_OLD "RUNNING,STATE,WIFI-HARDWARE,WIFI,WWAN-HARDWARE,WWAN"
#define NMC_FIELDS_NM_NET_ENABLED_OLD "NET-ENABLED"
#define NMC_FIELDS_NM_WIFI_OLD "WIFI"
#define NMC_FIELDS_NM_WWAN_OLD "WWAN"
#define NMC_FIELDS_NM_WIMAX_OLD "WIMAX"
/* --- */
/* Available fields for 'general permissions' */
static NmcOutputField nmc_fields_nm_permissions[] = {
......@@ -180,7 +153,7 @@ nm_state_to_string (NMState state)
}
static gboolean
show_nm_status (NmCli *nmc, const char *pretty_header_name, gboolean new_cmd, const char *print_flds)
show_nm_status (NmCli *nmc, const char *pretty_header_name, const char *print_flds)
{
gboolean nm_running;
NMState state = NM_STATE_UNKNOWN;
......@@ -192,8 +165,8 @@ show_nm_status (NmCli *nmc, const char *pretty_header_name, gboolean new_cmd, co
#endif
GError *error = NULL;
const char *fields_str;
const char *fields_all = new_cmd ? (print_flds ? print_flds : NMC_FIELDS_NM_STATUS_ALL) : NMC_FIELDS_NM_STATUS_ALL_OLD;
const char *fields_common = new_cmd ? (print_flds ? print_flds : NMC_FIELDS_NM_STATUS_COMMON) : NMC_FIELDS_NM_STATUS_COMMON_OLD;
const char *fields_all = print_flds ? print_flds : NMC_FIELDS_NM_STATUS_ALL;
const char *fields_common = print_flds ? print_flds : NMC_FIELDS_NM_STATUS_COMMON;
guint32 mode_flag = (nmc->print_output == NMC_PRINT_PRETTY) ? NMC_PF_FLAG_PRETTY : (nmc->print_output == NMC_PRINT_TERSE) ? NMC_PF_FLAG_TERSE : 0;
guint32 multiline_flag = nmc->multiline_output ? NMC_PF_FLAG_MULTILINE : 0;
guint32 escape_flag = nmc->escape_values ? NMC_PF_FLAG_ESCAPE : 0;
......@@ -205,7 +178,7 @@ show_nm_status (NmCli *nmc, const char *pretty_header_name, gboolean new_cmd, co
else
fields_str = nmc->required_fields;
nmc->allowed_fields = new_cmd ? nmc_fields_nm_status : nmc_fields_nm_status_old;
nmc->allowed_fields = nmc_fields_nm_status;
nmc->print_fields.indices = parse_output_fields (fields_str, nmc->allowed_fields, &error);
if (error) {
......@@ -440,42 +413,6 @@ show_general_logging (NmCli *nmc)
return TRUE;
}
/* libnm-glib doesn't provide API fro Sleep method - implement D-Bus call ourselves */
static void networking_set_sleep (NmCli *nmc, gboolean in_sleep)
{
DBusGConnection *connection = NULL;
DBusGProxy *proxy = NULL;
GError *err = NULL;
connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &err);
if (!connection) {
g_string_printf (nmc->return_text, _("Error: Couldn't connect to system bus: %s"), err->message);
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
g_error_free (err);
goto gone;
}
proxy = dbus_g_proxy_new_for_name (connection,
"org.freedesktop.NetworkManager",
"/org/freedesktop/NetworkManager",
"org.freedesktop.NetworkManager");
if (!proxy) {
g_string_printf (nmc->return_text, _("Error: Couldn't create D-Bus object proxy."));
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
goto gone;
}
if (!dbus_g_proxy_call (proxy, "Sleep", &err, G_TYPE_BOOLEAN, in_sleep, G_TYPE_INVALID, G_TYPE_INVALID)) {
g_string_printf (nmc->return_text, _("Error in sleep: %s"), err->message);
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
g_error_free (err);
}
gone:
if (connection) dbus_g_connection_unref (connection);
if (proxy) g_object_unref (proxy);
}
/*
* Entry point function for general operations 'nmcli general'
*/
......@@ -490,7 +427,7 @@ do_general (NmCli *nmc, int argc, char **argv)
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
goto finish;
}
show_nm_status (nmc, NULL, TRUE, NULL);
show_nm_status (nmc, NULL, NULL);
}
if (argc > 0) {
......@@ -500,7 +437,7 @@ do_general (NmCli *nmc, int argc, char **argv)
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
goto finish;
}
show_nm_status (nmc, NULL, TRUE, NULL);
show_nm_status (nmc, NULL, NULL);
}
else if (matches (*argv, "permissions") == 0) {
if (!nmc_terse_option_check (nmc->print_output, nmc->required_fields, &error)) {
......@@ -575,7 +512,7 @@ nmc_switch_show (NmCli *nmc, const char *switch_name, const char *header)
nmc->print_output = NMC_PRINT_TERSE;
nmc->required_fields = g_strdup (switch_name);
return show_nm_status (nmc, header, TRUE, NMC_FIELDS_NM_STATUS_SWITCH);
return show_nm_status (nmc, header, NMC_FIELDS_NM_STATUS_SWITCH);
}
static gboolean
......@@ -642,7 +579,7 @@ do_radio (NmCli *nmc, int argc, char **argv)
g_error_free (error);
goto finish;
}
show_nm_status (nmc, _("Radio switches"), TRUE, NMC_FIELDS_NM_STATUS_RADIO);
show_nm_status (nmc, _("Radio switches"), NMC_FIELDS_NM_STATUS_RADIO);
}
if (argc > 0) {
......@@ -655,7 +592,7 @@ do_radio (NmCli *nmc, int argc, char **argv)
g_error_free (error);
goto finish;
}
show_nm_status (nmc, _("Radio switches"), TRUE, NMC_FIELDS_NM_STATUS_RADIO);
show_nm_status (nmc, _("Radio switches"), NMC_FIELDS_NM_STATUS_RADIO);
} else {
if (!nmc_switch_parse_on_off (nmc, *(argv-1), *argv, &enable_flag))
goto finish;
......@@ -719,258 +656,3 @@ finish:
return nmc->return_value;
}
/* --- Legacy stuff - kept for backward compatibility only */
/* Legacy 'nmcli nm' command */
static void
usage (void)
{
fprintf (stderr,
_("Usage: nmcli nm { COMMAND | help }\n\n"
#if WITH_WIMAX
" COMMAND := { status | permissions | enable | sleep | wifi | wwan | wimax }\n\n"
#else
" COMMAND := { status | permissions | enable | sleep | wifi | wwan }\n\n"
#endif
" status\n"
" permissions\n"
" enable [true|false]\n"
" sleep [true|false]\n"
" wifi [on|off]\n"
" wwan [on|off]\n"
#if WITH_WIMAX
" wimax [on|off]\n"
#endif
"\n"
));
}
/*
* Deprecated, remained here just for backward compatibility!
* Entry point function for global network manager related commands 'nmcli nm'
*/
NMCResultCode
do_network_manager (NmCli *nmc, int argc, char **argv)
{
GError *error = NULL;
gboolean sleep_flag;
gboolean enable_net;
gboolean enable_wifi;
gboolean enable_wwan;
#if WITH_WIMAX
gboolean enable_wimax;
#endif
guint32 mode_flag = (nmc->print_output == NMC_PRINT_PRETTY) ? NMC_PF_FLAG_PRETTY : (nmc->print_output == NMC_PRINT_TERSE) ? NMC_PF_FLAG_TERSE : 0;
guint32 multiline_flag = nmc->multiline_output ? NMC_PF_FLAG_MULTILINE : 0;
guint32 escape_flag = nmc->escape_values ? NMC_PF_FLAG_ESCAPE : 0;
if (argc == 0) {
if (!nmc_terse_option_check (nmc->print_output, nmc->required_fields, &error))
goto opt_error;
show_nm_status (nmc, NULL, FALSE, FALSE);
}
if (argc > 0) {
if (matches (*argv, "status") == 0) {
if (!nmc_terse_option_check (nmc->print_output, nmc->required_fields, &error))
goto opt_error;
show_nm_status (nmc, NULL, FALSE, FALSE);
}
else if (matches (*argv, "permissions") == 0) {
if (!nmc_terse_option_check (nmc->print_output, nmc->required_fields, &error))
goto opt_error;
show_nm_permissions (nmc);
}
else if (matches (*argv, "enable") == 0) {
if (next_arg (&argc, &argv) != 0) {
/* no argument, show current state of networking */
if (!nmc_terse_option_check (nmc->print_output, nmc->required_fields, &error))
goto opt_error;
if (nmc->required_fields && strcasecmp (nmc->required_fields, "NET-ENABLED")) {
g_string_printf (nmc->return_text, _("Error: '--fields' value '%s' is not valid here (allowed fields: %s)"),
nmc->required_fields, NMC_FIELDS_NM_NET_ENABLED_OLD);
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
goto end;
}
nmc->allowed_fields = nmc_fields_nm_status;
nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_NM_NET_ENABLED_OLD, nmc->allowed_fields, NULL);
nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_MAIN_HEADER_ADD | NMC_PF_FLAG_FIELD_NAMES;
nmc->print_fields.header_name = _("Networking enabled");
print_fields (nmc->print_fields, nmc->allowed_fields); /* Print header */
nmc->get_client (nmc); /* create NMClient */
if (nm_client_get_manager_running (nmc->client))
nmc->allowed_fields[3].value = nm_client_networking_get_enabled (nmc->client) ? _("enabled") : _("disabled");
else
nmc->allowed_fields[3].value = _("unknown");
nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag;
print_fields (nmc->print_fields, nmc->allowed_fields); /* Print values */
} else {
if (!strcmp (*argv, "true"))
enable_net = TRUE;
else if (!strcmp (*argv, "false"))
enable_net = FALSE;
else {
g_string_printf (nmc->return_text, _("Error: invalid 'enable' parameter: '%s'; use 'true' or 'false'."), *argv);
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
goto end;
}
nmc->get_client (nmc); /* create NMClient */
nm_client_networking_set_enabled (nmc->client, enable_net);
}
}
else if (matches (*argv, "sleep") == 0) {
if (next_arg (&argc, &argv) != 0) {
g_string_printf (nmc->return_text, _("Error: Sleeping status is not exported by NetworkManager."));
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
} else {
if (!strcmp (*argv, "true"))
sleep_flag = TRUE;
else if (!strcmp (*argv, "false"))
sleep_flag = FALSE;
else {
g_string_printf (nmc->return_text, _("Error: invalid 'sleep' parameter: '%s'; use 'true' or 'false'."), *argv);
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
goto end;
}
networking_set_sleep (nmc, sleep_flag);
}
}
else if (matches (*argv, "wifi") == 0) {
if (next_arg (&argc, &argv) != 0) {
/* no argument, show current WiFi state */
if (!nmc_terse_option_check (nmc->print_output, nmc->required_fields, &error))
goto opt_error;
if (nmc->required_fields && strcasecmp (nmc->required_fields, "WIFI")) {
g_string_printf (nmc->return_text, _("Error: '--fields' value '%s' is not valid here (allowed fields: %s)"),
nmc->required_fields, NMC_FIELDS_NM_WIFI_OLD);
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
goto end;
}
nmc->allowed_fields = nmc_fields_nm_status;
nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_NM_WIFI_OLD, nmc->allowed_fields, NULL);
nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_MAIN_HEADER_ADD | NMC_PF_FLAG_FIELD_NAMES;
nmc->print_fields.header_name = _("WiFi enabled");
print_fields (nmc->print_fields, nmc->allowed_fields); /* Print header */
nmc->get_client (nmc); /* create NMClient */
if (nm_client_get_manager_running (nmc->client))
nmc->allowed_fields[5].value = nm_client_wireless_get_enabled (nmc->client) ? _("enabled") : _("disabled");
else
nmc->allowed_fields[5].value = _("unknown");
nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag;
print_fields (nmc->print_fields, nmc->allowed_fields); /* Print values */
} else {
if (!strcmp (*argv, "on"))
enable_wifi = TRUE;
else if (!strcmp (*argv, "off"))
enable_wifi = FALSE;
else {
g_string_printf (nmc->return_text, _("Error: invalid 'wifi' parameter: '%s'."), *argv);
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
goto end;
}
nmc->get_client (nmc); /* create NMClient */
nm_client_wireless_set_enabled (nmc->client, enable_wifi);
}
}
else if (matches (*argv, "wwan") == 0) {
if (next_arg (&argc, &argv) != 0) {
if (!nmc_terse_option_check (nmc->print_output, nmc->required_fields, &error))
goto opt_error;
/* no argument, show current WWAN state */
if (nmc->required_fields && strcasecmp (nmc->required_fields, "WWAN")) {
g_string_printf (nmc->return_text, _("Error: '--fields' value '%s' is not valid here (allowed fields: %s)"),
nmc->required_fields, NMC_FIELDS_NM_WWAN_OLD);
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
goto end;
}
nmc->allowed_fields = nmc_fields_nm_status;
nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_NM_WWAN_OLD, nmc->allowed_fields, NULL);
nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_MAIN_HEADER_ADD | NMC_PF_FLAG_FIELD_NAMES;
nmc->print_fields.header_name = _("WWAN enabled");
print_fields (nmc->print_fields, nmc->allowed_fields); /* Print header */
nmc->get_client (nmc); /* create NMClient */
if (nm_client_get_manager_running (nmc->client))
nmc->allowed_fields[7].value = nm_client_wwan_get_enabled (nmc->client) ? _("enabled") : _("disabled");
else
nmc->allowed_fields[7].value = _("unknown");
nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag;
print_fields (nmc->print_fields, nmc->allowed_fields); /* Print values */
} else {
if (!strcmp (*argv, "on"))
enable_wwan = TRUE;
else if (!strcmp (*argv, "off"))
enable_wwan = FALSE;
else {
g_string_printf (nmc->return_text, _("Error: invalid 'wwan' parameter: '%s'."), *argv);
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
goto end;
}
nmc->get_client (nmc); /* create NMClient */
nm_client_wwan_set_enabled (nmc->client, enable_wwan);
}
}
#if WITH_WIMAX
else if (matches (*argv, "wimax") == 0) {
if (next_arg (&argc, &argv) != 0) {
if (!nmc_terse_option_check (nmc->print_output, nmc->required_fields, &error))
goto opt_error;
/* no argument, show current WiMAX state */
if (nmc->required_fields && strcasecmp (nmc->required_fields, "WIMAX")) {
g_string_printf (nmc->return_text, _("Error: '--fields' value '%s' is not valid here (allowed fields: %s)"),
nmc->required_fields, NMC_FIELDS_NM_WIMAX_OLD);
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
goto end;
}
nmc->allowed_fields = nmc_fields_nm_status;
nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_NM_WIMAX_OLD, nmc->allowed_fields, NULL);
nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_MAIN_HEADER_ADD | NMC_PF_FLAG_FIELD_NAMES;
nmc->print_fields.header_name = _("WiMAX enabled");
print_fields (nmc->print_fields, nmc->allowed_fields); /* Print header */
nmc->get_client (nmc); /* create NMClient */
if (nm_client_get_manager_running (nmc->client))
nmc->allowed_fields[9].value = nm_client_wimax_get_enabled (nmc->client) ? _("enabled") : _("disabled");
else
nmc->allowed_fields[9].value = _("unknown");
nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag;
print_fields (nmc->print_fields, nmc->allowed_fields); /* Print values */
} else {
if (!strcmp (*argv, "on"))
enable_wimax = TRUE;
else if (!strcmp (*argv, "off"))
enable_wimax = FALSE;
else {
g_string_printf (nmc->return_text, _("Error: invalid 'wimax' parameter: '%s'."), *argv);
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
goto end;
}
nmc->get_client (nmc); /* create NMClient */
nm_client_wimax_set_enabled (nmc->client, enable_wimax);
}
}
#endif
else if (nmc_arg_is_help (*argv)) {
usage ();
}
else {
usage ();
g_string_printf (nmc->return_text, _("Error: 'nm' command '%s' is not valid."), *argv);
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
}
}
end:
quit ();
return nmc->return_value;
opt_error:
quit ();
g_string_printf (nmc->return_text, _("Error: %s."), error->message);
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
g_error_free (error);
return nmc->return_value;
}
/* --- */
......@@ -26,7 +26,4 @@ NMCResultCode do_general (NmCli *nmc, int argc, char **argv);
NMCResultCode do_networking (NmCli *nmc, int argc, char **argv);
NMCResultCode do_radio (NmCli *nmc, int argc, char **argv);
/* Backward compatibility only */
NMCResultCode do_network_manager (NmCli *nmc, int argc, char **argv);
#endif /* NMC_NETWORK_MANAGER_H */
......@@ -113,8 +113,6 @@ static const struct cmd {
{ "connection", do_connections },
{ "device", do_devices },
{ "help", do_help },
/* Deprecated objects; only kept for backwards compatibility */
{ "nm", do_network_manager },
{ 0 }
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment