mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-08 06:38:11 +02:00
cli: add 'nmcli device delete <ifname>' command (rh #1034150)
It only works for software devices. When called for a hardware device, an error is returned and the device is not deleted. https://bugzilla.redhat.com/show_bug.cgi?id=1034150
This commit is contained in:
parent
576c82049b
commit
c7a567ca90
3 changed files with 137 additions and 6 deletions
|
|
@ -1164,7 +1164,7 @@ _nmcli()
|
||||||
;;
|
;;
|
||||||
d|de|dev|devi|devic|device)
|
d|de|dev|devi|devic|device)
|
||||||
if [[ ${#words[@]} -eq 2 ]]; then
|
if [[ ${#words[@]} -eq 2 ]]; then
|
||||||
_nmcli_compl_COMMAND "$command" status show connect disconnect wifi wimax
|
_nmcli_compl_COMMAND "$command" status show connect disconnect delete wifi wimax
|
||||||
elif [[ ${#words[@]} -gt 2 ]]; then
|
elif [[ ${#words[@]} -gt 2 ]]; then
|
||||||
case "$command" in
|
case "$command" in
|
||||||
s|st|sta|stat|statu|status)
|
s|st|sta|stat|statu|status)
|
||||||
|
|
@ -1174,7 +1174,8 @@ _nmcli()
|
||||||
;;
|
;;
|
||||||
sh|sho|show| \
|
sh|sho|show| \
|
||||||
c|co|con|conn|conne|connec|connect| \
|
c|co|con|conn|conne|connec|connect| \
|
||||||
d|di|dis|disc|disco|discon|disconn|disconne|disconnec|disconnect)
|
d|di|dis|disc|disco|discon|disconn|disconne|disconnec|disconnect| \
|
||||||
|
de|del|dele|delet|delete)
|
||||||
if [[ ${#words[@]} -eq 3 ]]; then
|
if [[ ${#words[@]} -eq 3 ]]; then
|
||||||
_nmcli_compl_COMMAND_nl "${words[2]}" "$(_nmcli_dev_status DEVICE)"
|
_nmcli_compl_COMMAND_nl "${words[2]}" "$(_nmcli_dev_status DEVICE)"
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
|
|
@ -278,14 +278,15 @@ usage (void)
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("Usage: nmcli device { COMMAND | help }\n\n"
|
_("Usage: nmcli device { COMMAND | help }\n\n"
|
||||||
#if WITH_WIMAX
|
#if WITH_WIMAX
|
||||||
"COMMAND := { status | show | connect | disconnect | wifi | wimax }\n\n"
|
"COMMAND := { status | show | connect | disconnect | delete | wifi | wimax }\n\n"
|
||||||
#else
|
#else
|
||||||
"COMMAND := { status | show | connect | disconnect | wifi }\n\n"
|
"COMMAND := { status | show | connect | disconnect | delete | wifi }\n\n"
|
||||||
#endif
|
#endif
|
||||||
" status\n\n"
|
" status\n\n"
|
||||||
" show [<ifname>]\n\n"
|
" show [<ifname>]\n\n"
|
||||||
" connect <ifname>\n\n"
|
" connect <ifname>\n\n"
|
||||||
" disconnect <ifname>\n\n"
|
" disconnect <ifname>\n\n"
|
||||||
|
" delete <ifname>\n\n"
|
||||||
" wifi [list [ifname <ifname>] [bssid <BSSID>]]\n\n"
|
" wifi [list [ifname <ifname>] [bssid <BSSID>]]\n\n"
|
||||||
" wifi connect <(B)SSID> [password <password>] [wep-key-type key|phrase] [ifname <ifname>]\n"
|
" wifi connect <(B)SSID> [password <password>] [wep-key-type key|phrase] [ifname <ifname>]\n"
|
||||||
" [bssid <BSSID>] [name <name>] [private yes|no]\n\n"
|
" [bssid <BSSID>] [name <name>] [private yes|no]\n\n"
|
||||||
|
|
@ -350,6 +351,20 @@ usage_device_disconnect (void)
|
||||||
"further connections without user/manual intervention.\n\n"));
|
"further connections without user/manual intervention.\n\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
usage_device_delete (void)
|
||||||
|
{
|
||||||
|
fprintf (stderr,
|
||||||
|
_("Usage: nmcli device delete { ARGUMENTS | help }\n"
|
||||||
|
"\n"
|
||||||
|
"ARGUMENTS := <ifname>\n"
|
||||||
|
"\n"
|
||||||
|
"Deletes the software device.\n"
|
||||||
|
"The command removes the interface. It only works for software devices\n"
|
||||||
|
"(like bonds, bridges, etc.). Hardware devices cannot be deleted by the\n"
|
||||||
|
"command.\n\n"));
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
usage_device_wifi (void)
|
usage_device_wifi (void)
|
||||||
{
|
{
|
||||||
|
|
@ -1588,6 +1603,106 @@ error:
|
||||||
return nmc->return_value;
|
return nmc->return_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
delete_device_cb (NMDevice *device, GError *error, gpointer user_data)
|
||||||
|
{
|
||||||
|
NmCli *nmc = (NmCli *) user_data;
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
g_string_printf (nmc->return_text, _("Error: Device '%s' (%s) deletion failed: %s"),
|
||||||
|
nm_device_get_iface (device),
|
||||||
|
nm_object_get_path (NM_OBJECT (device)),
|
||||||
|
error->message ? error->message : _("(unknown)"));
|
||||||
|
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
|
||||||
|
}
|
||||||
|
quit ();
|
||||||
|
}
|
||||||
|
|
||||||
|
static NMCResultCode
|
||||||
|
do_device_delete (NmCli *nmc, int argc, char **argv)
|
||||||
|
{
|
||||||
|
NMDevice **devices;
|
||||||
|
NMDevice *device = NULL;
|
||||||
|
const char *ifname = NULL;
|
||||||
|
char *ifname_ask = NULL;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
/* Set default timeout for delete operation. */
|
||||||
|
if (nmc->timeout == -1)
|
||||||
|
nmc->timeout = 10;
|
||||||
|
|
||||||
|
if (argc == 0) {
|
||||||
|
if (nmc->ask)
|
||||||
|
ifname = ifname_ask = nmc_readline (PROMPT_INTERFACE);
|
||||||
|
|
||||||
|
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_NOT_FOUND;
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!nm_device_is_software (device)) {
|
||||||
|
g_string_printf (nmc->return_text, _("Error: Device '%s' is a hardware device. It can't be deleted."), ifname);
|
||||||
|
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Use nowait_flag instead of should_wait, because exiting has to be postponed
|
||||||
|
* till delete_device_cb() is called, giving NM time to check our permissions.
|
||||||
|
*/
|
||||||
|
nmc->nowait_flag = (nmc->timeout == 0);
|
||||||
|
nmc->should_wait = TRUE;
|
||||||
|
nm_device_delete (device, delete_device_cb, nmc);
|
||||||
|
|
||||||
|
/* Start progress indication */
|
||||||
|
if (nmc->print_output == NMC_PRINT_PRETTY)
|
||||||
|
progress_id = g_timeout_add (120, progress_cb, device);
|
||||||
|
|
||||||
|
error:
|
||||||
|
return nmc->return_value;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
show_acces_point_info (NMDevice *device, NmCli *nmc)
|
show_acces_point_info (NMDevice *device, NmCli *nmc)
|
||||||
{
|
{
|
||||||
|
|
@ -2684,6 +2799,13 @@ do_devices (NmCli *nmc, int argc, char **argv)
|
||||||
}
|
}
|
||||||
nmc->return_value = do_device_disconnect (nmc, argc-1, argv+1);
|
nmc->return_value = do_device_disconnect (nmc, argc-1, argv+1);
|
||||||
}
|
}
|
||||||
|
else if (matches (*argv, "delete") == 0) {
|
||||||
|
if (nmc_arg_is_help (*(argv+1))) {
|
||||||
|
usage_device_delete ();
|
||||||
|
goto usage_exit;
|
||||||
|
}
|
||||||
|
nmc->return_value = do_device_delete (nmc, argc-1, argv+1);
|
||||||
|
}
|
||||||
else if (matches (*argv, "wifi") == 0) {
|
else if (matches (*argv, "wifi") == 0) {
|
||||||
if (nmc_arg_is_help (*(argv+1))) {
|
if (nmc_arg_is_help (*(argv+1))) {
|
||||||
usage_device_wifi ();
|
usage_device_wifi ();
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@
|
||||||
.\"
|
.\"
|
||||||
.\" Copyright (C) 2010 - 2014 Red Hat, Inc.
|
.\" Copyright (C) 2010 - 2014 Red Hat, Inc.
|
||||||
.\"
|
.\"
|
||||||
.TH NMCLI "1" "28 February 2014"
|
.TH NMCLI "1" "11 July 2014"
|
||||||
|
|
||||||
.SH NAME
|
.SH NAME
|
||||||
nmcli \- command\(hyline tool for controlling NetworkManager
|
nmcli \- command\(hyline tool for controlling NetworkManager
|
||||||
|
|
@ -683,7 +683,7 @@ of its latest state.
|
||||||
.B device - show and manage network interfaces
|
.B device - show and manage network interfaces
|
||||||
.br
|
.br
|
||||||
.TP
|
.TP
|
||||||
.SS \fICOMMAND\fP := { status | show | connect | disconnect | wifi | wimax }
|
.SS \fICOMMAND\fP := { status | show | connect | disconnect | delete | wifi | wimax }
|
||||||
.sp
|
.sp
|
||||||
.RS
|
.RS
|
||||||
.TP
|
.TP
|
||||||
|
|
@ -713,6 +713,14 @@ connections without user/manual intervention.
|
||||||
.br
|
.br
|
||||||
If '--wait' option is not specified, the default timeout will be 10 seconds.
|
If '--wait' option is not specified, the default timeout will be 10 seconds.
|
||||||
.TP
|
.TP
|
||||||
|
.B delete <ifname>
|
||||||
|
.br
|
||||||
|
Delete a device. The command removes the interface from the system. Note that
|
||||||
|
this only works for software devices like bonds, bridges, teams, etc.
|
||||||
|
Hardware devices (like Ethernet) cannot be deleted by the command.
|
||||||
|
.br
|
||||||
|
If '--wait' option is not specified, the default timeout will be 10 seconds.
|
||||||
|
.TP
|
||||||
.B wifi [list [ifname <ifname>] [bssid <BSSID>]]
|
.B wifi [list [ifname <ifname>] [bssid <BSSID>]]
|
||||||
.br
|
.br
|
||||||
List available Wi\(hyFi access points. The \fIifname\fP and \fIbssid\fP options
|
List available Wi\(hyFi access points. The \fIifname\fP and \fIbssid\fP options
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue