Functions¶
Details¶
- NM.bridge_vlan_from_str(str)¶
- Parameters:
str (
str
) – the string representation of a bridge VLAN- Raises:
- Returns:
the
NM.BridgeVlan
orNone
- Return type:
Parses the string representation of the queueing discipline to a
NM.BridgeVlan
instance.New in version 1.18.
- NM.conn_wireguard_import(filename)¶
- Parameters:
filename (
str
) – name of the file to attempt to read into a newNM.Connection
- Raises:
- Returns:
a new
NM.Connection
imported from path, orNone
on error or if the file with filename was not recognized as a WireGuard config- Return type:
New in version 1.40.
- NM.ethtool_optname_is_channels(optname)¶
- Parameters:
- Returns:
True
, if optname is valid- Return type:
Checks whether optname is a valid option name for a channels setting.
New in version 1.46.
- NM.ethtool_optname_is_coalesce(optname)¶
- Parameters:
- Returns:
True
, if optname is valid- Return type:
Checks whether optname is a valid option name for a coalesce setting.
New in version 1.26.
- NM.ethtool_optname_is_eee(optname)¶
- Parameters:
- Returns:
True
, if optname is valid- Return type:
Checks whether optname is a valid option name for an eee setting.
New in version 1.46.
- NM.ethtool_optname_is_feature(optname)¶
- Parameters:
- Returns:
True
, if optname is validNote that
NM.ethtool_optname_is_feature
() was first added to the libnm header files in 1.14.0 but forgot to actually add to the library. This happened belatedly in 1.20.0 and the stable versions 1.18.2, 1.16.4 and 1.14.8 (with linker version “libnm_1_14_8”).- Return type:
Checks whether optname is a valid option name for an offload feature.
New in version 1.20.
- NM.ethtool_optname_is_pause(optname)¶
- Parameters:
- Returns:
True
, if optname is valid- Return type:
Checks whether optname is a valid option name for a pause setting.
New in version 1.32.
- NM.ethtool_optname_is_ring(optname)¶
- Parameters:
- Returns:
True
, if optname is valid- Return type:
Checks whether optname is a valid option name for a ring setting.
New in version 1.26.
- NM.ip_route_attribute_validate(name, value, family)¶
- Parameters:
name (
str
) – the attribute namevalue (
GLib.Variant
) – the attribute valuefamily (
int
) – IP address family of the route
- Raises:
- Returns:
True
if the attribute is valid,False
otherwise- known:
on return, whether the attribute name is a known one
- Return type:
Validates a route attribute, i.e. checks that the attribute is a known one and the value is of the correct type and well-formed.
New in version 1.8.
- NM.ip_route_get_variant_attribute_spec()¶
- Returns:
the specifiers for route attributes
- Return type:
New in version 1.8.
- NM.ip_routing_rule_from_string(str, to_string_flags, extra_args)¶
- Parameters:
str (
str
) – the string representation to convert to anNM.IPRoutingRule
to_string_flags (
NM.IPRoutingRuleAsStringFlags
) –NM.IPRoutingRuleAsStringFlags
for controlling the string conversion.extra_args ({
object
:object
} orNone
) – extra arguments for controlling the string conversion. Currently, not extra arguments are supported.
- Raises:
- Returns:
the new
NM.IPRoutingRule
orNone
on error.- Return type:
New in version 1.18.
- NM.keyfile_read(keyfile, base_dir, handler_flags, handler, *user_data)¶
- Parameters:
keyfile (
GLib.KeyFile
) – the keyfile from which to create the connectionbase_dir (
str
) – when reading certificates from files with relative name, the relative path is made absolute using base_dir. This must be an absolute path.handler_flags (
NM.KeyfileHandlerFlags
) – theNM.KeyfileHandlerFlags
.handler (
NM.KeyfileReadHandler
orNone
) – read handler
- Raises:
- Returns:
on success, returns the created connection.
- Return type:
Tries to create a
NM.Connection
from a keyfile. The resulting keyfile is not normalized and might not even verify.New in version 1.30.
- NM.keyfile_write(connection, handler_flags, handler, *user_data)¶
- Parameters:
connection (
NM.Connection
) – theNM.Connection
to persist to keyfile.handler_flags (
NM.KeyfileHandlerFlags
) – theNM.KeyfileHandlerFlags
.handler (
NM.KeyfileWriteHandler
orNone
) – optional handler for events and to override the default behavior.
- Raises:
- Returns:
a new
GLib.KeyFile
orNone
on error.- Return type:
connection should verify as a valid profile according to
NM.Connection.verify
(). If it does not verify, the keyfile may be incomplete and the parser may not be able to fully recreate the original profile.New in version 1.30.
- NM.range_from_str(str)¶
- Parameters:
str (
str
) – the string representation of a range- Raises:
- Returns:
- Return type:
Parses the string representation of the range to create a
NM.Range
instance.New in version 1.42.
- NM.sriov_vf_attribute_validate(name, value)¶
- Parameters:
name (
str
) – the attribute namevalue (
GLib.Variant
) – the attribute value
- Raises:
- Returns:
True
if the attribute is valid,False
otherwise- known:
on return, whether the attribute name is a known one
- Return type:
Validates a VF attribute, i.e. checks that the attribute is a known one, the value is of the correct type and well-formed.
New in version 1.42.
- NM.utils_ap_mode_security_valid(type, wifi_caps)¶
- Parameters:
type (
NM.UtilsSecurityType
) – the security type to check device capabilities against, e.g.NM.UtilsSecurityType.STATIC_WEP
wifi_caps (
NM.DeviceWifiCapabilities
) – bitfield of the capabilities of the specific Wi-Fi device, e.g.NM.DeviceWifiCapabilities.CIPHER_WEP40
- Returns:
True
if the device capabilities are compatible with the desired type,False
if they are not.- Return type:
Given a set of device capabilities, and a desired security type to check against, determines whether the combination of device capabilities and desired security type are valid for AP/Hotspot connections.
- NM.utils_base64secret_decode(base64_key, required_key_len)¶
- Parameters:
- Returns:
True
if the input key is a valid base64 encoded key with required_key_len bytes.- out_key:
an optional output buffer for the binary key. If given, it will be filled with exactly required_key_len bytes.
- Return type:
New in version 1.16.
- NM.utils_bin2hexstr(src, final_len)¶
- Parameters:
- Returns:
the textual form of bytes
- Return type:
Converts the byte array src into a hexadecimal string. If final_len is greater than -1, the returned string is terminated at that index (returned_string[final_len] == ‘\0’),
- NM.utils_bond_mode_int_to_string(mode)¶
- Parameters:
mode (
int
) – bonding mode as a numeric value- Returns:
bonding mode string, or
None
on error- Return type:
Convert bonding mode from integer value to descriptive name. See https://www.kernel.org/doc/Documentation/networking/bonding.txt for available modes.
New in version 1.2.
- NM.utils_bond_mode_string_to_int(mode)¶
- Parameters:
mode (
str
) – bonding mode as string- Returns:
numeric bond mode, or -1 on error
- Return type:
Convert bonding mode from string representation to numeric value. See https://www.kernel.org/doc/Documentation/networking/bonding.txt for available modes. The mode string can be either a descriptive name or a number (as string).
New in version 1.2.
- NM.utils_check_virtual_device_compatibility(virtual_type, other_type)¶
- Parameters:
virtual_type (
GObject.GType
) – a virtual connection typeother_type (
GObject.GType
) – a connection type to test against virtual_type
- Returns:
- Return type:
Determines if a connection of type virtual_type can (in the general case) work with connections of type other_type.
If virtual_type is %NM_TYPE_SETTING_VLAN, then this checks if other_type is a valid type for the parent of a VLAN.
If virtual_type is a “master” type (eg, %NM_TYPE_SETTING_BRIDGE), then this checks if other_type is a valid type for a slave of that master.
Note that even if this returns
True
it is not guaranteed that every connection of type other_type is compatible with virtual_type; it may depend on the exact configuration of the two connections, or on the capabilities of an underlying device driver.
- NM.utils_ensure_gtypes()¶
This ensures that all
NM.Setting
GTypes are created. For example, after this call,GObject.type_from_name
(”NM.SettingConnection
") will work.This cannot fail and does nothing if the type already exists.
New in version 1.42.
- NM.utils_enum_from_str(type, str)¶
- Parameters:
type (
GObject.GType
) – theGObject.GType
of the enumstr (
str
) – the input string
- Returns:
True
if the conversion was successful,False
otherwise- out_value:
the output value
- err_token:
location to store the first unrecognized token
- Return type:
Converts a string to the matching enum value.
If the enum is a
GObject.TYPE_FLAGS
the function returns the logical OR of values matching the comma-separated tokens in the string; if an unknown token is found the function returnsFalse
and stores a pointer to a newly allocated string containing the unrecognized token in err_token.New in version 1.2.
- NM.utils_enum_get_values(type, from_, to)¶
- Parameters:
type (
GObject.GType
) – theGObject.GType
of the enumfrom (
int
) – the first element to be returnedto (
int
) – the last element to be returned
- Returns:
a
None
-terminated dynamically-allocated array of static strings orNone
on error- Return type:
[
str
]
Returns the list of possible values for a given enum.
New in version 1.2.
- NM.utils_enum_to_str(type, value)¶
- Parameters:
type (
GObject.GType
) – theGObject.GType
of the enumvalue (
int
) – the value to be translated
- Returns:
a newly allocated string or
None
- Return type:
Converts an enum value to its string representation. If the enum is a
GObject.TYPE_FLAGS
the function returns a comma-separated list of matching values. If the value has no corresponding string representation, it is converted to a number. For enums it is converted to a decimal number, for flags to an (unsigned) hex number.New in version 1.2.
- NM.utils_escape_ssid(ssid)¶
- Parameters:
ssid (
bytes
) – pointer to a buffer containing the SSID data- Returns:
pointer to the escaped SSID, which uses an internal static buffer and will be overwritten by subsequent calls to this function
- Return type:
This function does a quick printable character conversion of the SSID, simply replacing embedded NULLs and non-printable characters with the hexadecimal representation of that character. Intended for debugging only, should not be used for display of SSIDs.
Warning: this function uses a static buffer. It is not thread-safe. Don’t use this function.
Deprecated since version 1.46: use
NM.utils_ssid_to_utf8
() orNM.utils_bin2hexstr
().
- NM.utils_file_is_certificate(filename)¶
- Parameters:
filename (
str
) – name of the file to test- Returns:
- Return type:
Tests if filename has a valid extension for an X.509 certificate file (“.cer”, “.crt”, “.der”, or “.pem”), and contains a certificate in a format recognized by NetworkManager.
- NM.utils_file_is_pkcs12(filename)¶
- Parameters:
filename (
str
) – name of the file to test- Returns:
- Return type:
Tests if filename is a PKCS# 12 file.
- NM.utils_file_is_private_key(filename)¶
- Parameters:
filename (
str
) – name of the file to test- Returns:
True
if the file is a private key,False
if it is not- out_encrypted:
on return, whether the file is encrypted
- Return type:
Tests if filename has a valid extension for an X.509 private key file (“.der”, “.key”, “.pem”, or “.p12”), and contains a private key in a format recognized by NetworkManager.
- NM.utils_file_search_in_paths(progname, try_first, paths, file_test_flags, predicate, *user_data)¶
- Parameters:
progname (
str
) – the helper program name, like “iptables” Must be a non-empty string, without path separator (/).try_first (
str
orNone
) – a custom path to try first before searching. It is silently ignored if it is empty or not an absolute path.paths (
str
orNone
) – aNone
terminated list of search paths. Can be empty orNone
, in which case only try_first is checked.file_test_flags (
GLib.FileTest
) – the flags passed toGLib.file_test
() when searching for progname. Set it to 0 to skip theGLib.file_test
().predicate (
NM.UtilsFileSearchInPathsPredicate
) – if given, pass the file name to this function for additional checks. This check is performed after the check for file_test_flags. You cannot omit both file_test_flags and predicate.user_data (
object
orNone
) – user data for predicate function.
- Raises:
- Returns:
the full path to the helper, if found, or
None
if not found. The returned string is not owned by the caller, but later invocations of the function might overwrite it.- Return type:
Searches for a progname file in a list of search paths.
- NM.utils_format_variant_attributes(attributes, attr_separator, key_value_separator)¶
- Parameters:
attributes ({
str
:GLib.Variant
}) – aGLib.HashTable
mapping attribute names toGLib.Variant
valuesattr_separator (
int
) – the attribute separator characterkey_value_separator (
int
) – character separating key and values
- Returns:
the string representing attributes, or
None
in case there are no attributes- Return type:
Format attributes to a string.
New in version 1.8.
- NM.utils_get_timestamp_msec()¶
- Returns:
time in milliseconds
- Return type:
Gets current time in milliseconds of CLOCK_BOOTTIME.
New in version 1.12.
- NM.utils_hexstr2bin(hex)¶
- Parameters:
hex (
str
) – a string of hexadecimal characters with optional ‘:’ separators- Returns:
the converted bytes, or
None
on error- Return type:
Converts a hexadecimal string hex into an array of bytes. The optional separator ‘:’ may be used between single or pairs of hexadecimal characters, eg “00:11” or “0:1”. Any “0x” at the beginning of hex is ignored. hex may not start or end with ‘:’.
- NM.utils_hwaddr_atoba(asc, length)¶
- Parameters:
- Returns:
a new
GLib.ByteArray
, orNone
if asc couldn’t be parsed- Return type:
Parses asc and converts it to binary form in a
GLib.ByteArray
. SeeNM.utils_hwaddr_aton
() if you don’t want aGLib.ByteArray
.
- NM.utils_hwaddr_aton(asc, buffer)¶
- Parameters:
- Returns:
buffer, or
None
if asc couldn’t be parsed or would be shorter or longer than length.- Return type:
Parses asc and converts it to binary form in buffer. Bytes in asc can be separated by colons (:), or hyphens (-), but not mixed.
- NM.utils_hwaddr_canonical(asc, length)¶
- Parameters:
asc (
str
) – the ASCII representation of a hardware addresslength (
int
) – the length of address that asc is expected to convert to (or -1 to accept any length up toNM.UTILS_HWADDR_LEN_MAX
)
- Returns:
the canonicalized address if asc appears to be a valid hardware address of the indicated length,
None
if not.- Return type:
Parses asc to see if it is a valid hardware address of the given length, and if so, returns it in canonical form (uppercase, with leading 0s as needed, and with colons rather than hyphens).
- NM.utils_hwaddr_len(type)¶
- Parameters:
type (
int
) – the type of address; eitherARPHRD_ETHER
orARPHRD_INFINIBAND
- Returns:
the length or zero if the type is unrecognized.
- Return type:
Returns the length in octets of a hardware address of type type.
Before 1.28, it was an error to call this function with any value other than
ARPHRD_ETHER
orARPHRD_INFINIBAND
.
- NM.utils_hwaddr_matches(hwaddr1, hwaddr1_len, hwaddr2, hwaddr2_len)¶
- Parameters:
- Returns:
True
if hwaddr1 and hwaddr2 are equivalent,False
if they are different (or either of them is invalid).- Return type:
Generalized hardware address comparison function. Tests if hwaddr1 and hwaddr2 “equal” (or more precisely, “equivalent”), with several advantages over a simple memcmp():
If hwaddr1_len or hwaddr2_len is -1, then the corresponding address is assumed to be ASCII rather than binary, and will be converted to binary before being compared.
If hwaddr1 or hwaddr2 is
None
, it is treated instead as though it was a zero-filled buffer hwaddr1_len or hwaddr2_len bytes long.If hwaddr1 and hwaddr2 are InfiniBand hardware addresses (that is, if they are
INFINIBAND_ALEN
bytes long in binary form) then only the last 8 bytes are compared, since those are the only bytes that actually identify the hardware. (The other 12 bytes will change depending on the configuration of the InfiniBand fabric that the device is connected to.)If a passed-in ASCII hardware address cannot be parsed, or would parse to an address larger than
NM.UTILS_HWADDR_LEN_MAX
, then it will silently fail to match. (This means that externally-provided address strings do not need to be sanity-checked before comparing them against known good addresses; they are guaranteed to not match if they are invalid.)
- NM.utils_hwaddr_ntoa(addr)¶
- Parameters:
addr (
bytes
) – a binary hardware address- Returns:
the textual form of addr
- Return type:
Converts addr to textual form.
- NM.utils_hwaddr_valid(asc, length)¶
- Parameters:
asc (
str
) – the ASCII representation of a hardware addresslength (
int
) – the length of address that asc is expected to convert to (or -1 to accept any length up toNM.UTILS_HWADDR_LEN_MAX
)
- Returns:
True
if asc appears to be a valid hardware address of the indicated length,False
if not.- Return type:
Parses asc to see if it is a valid hardware address of the given length.
- NM.utils_iface_valid_name(name)¶
- Parameters:
- Returns:
True
if interface name is valid, otherwiseFalse
is returned.Before 1.20, this function did not accept
None
as name argument. If you want to run against older versions of libnm, don’t passNone
.- Return type:
Validate the network interface name.
Deprecated since version 1.6: Use
NM.utils_is_valid_iface_name
() instead, with better error reporting.
- NM.utils_ip4_addresses_from_variant(value)¶
- Parameters:
value (
GLib.Variant
) – aGLib.Variant
of type ‘aau’- Returns:
a newly allocated
GLib.PtrArray
ofNM.IPAddress
objects- out_gateway:
on return, will contain the IP gateway
- Return type:
([
NM.IPAddress
], out_gateway:str
orNone
)
Utility function to convert a
GLib.Variant
of type ‘aau’ representing a list of NetworkManager IPv4 addresses (which are tuples of address, prefix, and gateway) into aGLib.PtrArray
ofNM.IPAddress
objects. The “gateway” field of the first address (if set) will be returned in out_gateway; the “gateway” fields of the other addresses are ignored. Note that invalid addresses are discarded but the valid addresses are still returned.Since 1.46, an empty list is returned if the variant type is not valid (before it was checked as assertion)
- NM.utils_ip4_addresses_to_variant(addresses, gateway)¶
- Parameters:
addresses ([
NM.IPAddress
]) – an array ofNM.IPAddress
objects
- Returns:
a new floating
GLib.Variant
representing addresses.- Return type:
Utility function to convert a
GLib.PtrArray
ofNM.IPAddress
objects representing IPv4 addresses into aGLib.Variant
of type ‘aau’ representing an array of NetworkManager IPv4 addresses (which are tuples of address, prefix, and gateway). The “gateway” field of the first address will get the value of gateway (if non-None
). In all of the other addresses, that field will be 0.
- NM.utils_ip4_dns_from_variant(value)¶
- Parameters:
value (
GLib.Variant
) – aGLib.Variant
of type ‘au’- Returns:
a
None
-terminated array of IP address strings.- Return type:
Utility function to convert a
GLib.Variant
of type ‘au’ representing a list of IPv4 addresses into an array of IP address strings.Since 1.46, an empty list is returned if the variant type is not valid (before it was checked as assertion)
- NM.utils_ip4_dns_to_variant(dns)¶
- Parameters:
dns (
str
) – an array of IP address strings- Returns:
a new floating
GLib.Variant
representing dns.- Return type:
Utility function to convert an array of IP address strings int a
GLib.Variant
of type ‘au’ representing an array of IPv4 addresses.
- NM.utils_ip4_get_default_prefix(ip)¶
- Parameters:
ip (
int
) – an IPv4 address (in network byte order)- Returns:
the default class prefix for the given IP
- Return type:
When the Internet was originally set up, various ranges of IP addresses were segmented into three network classes: A, B, and C. This function will return a prefix that is associated with the IP address specified defining where it falls in the predefined classes.
- NM.utils_ip4_netmask_to_prefix(netmask)¶
- Parameters:
netmask (
int
) – an IPv4 netmask in network byte order. Usually the netmask has all leading bits up to the prefix set so that the netmask is identical to having the first prefix bits of the address set. If that is not the case and there are “holes” in the mask, the prefix is determined based on the lowest bit set.- Returns:
the CIDR prefix represented by the netmask
- Return type:
- NM.utils_ip4_prefix_to_netmask(prefix)¶
- NM.utils_ip4_routes_from_variant(value)¶
- Parameters:
value (
GLib.Variant
) –GLib.Variant
of type ‘aau’- Returns:
a newly allocated
GLib.PtrArray
ofNM.IPRoute
objects- Return type:
Utility function to convert a
GLib.Variant
of type ‘aau’ representing an array of NetworkManager IPv4 routes (which are tuples of route, prefix, next hop, and metric) into aGLib.PtrArray
ofNM.IPRoute
objects. Note that invalid routes are discarded but the valid routes are still returned.Since 1.46, an empty list is returned if the variant type is not valid (before it was checked as assertion)
- NM.utils_ip4_routes_to_variant(routes)¶
- Parameters:
routes ([
NM.IPRoute
]) – an array of #NMIP4Route objects- Returns:
a new floating
GLib.Variant
representing routes.- Return type:
Utility function to convert a
GLib.PtrArray
ofNM.IPRoute
objects representing IPv4 routes into aGLib.Variant
of type ‘aau’ representing an array of NetworkManager IPv4 routes (which are tuples of route, prefix, next hop, and metric).
- NM.utils_ip6_addresses_from_variant(value)¶
- Parameters:
value (
GLib.Variant
) – aGLib.Variant
of type ‘a(ayuay)’- Returns:
a newly allocated
GLib.PtrArray
ofNM.IPAddress
objects- out_gateway:
on return, will contain the IP gateway
- Return type:
([
NM.IPAddress
], out_gateway:str
orNone
)
Utility function to convert a
GLib.Variant
of type ‘a(ayuay)’ representing a list of NetworkManager IPv6 addresses (which are tuples of address, prefix, and gateway) into aGLib.PtrArray
ofNM.IPAddress
objects. The “gateway” field of the first address (if set) will be returned in out_gateway; the “gateway” fields of the other addresses are ignored. Note that invalid addresses are discarded but the valid addresses are still returned.Since 1.46, an empty list is returned if the variant type is not valid (before it was checked as assertion)
- NM.utils_ip6_addresses_to_variant(addresses, gateway)¶
- Parameters:
addresses ([
NM.IPAddress
]) – an array ofNM.IPAddress
objects
- Returns:
a new floating
GLib.Variant
representing addresses.- Return type:
Utility function to convert a
GLib.PtrArray
ofNM.IPAddress
objects representing IPv6 addresses into aGLib.Variant
of type ‘a(ayuay)’ representing an array of NetworkManager IPv6 addresses (which are tuples of address, prefix, and gateway). The “gateway” field of the first address will get the value of gateway (if non-None
). In all of the other addresses, that field will be all 0s.
- NM.utils_ip6_dns_from_variant(value)¶
- Parameters:
value (
GLib.Variant
) – aGLib.Variant
of type ‘aay’- Returns:
a
None
-terminated array of IP address strings.- Return type:
Utility function to convert a
GLib.Variant
of type ‘aay’ representing a list of IPv6 addresses into an array of IP address strings. Each “ay” entry must be a IPv6 address in binary form (16 bytes long). Invalid entries are silently ignored.Since 1.46, an empty list is returned if the variant type is not valid (before it was checked as assertion)
- NM.utils_ip6_dns_to_variant(dns)¶
- Parameters:
dns (
str
) – an array of IP address strings- Returns:
a new floating
GLib.Variant
representing dns.- Return type:
Utility function to convert an array of IP address strings int a
GLib.Variant
of type ‘aay’ representing an array of IPv6 addresses.If a string cannot be parsed, it will be silently ignored.
- NM.utils_ip6_routes_from_variant(value)¶
- Parameters:
value (
GLib.Variant
) –GLib.Variant
of type ‘a(ayuayu)’- Returns:
a newly allocated
GLib.PtrArray
ofNM.IPRoute
objects- Return type:
Utility function to convert a
GLib.Variant
of type ‘a(ayuayu)’ representing an array of NetworkManager IPv6 routes (which are tuples of route, prefix, next hop, and metric) into aGLib.PtrArray
ofNM.IPRoute
objects. Note that invalid routes are ignored but the valid ones are still returned.Since 1.46, an empty list is returned if the variant type is not valid (before it was checked as assertion)
- NM.utils_ip6_routes_to_variant(routes)¶
- Parameters:
routes ([
NM.IPRoute
]) – an array ofNM.IPRoute
objects- Returns:
a new floating
GLib.Variant
representing routes.- Return type:
Utility function to convert a
GLib.PtrArray
ofNM.IPRoute
objects representing IPv6 routes into aGLib.Variant
of type ‘a(ayuayu)’ representing an array of NetworkManager IPv6 routes (which are tuples of route, prefix, next hop, and metric).
- NM.utils_ip_addresses_from_variant(value, family)¶
- Parameters:
value (
GLib.Variant
) – aGLib.Variant
of type ‘aa{sv}’family (
int
) – an IP address family
- Returns:
a newly allocated
GLib.PtrArray
ofNM.IPAddress
objects- Return type:
Utility function to convert a
GLib.Variant
representing a list of new-style NetworkManager IPv4 or IPv6 addresses (as described in the documentation forNM.utils_ip_addresses_to_variant
()) into aGLib.PtrArray
ofNM.IPAddress
objects. Note that invalid addresses are discarded but the valid addresses are still returned.Since 1.46, an empty list is returned if the variant type is not valid (before it was checked as assertion)
New in version 1.42.
- NM.utils_ip_addresses_to_variant(addresses)¶
- Parameters:
addresses ([
NM.IPAddress
]) – an array ofNM.IPAddress
objects- Returns:
a new floating
GLib.Variant
representing addresses.- Return type:
Utility function to convert a
GLib.PtrArray
ofNM.IPAddress
objects representing IPv4 or IPv6 addresses into aGLib.Variant
of type ‘aa{sv}’ representing an array of new-style NetworkManager IP addresses. All addresses will include “address” (an IP address string), and “prefix” (a uint). Some addresses may include additional attributes.New in version 1.42.
- NM.utils_ip_routes_from_variant(value, family)¶
- Parameters:
value (
GLib.Variant
) – aGLib.Variant
of type ‘aa{sv}’family (
int
) – an IP address family
- Returns:
a newly allocated
GLib.PtrArray
ofNM.IPRoute
objects- Return type:
Utility function to convert a
GLib.Variant
representing a list of new-style NetworkManager IPv4 or IPv6 addresses (as described in the documentation forNM.utils_ip_routes_to_variant
()) into aGLib.PtrArray
ofNM.IPRoute
objects. Invalid routes are discarded but the valid routes are still returned.Since 1.46, an empty list is returned if the variant type is not valid (before it was checked as assertion)
New in version 1.42.
- NM.utils_ip_routes_to_variant(routes)¶
- Parameters:
routes ([
NM.IPRoute
]) – an array ofNM.IPRoute
objects- Returns:
a new floating
GLib.Variant
representing routes.- Return type:
Utility function to convert a
GLib.PtrArray
ofNM.IPRoute
objects representing IPv4 or IPv6 routes into aGLib.Variant
of type ‘aa{sv}’ representing an array of new-style NetworkManager IP routes. All routes will include “dest” (an IP address string), “prefix” (an uint) and optionally “next-hop” (an IP address string) and “metric” (an uint). Some routes may include additional attributes. Note that invalid routes are discarded and only a warning is emitted, but the valid routes are still returned.New in version 1.42.
- NM.utils_ipaddr_valid(family, ip)¶
- Parameters:
- Returns:
- Return type:
Checks if ip contains a valid IP address of the given family.
- NM.utils_is_empty_ssid(ssid)¶
- Parameters:
ssid (
bytes
) – pointer to a buffer containing the SSID data- Returns:
- Return type:
Different manufacturers use different mechanisms for not broadcasting the AP’s SSID. This function attempts to detect blank/empty SSIDs using a number of known SSID-cloaking methods.
- NM.utils_is_json_object(str)¶
- Parameters:
str (
str
) – the JSON string to test- Raises:
- Returns:
whether the passed string is valid JSON. If libnm is not compiled with libjansson support, this check will also return
True
for possibly invalid inputs. If that is a problem for you, you must validate the JSON yourself.- Return type:
New in version 1.6.
- NM.utils_is_uuid(str)¶
- Parameters:
- Returns:
True
if str is a UUID,False
if notIn older versions,
NM.utils_is_uuid
() did not acceptNone
as str argument. Don’t passNone
if you run against older versions of libnm.- Return type:
Checks if str is a UUID
Deprecated since version 1.32: older versions of NetworkManager had a wrong understanding of what makes a valid UUID. This function can thus accept some inputs as valid, which in fact are not valid UUIDs.
- NM.utils_is_valid_iface_name(name)¶
- Parameters:
- Raises:
- Returns:
True
if interface name is valid, otherwiseFalse
is returned.Before 1.20, this function did not accept
None
as name argument. If you want to run against older versions of libnm, don’t passNone
.- Return type:
Validate the network interface name.
This function is a 1:1 copy of the kernel’s interface validation function in net/core/dev.c.
New in version 1.6.
- NM.utils_parse_variant_attributes(string, attr_separator, key_value_separator, ignore_unknown, spec)¶
- Parameters:
string (
str
) – the input stringattr_separator (
int
) – the attribute separator characterkey_value_separator (
int
) – character separating key and valuesignore_unknown (
bool
) – whether unknown attributes should be ignoredspec (
NM.VariantAttributeSpec
) – the attribute format specifiers
- Raises:
- Returns:
a
GLib.HashTable
mapping attribute names toGLib.Variant
values. Warning: the variant are still floating references, owned by the hash table. If you take a reference, ensure to sink the one of the hash table first.- Return type:
{
str
:GLib.Variant
}
Parse attributes from a string.
New in version 1.8.
- NM.utils_print(output_mode, msg)¶
- Parameters:
output_mode (
int
) – if 1 it uses g_print(). If 2, it uses g_printerr(). If 0, it uses the same output as internal libnm debug logging does. That is, depending on LIBNM_CLIENT_DEBUG’s “stdout” flag it uses g_print() or g_printerr() and if LIBNM_CLIENT_DEBUG_FILE is set, it writes the output to file insteadmsg (
str
) – the message to print. The function does not append a trailing newline.
The only purpose of this function is to give access to g_print() or g_printerr() from pygobject. libnm can do debug logging by setting LIBNM_CLIENT_DEBUG and uses thereby g_printerr() or g_print(). A plain “print()” function in python is not in sync with these functions (it implements additional buffering). By using
NM.utils_print
(), the same logging mechanisms can be used.LIBNM_CLIENT_DEBUG is a list of keywords separated by commas. The keyword “trace” enables printing messages of the lowest up to the highest severity. Likewise, the severities “debug”, “warn” (“warning”) and “error” are honored in similar way. Setting the flags “ERROR” or “WARN” (“WARNING”) implies that respective levels are enabled, but also are ERROR messages printed with g_critical() and WARN messages with g_warning(). Together with G_DEBUG=”fatal-warnings” or G_DEBUG=”fatal-critical” this can be used to abort the program on errors. Note that all <error> messages imply an unexpected data on the D-Bus API (due to a bug). <warn> also implies unexepected data, but that can happen when using different versions of libnm and daemon. For testing, it is good to turn these into assertions.
By default, messages are printed to stderr, unless LIBNM_CLIENT_DEBUG contains “stdout” flag. Also, libnm honors LIBNM_CLIENT_DEBUG_FILE environment. If this is set to a filename pattern (accepting “%%p” for the process ID), then the debug log is written to that file instead of stderr/stdout. With output_mode zero, the same location will be written.
LIBNM_CLIENT_DEBUG_FILE is supported since 1.44. “ERROR”, “WARN” and “WARNING” are supported since 1.46.
New in version 1.30.
- NM.utils_same_ssid(ssid1, ssid2, ignore_trailing_null)¶
- Parameters:
- Returns:
- Return type:
Earlier versions of the Linux kernel added a
None
byte to the end of the SSID to enable easy printing of the SSID on the console or in a terminal, but this behavior was problematic (SSIDs are simply byte arrays, not strings) and thus was changed. This function compensates for that behavior at the cost of some compatibility with odd SSIDs that may legitimately have trailing NULLs, even though that is functionally pointless.
- NM.utils_security_valid(type, wifi_caps, have_ap, adhoc, ap_flags, ap_wpa, ap_rsn)¶
- Parameters:
type (
NM.UtilsSecurityType
) – the security type to check AP flags and device capabilities against, e.g.NM.UtilsSecurityType.STATIC_WEP
wifi_caps (
NM.DeviceWifiCapabilities
) – bitfield of the capabilities of the specific Wi-Fi device, e.g.NM.DeviceWifiCapabilities.CIPHER_WEP40
have_ap (
bool
) – whether the ap_flags, ap_wpa, and ap_rsn arguments are validadhoc (
bool
) – whether the capabilities being tested are from an Ad-Hoc AP (IBSS)ap_flags (
NM.80211ApFlags
) – bitfield of AP capabilities, e.g.NM._80211ApFlags.PRIVACY
ap_wpa (
NM.80211ApSecurityFlags
) – bitfield of AP capabilities derived from the AP’s WPA beacon, e.g. (NM._80211ApSecurityFlags.PAIR_TKIP
|NM._80211ApSecurityFlags.KEY_MGMT_PSK
)ap_rsn (
NM.80211ApSecurityFlags
) – bitfield of AP capabilities derived from the AP’s RSN/WPA2 beacon, e.g. (NM._80211ApSecurityFlags.PAIR_CCMP
|NM._80211ApSecurityFlags.PAIR_TKIP
)
- Returns:
True
if the device capabilities and AP capabilities intersect and are compatible with the desired type,False
if they are not- Return type:
Given a set of device capabilities, and a desired security type to check against, determines whether the combination of device, desired security type, and AP capabilities intersect.
NOTE: this function cannot handle checking security for AP/Hotspot mode; use
NM.utils_ap_mode_security_valid
() instead.
- NM.utils_sriov_vf_from_str(str)¶
- Parameters:
str (
str
) – the input string- Raises:
- Returns:
the virtual function object
- Return type:
Converts a string to a SR-IOV virtual function object.
New in version 1.14.
- NM.utils_sriov_vf_to_str(vf, omit_index)¶
- Parameters:
vf (
NM.SriovVF
) – theNM.SriovVF
omit_index (
bool
) – ifTrue
, the VF index will be omitted from output string
- Raises:
- Returns:
a newly allocated string or
None
on error- Return type:
Converts a SR-IOV virtual function object to its string representation.
New in version 1.14.
- NM.utils_ssid_to_utf8(ssid)¶
- Parameters:
ssid (
bytes
) – pointer to a buffer containing the SSID data- Returns:
an allocated string containing a UTF-8 representation of the SSID, which must be freed by the caller using
GLib.free
(). ReturnsNone
on errors.- Return type:
Wi-Fi SSIDs are byte arrays, they are _not_ strings. Thus, an SSID may contain embedded NULLs and other unprintable characters. Often it is useful to print the SSID out for debugging purposes, but that should be the _only_ use of this function. Do not use this function for any persistent storage of the SSID, since the printable SSID returned from this function cannot be converted back into the real SSID of the access point.
This function does almost everything humanly possible to convert the input into a printable UTF-8 string, using roughly the following procedure:
if the input data is already UTF-8 safe, no conversion is performed
2) attempts to get the current system language from the LANG environment variable, and depending on the language, uses a table of alternative encodings to try. For example, if LANG=hu_HU, the table may first try the ISO-8859-2 encoding, and if that fails, try the Windows-1250 encoding. If all fallback encodings fail, replaces non-UTF-8 characters with ‘?’. 3) If the system language was unable to be determined, falls back to the ISO-8859-1 encoding, then to the Windows-1251 encoding. 4) If step 3 fails, replaces non-UTF-8 characters with ‘?’.
Again, this function should be used for debugging and display purposes _only_.
- NM.utils_tc_action_from_str(str)¶
- Parameters:
str (
str
) – the string representation of a action- Raises:
- Returns:
the
NM.TCAction
orNone
- Return type:
Parses the tc style string action representation of the queueing discipline to a
NM.TCAction
instance. Supports a subset of the tc language.New in version 1.12.
- NM.utils_tc_action_to_str(action)¶
- Parameters:
action (
NM.TCAction
) – theNM.TCAction
- Raises:
- Returns:
formatted string or
None
- Return type:
Turns the
NM.TCAction
into a tc style string representation of the queueing discipline.New in version 1.12.
- NM.utils_tc_qdisc_from_str(str)¶
- Parameters:
str (
str
) – the string representation of a qdisc- Raises:
- Returns:
the
NM.TCQdisc
orNone
- Return type:
Parses the tc style string qdisc representation of the queueing discipline to a
NM.TCQdisc
instance. Supports a subset of the tc language.New in version 1.12.
- NM.utils_tc_qdisc_to_str(qdisc)¶
- Parameters:
qdisc (
NM.TCQdisc
) – theNM.TCQdisc
- Raises:
- Returns:
formatted string or
None
- Return type:
Turns the
NM.TCQdisc
into a tc style string representation of the queueing discipline.New in version 1.12.
- NM.utils_tc_tfilter_from_str(str)¶
- Parameters:
str (
str
) – the string representation of a tfilter- Raises:
- Returns:
the
NM.TCTfilter
orNone
- Return type:
Parses the tc style string tfilter representation of the queueing discipline to a
NM.TCTfilter
instance. Supports a subset of the tc language.New in version 1.12.
- NM.utils_tc_tfilter_to_str(tfilter)¶
- Parameters:
tfilter (
NM.TCTfilter
) – theNM.TCTfilter
- Raises:
- Returns:
formatted string or
None
- Return type:
Turns the
NM.TCTfilter
into a tc style string representation of the queueing discipline.New in version 1.12.
- NM.utils_uuid_generate()¶
- Returns:
a newly allocated UUID suitable for use as the
NM.SettingConnection
object’sNM.SettingConnection
:id
: property. Should be freed withGLib.free
()- Return type:
- NM.utils_version()¶
- Returns:
the version ID of the libnm version. That is, the %NM_VERSION at runtime.
- Return type:
New in version 1.6.
- NM.utils_wep_key_valid(key, wep_type)¶
- Parameters:
key (
str
) – a string that might be a WEP keywep_type (
NM.WepKeyType
) – theNM.WepKeyType
type of the WEP key
- Returns:
- Return type:
Checks if key is a valid WEP key
- NM.utils_wifi_2ghz_freqs()¶
- Returns:
zero-terminated array of frequencies numbers (in MHz)
- Return type:
Utility function to return 2.4 GHz Wi-Fi frequencies (802.11bg band).
New in version 1.2.
- NM.utils_wifi_5ghz_freqs()¶
- Returns:
zero-terminated array of frequencies numbers (in MHz)
- Return type:
Utility function to return 5 GHz Wi-Fi frequencies (802.11a band).
New in version 1.2.
- NM.utils_wifi_channel_to_freq(channel, band)¶
- Parameters:
- Returns:
the frequency represented by the channel of the band, or -1 when the freq is invalid, or 0 when the band is invalid
- Return type:
Utility function to translate a Wi-Fi channel to its corresponding frequency.
- NM.utils_wifi_find_next_channel(channel, direction, band)¶
- Parameters:
- Returns:
the next channel in the specified direction or 0
- Return type:
Utility function to find out next/previous Wi-Fi channel for a channel.
- NM.utils_wifi_freq_to_channel(freq)¶
- Parameters:
freq (
int
) – frequency- Returns:
the channel represented by the frequency or 0
- Return type:
Utility function to translate a Wi-Fi frequency to its corresponding channel.
- NM.utils_wifi_is_channel_valid(channel, band)¶
- Parameters:
- Returns:
- Return type:
Utility function to verify Wi-Fi channel validity.
- NM.utils_wifi_strength_bars(strength)¶
- Parameters:
strength (
int
) – the access point strength, from 0 to 100- Returns:
the graphical representation of the access point strength
- Return type:
Converts strength into a 4-character-wide graphical representation of strength suitable for printing to stdout.
Previous versions used to take a guess at the terminal type and possibly return a wide UTF-8 encoded string. Now it always returns a 7-bit clean strings of one to 0 to 4 asterisks. Users that actually need the functionality are encouraged to make their implementations instead.
- NM.utils_wpa_psk_valid(psk)¶
- Parameters:
psk (
str
) – a string that might be a WPA PSK- Returns:
- Return type:
Checks if psk is a valid WPA PSK
- NM.vpn_editor_plugin_load(plugin_name, check_service)¶
- Parameters:
- Raises:
- Returns:
a new plugin instance or
None
on error.- Return type:
Load the shared library plugin_name and create a new
NM.VpnEditorPlugin
instance via the #NMVpnEditorPluginFactory function.This is similar to
NM.VpnEditorPlugin.load_from_file
(), but it does no validation of the plugin name, instead passes it directly to dlopen(). If you have the full path to a plugin file,NM.VpnEditorPlugin.load_from_file
() is preferred.New in version 1.4.
- NM.vpn_editor_plugin_load_from_file(plugin_name, check_service, check_owner, check_file, *user_data)¶
- Parameters:
plugin_name (
str
) – The path or name of the shared library to load. The path must either be an absolute filename to an existing file. Alternatively, it can be the name (without path) of a library in the plugin directory of NetworkManager.check_service (
str
) – if not-null, check that the loaded plugin advertises the given service.check_owner (
int
) – if non-negative, check whether the file is owned by UID check_owner or by root. In this case also check that the file is not writable by anybody else.check_file (
NM.UtilsCheckFilePredicate
) – optional callback to validate the file prior to loading the shared library.
- Raises:
- Returns:
a new plugin instance or
None
on error.- Return type:
Load the shared library plugin_name and create a new
NM.VpnEditorPlugin
instance via the #NMVpnEditorPluginFactory function.If plugin_name is not an absolute path name, it assumes the file is in the plugin directory of NetworkManager. In any case, the call will do certain checks on the file before passing it to dlopen. A consequence for that is, that you cannot omit the “.so” suffix as you could for
NM.VpnEditorPlugin.load
().New in version 1.2.