networking_generic_switch.devices package

Submodules

networking_generic_switch.devices.utils module

networking_generic_switch.devices.utils.get_hostname()

Helper to allow isolation of CONF.host and plugin loading.

networking_generic_switch.devices.utils.get_switch_device(switches, switch_info=None, ngs_mac_address=None)

Return switch device by specified identifier.

Returns switch device from switches array that matched with any of passed identifiers. ngs_mac_address takes precedence over switch_info, if didn’t match any address based on mac fallback to switch_info.

Parameters:
  • switch_info – hostname of the switch or any other switch identifier.

  • ngs_mac_address – Normalized mac address of the switch.

Returns:

switch device matches by specified identifier or None.

networking_generic_switch.devices.utils.sanitise_config(config)

Return a sanitised configuration of a switch device.

Parameters:

config – a configuration dict to sanitise.

Returns:

a copy of the configuration, with sensitive fields removed.

Module contents

class networking_generic_switch.devices.GenericSwitchDevice(device_cfg, device_name='')

Bases: object

abstract add_network(segmentation_id, network_id)
abstract add_security_group(sg)

Add a security group to a switch

Parameters:

sg – Security group object including rules

abstract add_subports_on_trunk(binding_profile, port_id, subports)

Allow subports on trunk

Parameters:
  • binding_profile – Binding profile of parent port

  • port_id – The name of the switch port from Local Link Information

  • subports – List with subports objects.

abstract bind_security_group(sg, port_id, port_ids)

Apply a security group to a port

The rules in the provided security group will also be used to assert the state with the switch.

Parameters:
  • sg – Security group object including rules

  • port_id – Name of switch port to bind group to

  • port_ids – Names of all switch ports currently bound to this group

abstract del_network(segmentation_id, network_id)
abstract del_security_group(sg_id)

Delete a security group

Parameters:

sg_id – Security group ID

abstract del_subports_on_trunk(binding_profile, port_id, subports)

Allow subports on trunk

Parameters:
  • binding_profile – Binding profile of parent port

  • port_id – The name of the switch port from Local Link Information

  • subports – List with subports objects.

abstract delete_port(port_id, segmentation_id, trunk_details=None, default_vlan=None)

Delete port from specific network.

Parameters:
  • port_id – The name of the switch interface

  • segmentation_id – VLAN identifier of the network used as access or native VLAN for port.

  • trunk_details – trunk information if port is a part of trunk

  • default_vlan – Default VLAN identifier if port is not configured

is_allowed(port_id, segmentation_id)
plug_bond_to_network(bond_id, segmentation_id, trunk_details=None, default_vlan=None)

Plug bond port into network.

Parameters:
  • port_id – The name of the switch interface

  • segmentation_id – VLAN identifier of the network used as access or native VLAN for port.

  • trunk_details – trunk information if port is a part of trunk

  • default_vlan – Default VLAN identifier if port is not configured

abstract plug_port_to_network(port_id, segmentation_id, trunk_details=None, default_vlan=None)

Plug port into network.

Parameters:
  • port_id – The name of the switch interface

  • segmentation_id – VLAN identifier of the network used as access or native VLAN for port.

  • trunk_details – trunk information if port is a part of trunk

  • default_vlan – Default VLAN identifier if port is not configured

abstract plug_switch_to_network(vni: int, segmentation_id: int, physnet: str = None)

Configure L2VNI mapping on the switch.

In VXLAN L2VNI scenarios with hierarchical port binding, Neutron creates a VXLAN network (top segment) and dynamically allocates a local VLAN (bottom segment) on each switch. This method maps the VLAN to the VNI on the switch fabric.

Called during port binding when both conditions are met: - Top bound segment is VXLAN - Bottom bound segment is VLAN

For switches that don’t support VXLAN, this can be left as None (will log a warning but not fail).

Parameters:
  • vni – The VXLAN Network Identifier

  • segmentation_id – VLAN ID to map to the VNI

  • physnet – Physical network name for per-physnet configuration (optional, for future use).

Raises:

GenericSwitchConfigException on configuration failure

property support_trunk_on_bond_ports
property support_trunk_on_ports
abstract unbind_security_group(sg_id, port_id, port_ids)

Remove a bound security group from a port

Parameters:
  • sg_id – ID of security group to unbind

  • port_id – Name of switch port to unbind group from

  • port_ids – Names of all switch ports currently bound to this group

unplug_bond_from_network(bond_id, segmentation_id, trunk_details=None, default_vlan=None)

Unplug bond port from network.

Parameters:
  • port_id – The name of the switch interface

  • segmentation_id – VLAN identifier of the network used as access or native VLAN for port.

  • trunk_details – trunk information if port is a part of trunk

  • default_vlan – Default VLAN identifier if port is not configured

abstract unplug_switch_from_network(vni: int, segmentation_id: int, physnet: str = None)

Remove L2VNI mapping from the switch.

Removes the VNI-to-VLAN mapping when the last port on a VLAN is unplugged. Called automatically by the cleanup logic in _unplug_port_from_segment() after verifying no ports remain via vlan_has_ports().

Should be idempotent - safely handle cases where the VNI is already removed.

Example (Cisco NX-OS):
interface nve1

no member vni 5000

vlan 100

no vn-segment

Parameters:
  • vni – The VXLAN Network Identifier to remove

  • segmentation_id – VLAN ID from which to remove the VNI mapping

  • physnet – Physical network name (optional, for signature consistency)

Raises:

GenericSwitchConfigException on configuration failure

abstract update_security_group(sg)

Updates an existing a security group on a switch

Rules may have been added or deleted so the driver needs to update the switch state to accurately reflect the provided security group.

Parameters:

sg – Security group object including rules

abstract vlan_has_ports(segmentation_id: int) bool

Check if a VLAN has any switch ports currently assigned.

Used by L2VNI cleanup logic to determine if it’s safe to remove the VNI mapping. The VNI should only be removed when no ports remain on the VLAN.

This is a read-only operation and should not acquire locks.

Implementations should: - Query the switch directly (not rely on cached state) - Return True if the VLAN has any ports (access or trunk) - Return True on error (conservative - prevents accidental removal) - Return True if query command is not implemented

Parameters:

segmentation_id – VLAN ID to check

Returns:

True if VLAN has ports assigned, False if empty

abstract vlan_has_vni(segmentation_id: int, vni: int) bool

Check if a VLAN already has a specific VNI mapping configured.

Used for idempotency during port binding to avoid reconfiguring the same VNI mapping multiple times when multiple ports bind to the same VXLAN network.

This is a read-only operation and should not acquire locks.

Implementations should: - Query the switch directly (not rely on cached state) - Return True only if this exact VNI is configured on this VLAN - Return False on error (will attempt to configure) - Return False if query command is not implemented

Parameters:
  • segmentation_id – VLAN ID to check

  • vni – VNI to check for

Returns:

True if VLAN has this VNI configured, False otherwise

networking_generic_switch.devices.device_manager(device_cfg, device_name='')
networking_generic_switch.devices.get_devices()