netutils

Network-related utilities and helper functions.

oslo_utils.netutils.get_ipv6_addr_by_EUI64(prefix, mac)

Calculate IPv6 address using EUI-64 specification.

This method calculates the IPv6 address using the EUI-64 addressing scheme as explained in rfc2373.

Parameters:
  • prefix – IPv6 prefix.
  • mac – IEEE 802 48-bit MAC address.
Returns:

IPv6 address on success.

Raises ValueError, TypeError:
 

For any invalid input.

oslo_utils.netutils.get_my_ipv4()

Returns the actual ipv4 of the local machine.

This code figures out what source address would be used if some traffic were to be sent out to some well known address on the Internet. In this case, IP from RFC5737 is used, but the specific address does not matter much. No traffic is actually sent.

oslo_utils.netutils.is_ipv6_enabled()

Check if IPv6 support is enabled on the platform.

This api will look into the proc entries of the platform to figure out the status of IPv6 support on the platform.

Returns:True if the platform has IPv6 support, False otherwise.
oslo_utils.netutils.is_valid_ip(address)

Verify that address represents a valid IP address.

Parameters:address (string) – Value to verify
Returns:bool
oslo_utils.netutils.is_valid_ipv4(address)

Verify that address represents a valid IPv4 address.

Parameters:address (string) – Value to verify
Returns:bool
oslo_utils.netutils.is_valid_ipv6(address)

Verify that address represents a valid IPv6 address.

Parameters:address (string) – Value to verify
Returns:bool
oslo_utils.netutils.is_valid_port(port)

Verify that port represents a valid port number.

oslo_utils.netutils.parse_host_port(address, default_port=None)

Interpret a string as a host:port pair.

An IPv6 address MUST be escaped if accompanied by a port, because otherwise ambiguity ensues: 2001:db8:85a3::8a2e:370:7334 means both [2001:db8:85a3::8a2e:370:7334] and [2001:db8:85a3::8a2e:370]:7334.

>>> parse_host_port('server01:80')
('server01', 80)
>>> parse_host_port('server01')
('server01', None)
>>> parse_host_port('server01', default_port=1234)
('server01', 1234)
>>> parse_host_port('[::1]:80')
('::1', 80)
>>> parse_host_port('[::1]')
('::1', None)
>>> parse_host_port('[::1]', default_port=1234)
('::1', 1234)
>>> parse_host_port('2001:db8:85a3::8a2e:370:7334', default_port=1234)
('2001:db8:85a3::8a2e:370:7334', 1234)
>>> parse_host_port(None)
(None, None)
oslo_utils.netutils.set_tcp_keepalive(sock, tcp_keepalive=True, tcp_keepidle=None, tcp_keepalive_interval=None, tcp_keepalive_count=None)

Set values for tcp keepalive parameters

This function configures tcp keepalive parameters if users wish to do so.

Parameters:
  • tcp_keepalive – Boolean, turn on or off tcp_keepalive. If users are not sure, this should be True, and default values will be used.
  • tcp_keepidle – time to wait before starting to send keepalive probes
  • tcp_keepalive_interval – time between successive probes, once the initial wait time is over
  • tcp_keepalive_count – number of probes to send before the connection is killed
oslo_utils.netutils.urlsplit(url, scheme='', allow_fragments=True)

Parse a URL using urlparse.urlsplit(), splitting query and fragments. This function papers over Python issue9374 when needed.

The parameters are the same as urlparse.urlsplit.

Previous topic

importutils

Next topic

strutils

This Page