cli: consolidate active and configured connections (rh #997999)
Handle connection profiles in a single 'show' command instead of 'show active' and 'show configured'. nmcli con show [--active] [[id|uuid|path|apath] <bla>] nmcli con show : display all connection profiles nmcli con show --active : only display active connection profiles (filters out inactive profiles) nmcli con show myeth : display details of "myeth" profile, and also active connection info (if the profile is active) nmcli -f profile con show myeth : only display "myeth"'s static configuration nmcli -f active con show myeth : only display active details of "myeth" nmcli -f connection.id,ipv4,general con show myeth : display "connection.id"a property "ipv4" setting and "GENERAL" group of active data https://bugzilla.redhat.com/show_bug.cgi?id=997999
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -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)
|
||||
{
|
||||
|
@@ -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);
|
||||
|
@@ -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>
|
||||
|
@@ -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"
|
||||
|
Reference in New Issue
Block a user