Merge changes for 'nmcli connection show' (rh #997999)

The syntax changes to:
nmcli con show [--active] [id | uuid | path | apath] <ID> ...

https://bugzilla.redhat.com/show_bug.cgi?id=997999
This commit is contained in:
Jiří Klimeš 2014-01-23 13:48:13 +01:00
commit e809990405
6 changed files with 722 additions and 462 deletions

View file

@ -15,7 +15,7 @@ _nmcli_list_nl()
_nmcli_con_show()
{
nmcli -t -f "$1" connection show "$2" 2>/dev/null
nmcli -t -f "$1" connection show $2 2> /dev/null
}
_nmcli_wifi_list()
@ -99,7 +99,11 @@ _nmcli_compl_OPTIONS()
;;
-f|--fields)
if [[ "${#words[@]}" -eq 2 ]]; then
_nmcli_list "all common"
_nmcli_list "all common
NAME UUID TYPE TIMESTAMP TIMESTAMP-REAL AUTOCONNECT READONLY DBUS-PATH ACTIVE DEVICE STATE ACTIVE-PATH
connection 802-3-ethernet 802-1x 802-11-wireless 802-11-wireless-security ipv4 ipv6 serial ppp pppoe gsm cdma bluetooth 802-11-olpc-mesh vpn wimax infiniband bond vlan adsl bridge bridge-port team team-port dcb
GENERAL IP4 DHCP4 IP6 DHCP6 VPN
profile active"
return 0
fi
REMOVE_OPTIONS=(-f --fields)
@ -271,7 +275,7 @@ _nmcli_compl_ARGS()
if [[ "${words[1]}" = "" ]]; then
_nmcli_list_nl "$(_nmcli_dev_status DEVICE)"
else
_nmcli_list_nl "$(printf "%s\n%s\n%s" "$(_nmcli_dev_status DEVICE)" "$(_nmcli_con_show UUID configured)")"
_nmcli_list_nl "$(printf "%s\n%s\n%s" "$(_nmcli_dev_status DEVICE)" "$(_nmcli_con_show UUID)")"
fi
return 0
fi
@ -281,7 +285,7 @@ _nmcli_compl_ARGS()
if [[ "${words[1]}" = "" ]]; then
_nmcli_list_nl "$(_nmcli_dev_status DEVICE)"
else
_nmcli_list_nl "$(printf "%s\n%s\n%s" "$(_nmcli_dev_status DEVICE)" "$(_nmcli_wifi_list BSSID)" "$(_nmcli_con_show UUID configured)")"
_nmcli_list_nl "$(printf "%s\n%s\n%s" "$(_nmcli_dev_status DEVICE)" "$(_nmcli_wifi_list BSSID)" "$(_nmcli_con_show UUID)")"
fi
return 0
fi
@ -437,41 +441,41 @@ _nmcli_compl_ARGS_CONNECTION()
fi
COMMAND_CONNECTION_TYPE="${words[0]}"
COMMAND_CONNECTION_ID="${words[1]}"
local CON_TYPE=configured
local CON_TYPE=
if [[ "x$COMMAND_CONNECTION_ACTIVE" != x ]]; then
CON_TYPE=active
CON_TYPE=--active
fi
case "${words[0]}" in
id)
if [[ ${#words[@]} -eq 2 ]]; then
if [[ ${#words[@]} -le 2 ]]; then
_nmcli_list_nl "$(_nmcli_con_show NAME $CON_TYPE)"
return 0
fi
words=("${words[@]:2}")
;;
uuid)
if [[ ${#words[@]} -eq 2 ]]; then
if [[ ${#words[@]} -le 2 ]]; then
_nmcli_list_nl "$(_nmcli_con_show UUID $CON_TYPE)"
return 0
fi
words=("${words[@]:2}")
;;
path)
if [[ ${#words[@]} -eq 2 ]]; then
_nmcli_list_nl "$(_nmcli_con_show DBUS-PATH configured)"
if [[ ${#words[@]} -le 2 ]]; then
_nmcli_list_nl "$(_nmcli_con_show DBUS-PATH $CON_TYPE)"
return 0
fi
words=("${words[@]:2}")
;;
apath)
if [[ ${#words[@]} -eq 2 ]]; then
_nmcli_list_nl "$(_nmcli_con_show DBUS-PATH active)"
if [[ ${#words[@]} -le 2 ]]; then
_nmcli_list_nl "$(_nmcli_con_show ACTIVE-PATH --active)"
return 0
fi
words=("${words[@]:2}")
;;
ifname)
if [[ ${#words[@]} -eq 2 ]]; then
if [[ ${#words[@]} -le 2 ]]; then
_nmcli_list_nl "$(_nmcli_dev_status DEVICE)"
return 0
fi
@ -534,6 +538,7 @@ _nmcli()
local command="${words[1]}"
local OPTIONS_UNKNOWN_OPTION OPTIONS_TYPE OPTIONS_TYPED OPTIONS OPTIONS_MANDATORY COMMAND_ARGS_WAIT_OPTIONS ARRAY OPTIONS_IP OPTIONS_MANDATORY OPTIONS_NEXT_GROUP
local COMMAND_CONNECTION_TYPE COMMAND_CONNECTION_ID
local COMMAND_CONNECTION_ACTIVE=""
case "${words[0]}" in
h|he|hel|help)
@ -594,33 +599,29 @@ _nmcli()
case "$command" in
s|sh|sho|show)
if [[ ${#words[@]} -eq 3 ]]; then
_nmcli_compl_COMMAND "${words[2]}" configured active
_nmcli_compl_COMMAND_nl "${words[2]}" "$(printf "id\nuuid\npath\napath\n--active\n%s" "$(_nmcli_con_show NAME)")"
elif [[ ${#words[@]} -gt 3 ]]; then
case "${words[2]}" in
c|co|con|conf|confi|config|configu|configur|configure|configured)
if [[ ${#words[@]} -eq 4 ]]; then
_nmcli_list_nl "$(printf "id\nuuid\npath\n%s" "$(_nmcli_con_show NAME configured)")"
else
words=("${words[@]:3}")
OPTIONS=(id uuid path)
_nmcli_compl_ARGS_CONNECTION
fi
;;
a|ac|act|acti|activ|active)
if [[ ${#words[@]} -eq 4 ]]; then
_nmcli_list_nl "$(printf "id\nuuid\npath\napath\n%s" "$(_nmcli_con_show NAME active)")"
else
words=("${words[@]:3}")
OPTIONS=(id uuid path apath)
_nmcli_compl_ARGS_CONNECTION
fi
OPTIONS=(id uuid path apath)
words=("${words[@]:2}")
case "${words[0]}" in
--a|--ac|--act|--acti|--activ|--active)
COMMAND_CONNECTION_ACTIVE=1
words=("${words[@]:1}")
;;
esac
while [[ ${#words[@]} -gt 0 ]]; do
_nmcli_compl_ARGS_CONNECTION && return 0
done
if [[ "x$COMMAND_CONNECTION_ACTIVE" = x ]]; then
_nmcli_list_nl "$(printf "id\nuuid\npath\napath\n%s" "$(_nmcli_con_show NAME)")"
else
_nmcli_list_nl "$(printf "id\nuuid\npath\napath\n%s" "$(_nmcli_con_show NAME --active)")"
fi
fi
;;
u|up)
if [[ ${#words[@]} -eq 3 ]]; then
_nmcli_compl_COMMAND_nl "${words[2]}" "$(printf "ifname\nid\nuuid\npath\n%s" "$(_nmcli_con_show NAME configured)")"
_nmcli_compl_COMMAND_nl "${words[2]}" "$(printf "ifname\nid\nuuid\npath\n%s" "$(_nmcli_con_show NAME)")"
elif [[ ${#words[@]} -gt 3 ]]; then
local COMMAND_CONNECTION_TYPE=''
words=("${words[@]:2}")
@ -637,11 +638,11 @@ _nmcli()
;;
d|do|dow|down)
if [[ ${#words[@]} -eq 3 ]]; then
_nmcli_compl_COMMAND_nl "${words[2]}" "$(printf "id\nuuid\npath\napath\n%s" "$(_nmcli_con_show NAME active)")"
_nmcli_compl_COMMAND_nl "${words[2]}" "$(printf "id\nuuid\npath\napath\n%s" "$(_nmcli_con_show NAME --active)")"
elif [[ ${#words[@]} -gt 3 ]]; then
words=("${words[@]:2}")
OPTIONS=(id uuid path apath)
local COMMAND_CONNECTION_ACTIVE=1
COMMAND_CONNECTION_ACTIVE=1
_nmcli_compl_ARGS_CONNECTION
fi
;;
@ -836,7 +837,7 @@ _nmcli()
;;
e|ed|edi|edit)
if [[ ${#words[@]} -eq 3 ]]; then
_nmcli_compl_COMMAND_nl "${words[2]}" "$(printf "id\nuuid\npath\ntype\ncon-name\n%s" "$(_nmcli_con_show NAME configured)")"
_nmcli_compl_COMMAND_nl "${words[2]}" "$(printf "id\nuuid\npath\ntype\ncon-name\n%s" "$(_nmcli_con_show NAME)")"
elif [[ ${#words[@]} -gt 3 ]]; then
words=("${words[@]:2}")
if [[ "${words[0]}" = 'type' || "${words[0]}" = 'con-name' ]]; then
@ -850,19 +851,19 @@ _nmcli()
;;
m|mo|mod|modi|modif|modify)
if [[ ${#words[@]} -eq 3 ]]; then
_nmcli_compl_COMMAND_nl "${words[2]}" "$(printf "id\nuuid\npath\n%s" "$(_nmcli_con_show NAME configured)")"
_nmcli_compl_COMMAND_nl "${words[2]}" "$(printf "id\nuuid\npath\n%s" "$(_nmcli_con_show NAME)")"
elif [[ ${#words[@]} -gt 3 ]]; then
words=("${words[@]:2}")
OPTIONS=(id uuid path apath)
_nmcli_compl_ARGS_CONNECTION && return 0
if [[ ${#words[@]} -le 1 ]]; then
_nmcli_list_nl "$(nmcli connection show configured "${COMMAND_CONNECTION_TYPE:-id}" "$COMMAND_CONNECTION_ID" 2>/dev/null | sed -n 's/^\([^:]\+\):.*/\1/p')"
_nmcli_list_nl "$(nmcli connection show "${COMMAND_CONNECTION_TYPE:-id}" "$COMMAND_CONNECTION_ID" 2>/dev/null | sed -n 's/^\([^:]\+\):.*/\1/p')"
fi
fi
;;
de|del|dele|delet|delete)
if [[ ${#words[@]} -eq 3 ]]; then
_nmcli_compl_COMMAND_nl "${words[2]}" "$(printf "id\nuuid\npath\n%s" "$(_nmcli_con_show NAME configured)")"
_nmcli_compl_COMMAND_nl "${words[2]}" "$(printf "id\nuuid\npath\n%s" "$(_nmcli_con_show NAME)")"
elif [[ ${#words[@]} -gt 3 ]]; then
words=("${words[@]:2}")
OPTIONS=(id uuid path apath)

File diff suppressed because it is too large Load diff

View file

@ -14,7 +14,7 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* (C) Copyright 2010 - 2013 Red Hat, Inc.
* (C) Copyright 2010 - 2014 Red Hat, Inc.
*/
/* Generated configuration file */
@ -72,6 +72,23 @@ nmc_arg_is_help (const char *arg)
return FALSE;
}
gboolean
nmc_arg_is_option (const char *str, const char *opt_name)
{
const char *p;
if (!str || !*str)
return FALSE;
if (str[0] != '-')
return FALSE;
p = (str[1] == '-') ? str + 2 : str + 1;
return (*p ? (matches (p, opt_name) == 0) : FALSE);
}
/*
* Helper function to parse command-line arguments.
* arg_arr: description of arguments to look for
@ -699,27 +716,15 @@ parse_output_fields (const char *fields_str,
/* Field was not found - error case */
if (fields_array[i].name == NULL) {
GString *allowed_fields = g_string_sized_new (256);
int k;
/* Set GError */
if (idx != -1 && fields_array[idx].group) {
NmcOutputField *second_level = fields_array[idx].group;
for (k = 0; second_level[k].name; k++)
g_string_append_printf (allowed_fields, "%s.%s,",
fields_array[idx].name, second_level[k].name);
} else {
for (k = 0; fields_array[k].name; k++)
g_string_append_printf (allowed_fields, "%s,", fields_array[k].name);
}
g_string_truncate (allowed_fields, allowed_fields->len - 1);
if (!strcasecmp (*iter, "all") || !strcasecmp (*iter, "common"))
g_set_error (error, NMCLI_ERROR, 0, _("field '%s' has to be alone"), *iter);
else
else {
char *allowed_fields = nmc_get_allowed_fields (fields_array, idx);
g_set_error (error, NMCLI_ERROR, 1, _("invalid field '%s'; allowed fields: %s"),
*iter, allowed_fields->str);
g_string_free (allowed_fields, TRUE);
*iter, allowed_fields);
g_free (allowed_fields);
}
/* Free arrays on error */
g_array_free (array, TRUE);
@ -737,6 +742,35 @@ done:
return array;
}
/**
* nmc_get_allowed_fields:
* @fields_array: array of fields
* @group_idx: index to the array (for second-level array in 'group' member),
* or -1
*
* Returns: string of allowed fields names.
* Caller is responsible for freeing the array.
*/
char *
nmc_get_allowed_fields (const NmcOutputField fields_array[], int group_idx)
{
GString *allowed_fields = g_string_sized_new (256);
int i;
if (group_idx != -1 && fields_array[group_idx].group) {
NmcOutputField *second_level = fields_array[group_idx].group;
for (i = 0; second_level[i].name; i++)
g_string_append_printf (allowed_fields, "%s.%s,",
fields_array[group_idx].name, second_level[i].name);
} else {
for (i = 0; fields_array[i].name; i++)
g_string_append_printf (allowed_fields, "%s,", fields_array[i].name);
}
g_string_truncate (allowed_fields, allowed_fields->len - 1);
return g_string_free (allowed_fields, FALSE);
}
gboolean
nmc_terse_option_check (NMCPrintOutput print_output, const char *fields, GError **error)
{

View file

@ -14,7 +14,7 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* (C) Copyright 2010 - 2013 Red Hat, Inc.
* (C) Copyright 2010 - 2014 Red Hat, Inc.
*/
#ifndef NMC_UTILS_H
@ -38,6 +38,7 @@ typedef struct {
int matches (const char *cmd, const char *pattern);
int next_arg (int *argc, char ***argv);
gboolean nmc_arg_is_help (const char *arg);
gboolean nmc_arg_is_option (const char *arg, const char *opt_name);
gboolean nmc_parse_args (nmc_arg_t *arg_arr, gboolean last, int *argc, char ***argv, GError **error);
char *ssid_to_hex (const char *str, gsize len);
gboolean nmc_string_to_int_base (const char *str,
@ -85,6 +86,7 @@ GArray *parse_output_fields (const char *fields_str,
gboolean parse_groups,
GPtrArray **group_fields,
GError **error);
char *nmc_get_allowed_fields (const NmcOutputField fields_array[], int group_idx);
gboolean nmc_terse_option_check (NMCPrintOutput print_output, const char *fields, GError **error);
NmcOutputField *nmc_dup_fields_array (NmcOutputField fields[], size_t size, guint32 flags);
void nmc_empty_output_fields (NmCli *nmc);

View file

@ -224,7 +224,7 @@ $ nmcli con add up Team1-slave2
$ nmcli con add con-name my-con-em1 ifname em1 type ethernet ip4 192.168.100.100/24 gw4 192.168.100.1 ip4 1.2.3.4 ip6 abbe::cafe
$ nmcli con mod my-con-em1 ipv4.dns "8.8.8.8 8.8.4.4"
$ nmcli con mod my-con-em1 ipv6.dns "2001:4860:4860::8888 2001:4860:4860::8844"
$ nmcli -p con show conf my-con-em1
$ nmcli -p con show my-con-em1
</emphasis>
</programlisting>
</example>
@ -232,8 +232,8 @@ $ nmcli -p con show conf my-con-em1
The first command adds an Ethernet connection profile named <emphasis>my-con-em1</emphasis>
that is bound to interface name <emphasis>em1</emphasis>. The profile is configured
with static IP addresses. The second and third commands modify DNS parameters of the
new connection profile. Using the last <emphasis>con show configured</emphasis> the
profile is displayed so that all parameters can be reviewed.
new connection profile. The last <emphasis>con show</emphasis> command displays the
profile so that all parameters can be reviewed.
</para>
<example><title>Escaping colon characters in tabular mode</title>

View file

@ -19,9 +19,9 @@
.\" with this manual; if not, write to the Free Software Foundation, Inc.,
.\" 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
.\"
.\" Copyright (C) 2010 - 2013 Red Hat, Inc.
.\" Copyright (C) 2010 - 2014 Red Hat, Inc.
.\"
.TH NMCLI "1" "12 December 2013"
.TH NMCLI "1" "14 January 2014"
.SH NAME
nmcli \- command\(hyline tool for controlling NetworkManager
@ -97,8 +97,7 @@ producing more structured information, that cannot be displayed on a single
line, default is \fImultiline\fP. Currently, they are:
.br
.nf
'nmcli connection show configured <ID>'
'nmcli connection show active <ID>'
'nmcli connection show <ID>'
'nmcli device show'
.fi
\fItabular\fP \(en Output is a table where each line describes a single entry.
@ -276,12 +275,21 @@ connected to the DHCP-enabled network the user would run "nmcli con up default"
.sp
.RS
.TP
.B show active [[ id | uuid | path | apath ] <ID>]
.B show [--active]
.br
Shows connections which are currently used by a device to connect to a network.
Without a parameter, all active connections are listed. In order to show the
connection details, \fI<ID>\fP must be provided. \fIid\fP, \fIuuid\fP,
\fIpath\fP and \fIapath\fP keywords can be used if \fI<ID>\fP is ambiguous.
List in-memory and on-disk connection profiles, some of which may also be
active if a device is using that connection profile. Without a parameter, all
profiles are listed. When --active option is specified, only the active profiles
are shown.
.TP
.B show [--active] [ id | uuid | path | apath ] <ID> ...
.br
Show details for specified connections. By default, both static configuration
and active connection data are displayed. When --active option is specified,
only the active profiles are taken into
account.
\fIid\fP, \fIuuid\fP, \fIpath\fP and \fIapath\fP keywords can be used if
\fI<ID>\fP is ambiguous.
.RS
.PP
Optional <ID>-specifying keywords are:
@ -295,19 +303,24 @@ in the format of /org/freedesktop/NetworkManager/Settings/<num> or just <num>
.IP \fIapath\fP 13
\(en the <ID> denotes a D-Bus active connection path
in the format of /org/freedesktop/NetworkManager/ActiveConnection/<num> or just <num>
.PP
It is possible to filter the output using the global \fI--fields\fP option. Use the following
values:
.RE
.TP
.B show configured [[ id | uuid | path ] <ID>]
.br
Shows in-memory and on-disk connections, some of which may also be \fIactive\fP
if a device is using that connection. Without a parameter, all connections
are listed. In order to show connection details, \fI<ID>\fP must be
provided. \fIid\fP, \fIuuid\fP and \fIpath\fP keywords can be used if
\fI<ID>\fP is ambiguous. See \fBshow active\fP above for the description of
the keywords.
.br
.RS
.PP
.IP \fIprofile\fP 13
\(en only shows static profile configuration
.IP \fIactive\fP 13
\(en only shows active connection data (when the profile is active)
.PP
You can also specify particular fields. For static configuration, use setting and property names
as described in \fInm-settings\fP(5) manual page. For active data use GENERAL, IP4, DHCP4, IP6,
DHCP6, VPN.
.PP
When no command is given to the \fIconnection\fP object, the default action
is 'nmcli connection show configured'.
is 'nmcli connection show'.
.RE
.TP
.B up [ id | uuid | path ] <ID> [ifname <ifname>] [ap <BSSID>] [nsp <name>]
.RE
@ -327,7 +340,7 @@ connection.
.br
If '--wait' option is not specified, the default timeout will be 90 seconds.
.br
See \fBshow active\fP above for the description of the <ID>-specifying keywords.
See \fBconnection show\fP above for the description of the <ID>-specifying keywords.
.RS
.PP
Available options are:
@ -357,7 +370,7 @@ The connection is identified by its name, UUID or D-Bus path.
If <ID> is ambiguous, a keyword \fIid\fP, \fIuuid\fP, \fIpath\fP or
\fIapath\fP can be used.
.br
See \fBshow active\fP above for the description of the <ID>-specifying keywords.
See \fBconnection show\fP above for the description of the <ID>-specifying keywords.
.TP
.B add COMMON_OPTIONS TYPE_SPECIFIC_OPTIONS IP_OPTIONS
.br
@ -583,7 +596,7 @@ Edit an existing connection or add a new one, using an interactive editor.
.br
The existing connection is identified by its name, UUID or D-Bus path.
If <ID> is ambiguous, a keyword \fIid\fP, \fIuuid\fP, or \fIpath\fP can be used.
See \fBshow active\fP above for the description of the <ID>-specifying keywords.
See \fBconnection show\fP above for the description of the <ID>-specifying keywords.
Not providing an <ID> means that a new connection will be added.
.sp
The interactive editor will guide you through the connection editing and
@ -621,7 +634,7 @@ Delete a configured connection. The connection to be deleted is identified by
its name, UUID or D-Bus path. If <ID> is ambiguous, a keyword \fIid\fP,
\fIuuid\fP or \fIpath\fP can be used.
.br
See \fBshow active\fP above for the description of the <ID>-specifying keywords.
See \fBconnection show\fP above for the description of the <ID>-specifying keywords.
.TP
.B reload
.br
@ -791,34 +804,38 @@ shows the overall status of NetworkManager.
.IP
switches Wi\(hyFi off.
.IP "\fB\f(CWnmcli connection show configured\fP\fP"
.IP "\fB\f(CWnmcli connection show\fP\fP"
.IP
lists all connections NetworkManager has.
.IP "\fB\f(CWnmcli \-p \-m multiline \-f all con show c\fP\fP"
.IP "\fB\f(CWnmcli \-p \-m multiline \-f all con show\fP\fP"
.IP
shows all configured connections in multi-line mode.
.IP "\fB\f(CWnmcli \-p connection show active\fP\fP"
.IP "\fB\f(CWnmcli connection show --active\fP\fP"
.IP
lists all currently active connections.
.IP "\fB\f(CWnmcli \-p connection show active \(dq\&My default em1\(dq\&\fP\fP"
.IP "\fB\f(CWnmcli \-f name,autoconnect c s\fP\fP"
.IP
shows all connection profile names and their auto-connect property.
.IP "\fB\f(CWnmcli \-p connection show \(dq\&My default em1\(dq\&\fP\fP"
.IP
shows details for "My default em1" connection profile.
.IP "\fB\f(CWnmcli \-f active connection show \(dq\&My default em1\(dq\&\fP\fP"
.IP
shows details for "My default em1" active connection, like IP, DHCP
information.
information, etc.
.IP "\fB\f(CWnmcli \-f name,autoconnect c s c\fP\fP"
.IP "\fB\f(CWnmcli -f profile con s \(dq\&My wired connection\(dq\&\fP\fP"
.IP
shows all connections' names and their auto-connect settings.
.IP "\fB\f(CWnmcli con s c \(dq\&My wired connection\(dq\&\fP\fP"
.IP
shows all details of the connection with "My wired connection" name.
shows static configuration details of the connection profile with "My wired connection" name.
.IP "\fB\f(CWnmcli \-p con up \(dq\&My wired connection\(dq\& ifname eth0\fP\fP"
.IP
activates the connection with name "My wired connection" on interface eth0.
activates the connection profile with name "My wired connection" on interface eth0.
The \-p option makes nmcli show progress of the activation.
.IP "\fB\f(CWnmcli con up 6b028a27\-6dc9\-4411\-9886\-e9ad1dd43761 ap 00:3A:98:7C:42:D3\fP\fP"