neutron_lib.plugins.utils module

neutron_lib.plugins.utils.can_port_be_bound_to_virtual_bridge(port)

Returns if port can be bound to a virtual bridge (e.g.: LB, OVS)

Parameters:

port – (dict) A port dictionary.

Returns:

True if the port VNIC type is ‘normal’ or ‘smart-nic’; False in any other case.

neutron_lib.plugins.utils.create_network(core_plugin, context, net, check_allow_post=True)
neutron_lib.plugins.utils.create_port(core_plugin, context, port, check_allow_post=True)
neutron_lib.plugins.utils.create_subnet(core_plugin, context, subnet, check_allow_post=True)
neutron_lib.plugins.utils.delete_port_on_error(core_plugin, context, port_id)

A decorator that deletes a port upon exception.

This decorator can be used to wrap a block of code that should delete a port if an exception is raised during the block’s execution.

Parameters:
  • core_plugin – The core plugin implementing the delete_port method to call.

  • context – The context.

  • port_id – The port’s ID.

Returns:

None

neutron_lib.plugins.utils.get_deployment_physnet_mtu()

Retrieves global physical network MTU setting.

Plugins should use this function to retrieve the MTU set by the operator that is equal to or less than the MTU of their nodes’ physical interfaces. Note that it is the responsibility of the plugin to deduct the value of any encapsulation overhead required before advertising it to VMs.

Note that this function depends on the global_physnet_mtu config option being registered in the global CONF.

Returns:

The global_physnet_mtu from the global CONF.

neutron_lib.plugins.utils.get_interface_name(name, prefix='', max_len=15)

Construct an interface name based on the prefix and name.

The interface name can not exceed the maximum length passed in. Longer names are hashed to help ensure uniqueness.

neutron_lib.plugins.utils.get_port_binding_by_status_and_host(bindings, status, host='', raise_if_not_found=False, port_id=None)

Returns from an iterable the binding with the specified status and host.

The input iterable can contain zero or one binding in status ACTIVE and zero or many bindings in status INACTIVE. As a consequence, to unequivocally retrieve an inactive binding, the caller must specify a non empty value for host. If host is the empty string, the first binding satisfying the specified status will be returned. If no binding is found with the specified status and host, None is returned or PortBindingNotFound is raised if raise_if_not_found is True

Parameters:
  • bindings – An iterable containing port bindings

  • status – The status of the port binding to return. Possible values are ACTIVE or INACTIVE as defined in neutron_lib/constants.py.

  • host – str representing the host of the binding to return.

  • raise_if_not_found – If a binding is not found and this parameter is True, a PortBindingNotFound exception is raised

  • port_id – The id of the binding’s port

Returns:

The searched for port binding or None if it is not found

Raises:

PortBindingNotFound if the binding is not found and raise_if_not_found is True

neutron_lib.plugins.utils.in_pending_status(status)

Return True if status is a form of pending

neutron_lib.plugins.utils.is_valid_geneve_vni(vni)

Validate a Geneve VNI

Parameters:

vni – The VNI to validate.

Returns:

True if vni is a number that’s a valid Geneve VNI.

neutron_lib.plugins.utils.is_valid_gre_id(gre_id)

Validate a GRE ID.

Parameters:

gre_id – The GRE ID to validate.

Returns:

True if gre_id is a number that’s a valid GRE ID.

neutron_lib.plugins.utils.is_valid_vlan_tag(vlan)

Validate a VLAN tag.

Parameters:

vlan – The VLAN tag to validate.

Returns:

True if vlan is a number that is a valid VLAN tag.

neutron_lib.plugins.utils.is_valid_vxlan_vni(vni)

Validate a VXLAN VNI.

Parameters:

vni – The VNI to validate.

Returns:

True if vni is a number that’s a valid VXLAN VNI.

neutron_lib.plugins.utils.parse_network_vlan_range(network_vlan_range)

Parse a well formed network VLAN range string.

The network VLAN range string has the format:

network[:vlan_begin:vlan_end]

Parameters:

network_vlan_range – The network VLAN range string to parse.

Returns:

A tuple who’s 1st element is the network name and 2nd element is the VLAN range parsed from network_vlan_range.

Raises:

NetworkVlanRangeError if network_vlan_range is malformed. PhysicalNetworkNameError if network_vlan_range is missing a network name.

neutron_lib.plugins.utils.parse_network_vlan_ranges(network_vlan_ranges_cfg_entries)

Parse a list of well formed network VLAN range string.

Behaves like parse_network_vlan_range, but parses a list of network VLAN strings into an ordered dict.

Parameters:

network_vlan_ranges_cfg_entries – The list of network VLAN strings to parse.

Returns:

An OrderedDict who’s keys are network names and values are the list of VLAN ranges parsed.

Raises:

See parse_network_vlan_range.

neutron_lib.plugins.utils.update_port_on_error(core_plugin, context, port_id, revert_value)

A decorator that updates a port upon exception.

This decorator can be used to wrap a block of code that should update a port if an exception is raised during the block’s execution.

Parameters:
  • core_plugin – The core plugin implementing the update_port method to call.

  • context – The context.

  • port_id – The port’s ID.

  • revert_value – The value to revert on the port object.

Returns:

None

neutron_lib.plugins.utils.verify_tunnel_range(tunnel_range, tunnel_type)

Verify a given tunnel range is valid given it’s tunnel type.

Existing validation is done for GRE, VXLAN and GENEVE types as per _TUNNEL_MAPPINGS.

Parameters:
  • tunnel_range – An iterable who’s 0 index is the min tunnel range and who’s 1 index is the max tunnel range.

  • tunnel_type – The tunnel type of the range.

Returns:

None if the tunnel_range is valid.

Raises:

NetworkTunnelRangeError if tunnel_range is invalid.

neutron_lib.plugins.utils.verify_vlan_range(vlan_range)

Verify a VLAN range is valid.

Parameters:

vlan_range – An iterable who’s 0 index is the min tunnel range and who’s 1 index is the max tunnel range.

Returns:

None if the vlan_range is valid.

Raises:

NetworkVlanRangeError if vlan_range is not valid.