diff options
author | Dan Winship <danw@gnome.org> | 2014-04-30 15:26:13 -0400 |
---|---|---|
committer | Dan Winship <danw@gnome.org> | 2014-07-10 09:26:54 -0400 |
commit | e68b25f1bbd2055e4ab27b73a576c31c08a5137a (patch) | |
tree | f26715751c13a05b1606e588c24797f0fb22d086 | |
parent | 31cadff04e860cc7beddd04d4f41155fcd1e6ed8 (diff) | |
download | NetworkManager-danw/disable.tar.gz |
cli: add "nmcli device manage" and "nmcli device unmanage"danw/disable
-rw-r--r-- | cli/src/devices.c | 111 | ||||
-rw-r--r-- | man/nmcli.1.in | 16 |
2 files changed, 126 insertions, 1 deletions
diff --git a/cli/src/devices.c b/cli/src/devices.c index 17492066b6..f3bdd1a4bc 100644 --- a/cli/src/devices.c +++ b/cli/src/devices.c @@ -284,6 +284,8 @@ usage (void) " show [<ifname>]\n\n" " connect <ifname>\n\n" " disconnect <ifname>\n\n" + " manage <ifname>\n\n" + " unmanage <ifname>\n\n" " wifi [list [ifname <ifname>] [bssid <BSSID>]]\n\n" " wifi connect <(B)SSID> [password <password>] [wep-key-type key|phrase] [ifname <ifname>]\n" " [bssid <BSSID>] [name <name>] [private yes|no]\n\n" @@ -349,6 +351,34 @@ usage_device_disconnect (void) } static void +usage_device_manage (void) +{ + fprintf (stderr, + _("Usage: nmcli device manage { ARGUMENTS | help }\n" + "\n" + "ARGUMENTS := <ifname>\n" + "\n" + "Tell NetworkManager to manage the device.\n" + "Marking a device as managed allows NetworkManager to activate connections\n" + "on it. This is the default state for recognized device types that have not\n" + "been explicitly configured to be unmanaged.\n\n")); +} + +static void +usage_device_unmanage (void) +{ + fprintf (stderr, + _("Usage: nmcli device unmanage { ARGUMENTS | help }\n" + "\n" + "ARGUMENTS := <ifname>\n" + "\n" + "Tell NetworkManager to stop managing the device.\n" + "Unmanaging a device will deactivate any connection currently active on it\n" + "and prevent NetworkManager from activating any other connection on it\n" + "in the future.\n\n")); +} + +static void usage_device_wifi (void) { fprintf (stderr, @@ -1584,6 +1614,73 @@ error: return nmc->return_value; } +static NMCResultCode +do_device_set_managed (NmCli *nmc, gboolean managed, int argc, char **argv) +{ + NMDevice **devices; + NMDevice *device = NULL; + const char *ifname = NULL; + char *ifname_ask = NULL; + int i; + + if (argc == 0) { + if (nmc->ask) { + ifname = ifname_ask = nmc_get_user_input (_("Interface: ")); + // TODO: list available devices when just Enter is pressed ? + } + if (!ifname_ask) { + g_string_printf (nmc->return_text, _("Error: No interface specified.")); + nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; + goto error; + } + } else { + ifname = *argv; + } + + if (!ifname) { + g_string_printf (nmc->return_text, _("Error: No interface specified.")); + nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; + goto error; + } + + if (next_arg (&argc, &argv) == 0) { + g_string_printf (nmc->return_text, _("Error: extra argument not allowed: '%s'."), *argv); + nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; + goto error; + } + + nmc->get_client (nmc); + if (!nm_client_get_manager_running (nmc->client)) { + g_string_printf (nmc->return_text, _("Error: NetworkManager is not running.")); + nmc->return_value = NMC_RESULT_ERROR_NM_NOT_RUNNING; + goto error; + } + + if (!nmc_versions_match (nmc)) + goto error; + + devices = get_devices_sorted (nmc->client); + for (i = 0; devices[i]; i++) { + NMDevice *candidate = devices[i]; + const char *dev_iface = nm_device_get_iface (candidate); + + if (!g_strcmp0 (dev_iface, ifname)) + device = candidate; + } + g_free (devices); + + if (!device) { + g_string_printf (nmc->return_text, _("Error: Device '%s' not found."), ifname); + nmc->return_value = NMC_RESULT_ERROR_UNKNOWN; + goto error; + } + + nm_device_set_managed (device, managed); + + error: + return nmc->return_value; +} + static void show_acces_point_info (NMDevice *device, NmCli *nmc) { @@ -2680,6 +2777,20 @@ do_devices (NmCli *nmc, int argc, char **argv) } nmc->return_value = do_device_disconnect (nmc, argc-1, argv+1); } + else if (matches (*argv, "manage") == 0) { + if (nmc_arg_is_help (*(argv+1))) { + usage_device_manage (); + goto usage_exit; + } + nmc->return_value = do_device_set_managed (nmc, TRUE, argc-1, argv+1); + } + else if (matches (*argv, "unmanage") == 0) { + if (nmc_arg_is_help (*(argv+1))) { + usage_device_unmanage (); + goto usage_exit; + } + nmc->return_value = do_device_set_managed (nmc, FALSE, argc-1, argv+1); + } else if (matches (*argv, "wifi") == 0) { if (nmc_arg_is_help (*(argv+1))) { usage_device_wifi (); diff --git a/man/nmcli.1.in b/man/nmcli.1.in index 08f07b4ab7..9437c861f4 100644 --- a/man/nmcli.1.in +++ b/man/nmcli.1.in @@ -683,7 +683,7 @@ of its latest state. .B device - show and manage network interfaces .br .TP -.SS \fICOMMAND\fP := { status | show | connect | disconnect | wifi | wimax } +.SS \fICOMMAND\fP := { status | show | connect | disconnect | manage | unmanage | wifi | wimax } .sp .RS .TP @@ -713,6 +713,20 @@ connections without user/manual intervention. .br If '--wait' option is not specified, the default timeout will be 10 seconds. .TP +.B manage <ifname> +.br +Tells NetworkManager to manage the device. Marking a device as managed +allows NetworkManager to activate connections on it. This is the +default state for recognized device types that have not been +explicitly configured to be unmanaged. +.TP +.B unmanage <ifname> +.br +Tells NetworkManager to stop managing the device. Unmanaging a device +will deactivate any connection currently active on it and prevent +NetworkManager from activating any other connection on it in the +future. +.TP .B wifi [list [ifname <ifname>] [bssid <BSSID>]] .br List available Wi\(hyFi access points. The \fIifname\fP and \fIbssid\fP options |