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
and use it for 'nmcli device show'.
This allows filtering output not only for whole groups, but also for individual
fields in commands that print data in groups (sections).
Example:
$ nmcli -f general.device,general.driver,ipv4,ipv6.address device show eth0
GENERAL.DEVICE: eth0
GENERAL.DRIVER: e1000e
IP4.ADDRESS[1]: ip = 10.0.5.228/23, gw = 10.0.5.254
IP4.ADDRESS[2]: ip = 5.5.5.5/32, gw = 5.5.5.1
IP4.DNS[1]: 192.168.122.1
IP4.DNS[2]: 8.8.8.8
IP4.DOMAIN[1]: mycompany.com
Ensure in matches() that a non-empty cmd is given, otherwise
as currently
nmcli general -
matches to '-h' and is thus treated as
nmcli general -h
Signed-off-by: Thomas Haller <thaller@redhat.com>
Before, when specifying a setting.property with missing property name,
the following happened:
nmcli> set connection.
Error: invalid property: '' not among [...
Reword this special error case of a missing property to make it more
clear.
Signed-off-by: Thomas Haller <thaller@redhat.com>
nmcli connection edit [type <type>] [con-name <name>]
Examples:
nmcli c e
nmcli c e type ethernet
nmcli c e type wifi con-name "My home Wi-Fi"
nmcli c e type bond
...
Until now we have used a static width defined for each column for tabular
output. Even if this worked in most cases, it was not optimal, because by
using too wide columns we wasted space, and in case of a too narrow column the
alignment broke. So, we need to know the longest string in a column to be able
to align columns in the tabular output. Thus, the printing has to be postponed
till we have all data available, and can find the widest column. This value is
then used for aligning while printing the data.
Arrays of NmcOutputField (rows) are inserted into output_data array. When all
data have been added, print_data() can be used to print the whole output_data
array with proper alignment.
A single row can be printed using print_required_fields().
Also, output flags are redone to better match the new output_data array.
The flags are needed for every row (in tabular output); they are stored in
the first field (NmcOutputField) for the whole row.
Addapted set_val_str() and set_val_arr() to set value type (char * x char **).
Added set_val_strc(), set_val_arrc() for const values that should not be freed.
output_data takes ownership of the data added to it and takes care of freeing
the memory.
See e.g.
https://bugzilla.gnome.org/show_bug.cgi?id=699503
nmc_string_to_int() - converts string to signed long int (decimal)
nmc_string_to_uint() - converts string to unsigned long int (decimal)
nmc_string_to_int_base() - converts string to signed long int with given base
nmc_string_to_uint_base() - converts string to unsigned long int with given base
This function checks whether a string is contained among allowed strings. It
performs case-insensitive comparison and supports shortcuts if they are unique.
It returns a pointer to the found string in allowed array, or NULL.
Simplify code by using property get functions, with most of them
autogenerated based on GObject properties and GValue transforms.
Based on a patch from Jiří Klimeš
This is similar to clicking a Wi-Fi network's SSID in a GUI applet.
The command does this:
- creates new connection (fills the user data specified via options, the
connection is then completed with default parameters by NM)
- and then activates the connection on a Wi-Fi device.
WPA-Enterprise is not supported as it requires a plethora of parameters and
they can't be obtained automatically.
Also, the created connection uses 'auto' IP method, which means that if the
Wi-Fi network doesn't support DHCP, the connection will albeit be created,
however the activation will fail (IP configuration won't be available).
Field values can now be string arrays. print_fields() recognizes the format and
prints values accordingly.
Setter functions was added to facilitate setting string vs. array:
set_val_str(), set_val_arr()
nmcli gets NM version and compares it with its own and complains
when they differ. This is to indicate that the results are not reliable,
because the API could differ. '--nocheck' switches the checks off.
If SSID is a UTF-8 string, it is printed as it is, but enclosed in quotes.
Otherwise the bytes are converted to hex string (in uppercase).
The added quotes for UTF-8 string allow to disambiguate the two forms.
Modifications are mainly for multiline mode to ease parsing - each
field name is prefixed with a section name.
'dev list' now also supports printing particular sections specifed via
'--fields' option.
The output is basically tabular with fields (columns) presenting specific pieces of info.
Each line represents a single object. It's possible to switch to multiline output using
'--multiline' option. In that mode single object is presented on more lines - each field
on its line.
Terse mode now uses ':' as field separator. It also escapes all occurences of ':' and '\'
inside field values to ease parsing. The escaping behaviour can be controlled through
'--escape' option. By default, escaping is switched on in tabular mode. When using terse
mode ('--terse'), '--fields' option is mandatory for specifying required fields. That helps
for flexibility and backwards compatibility.
Not all output is converted yet.