neutron_lib.utils.net module

class neutron_lib.utils.net.AuthenticEUI(addr, **kwargs)

Bases: _AuthenticBase, EUI

AuthenticEUI class

This class retains the format of the MAC address string passed during initialization.

This is useful when we want to make sure that we retain the format passed by a user through API.

class neutron_lib.utils.net.AuthenticIPNetwork(addr, **kwargs)

Bases: _AuthenticBase, IPNetwork

AuthenticIPNetwork class

This class retains the format of the IP network string passed during initialization.

This is useful when we want to make sure that we retain the format passed by a user through API.

neutron_lib.utils.net.get_hostname()

Get the hostname of the system.

Returns:

The hostname of the system.

neutron_lib.utils.net.get_random_mac(base_mac)

Get a random MAC address string of the specified base format.

The first 3 octets will remain unchanged. If the 4th octet is not 00, it will also be used. The others will be randomly generated.

Parameters:

base_mac – Base MAC address represented by an array of 6 strings/int

Returns:

The MAC address string.

neutron_lib.utils.net.is_port_trusted(port)

Used to determine if port can be trusted not to attack network.

Trust is currently based on the device_owner field starting with ‘network:’ since we restrict who can use that in the default policy.yaml file.

Parameters:

port – The port dict to inspect the ‘device_owner’ for.

Returns:

True if the port dict’s ‘device_owner’ value starts with the networking prefix. False otherwise.

neutron_lib.utils.net.random_mac_generator(base_mac)

Generates random mac addresses from a specified base format.

The first 3 octets of each MAC address will remain unchanged. If the 4th octet is not 00, it will also be used. The others will be randomly generated.

Parameters:

base_mac – Base mac address represented by an array of 6 strings.

Returns:

A mac address string generator.