networking_generic_switch.devices.netconf_devices package¶
Submodules¶
networking_generic_switch.devices.netconf_devices.netconf_switch module¶
- class networking_generic_switch.devices.netconf_devices.netconf_switch.NetconfSwitch(device_cfg, *args, **kwargs)¶
Bases:
GenericSwitchDeviceBase class for NETCONF-based switch drivers.
Provides ncclient transport, NETCONF locking, candidate/running datastore dispatch, confirmed-commit, and retry on lock-denied.
Subclasses must assign callable class variables (ADD_NETWORK, etc.) that build OpenConfig model objects. The dispatch methods in this class invoke those callables, serialize the result to XML via
ncutils.config_to_xml, and push to the device.- ADD_NETWORK_TO_TRUNK = None¶
- DISABLE_PORT = None¶
- ENABLE_PORT = None¶
- REMOVE_NETWORK_FROM_TRUNK = None¶
- VALID_NETCONF_TARGETS = ('candidate', 'running')¶
- add_network(segmentation_id, network_id, physnet_vlans=None)¶
Create a VLAN on the device.
Delegates to the
ADD_NETWORKcallable set by the subclass. If trunk ports are configured andADD_NETWORK_TO_TRUNKis defined, the trunk tagging is included in the same edit-config.- Parameters:
segmentation_id – VLAN ID of the network.
network_id – UUID of the Neutron network.
physnet_vlans – Complete set of VLAN segmentation IDs on the physical network, or None if convergence is not active.
- add_security_group(sg)¶
Add a security group to the switch.
- Parameters:
sg – Security group object including rules.
- add_subports_on_trunk(binding_profile, port_id, subports)¶
Allow subports on trunk.
- Parameters:
binding_profile – Binding profile of the parent port.
port_id – Name of the switch port.
subports – List of subport objects.
- Raises:
GenericSwitchNotSupported always.
- bind_security_group(sg, port_id, port_ids)¶
Apply a security group to a port.
- 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.
- del_network(segmentation_id, network_id, physnet_vlans=None)¶
Remove a VLAN from the device.
Delegates to the
DELETE_NETWORKcallable set by the subclass. If trunk ports are configured andREMOVE_NETWORK_FROM_TRUNKis defined, the trunk untagging is included in the same edit-config (before the VLAN delete).- Parameters:
segmentation_id – VLAN ID of the network.
network_id – UUID of the Neutron network.
physnet_vlans – Complete set of VLAN segmentation IDs on the physical network, or None if convergence is not active.
- del_security_group(sg_id)¶
Delete a security group from the switch.
- Parameters:
sg_id – Security group ID.
- del_subports_on_trunk(binding_profile, port_id, subports)¶
Remove subports from trunk.
- Parameters:
binding_profile – Binding profile of the parent port.
port_id – Name of the switch port.
subports – List of subport objects.
- Raises:
GenericSwitchNotSupported always.
- delete_port(port_id, segmentation_id, trunk_details=None, default_vlan=None)¶
Delete a port from a network.
Collects unplug, default-VLAN restoration, and disable config into a single edit-config RPC.
- Parameters:
port_id – Name of the switch interface.
segmentation_id – VLAN ID of the network.
trunk_details – Trunk information if port is part of a trunk.
default_vlan – Default VLAN ID when port is unconfigured.
- get_capabilities()¶
Connect to the device and return its processed capabilities.
- Returns:
set of short capability names.
- Raises:
GenericSwitchNetconfConnectError on SSH or authentication failure.
- get_from_device(query)¶
Read-only <get> RPC.
- Parameters:
query – An OpenConfig model object with a
to_xml_element()method.- Returns:
XML string of the reply data.
- plug_port_to_network(port_id, segmentation_id, trunk_details=None, default_vlan=None)¶
Plug a port into a network.
Collects enable, default-VLAN removal, and plug config into a single edit-config RPC.
- Parameters:
port_id – Name of the switch interface.
segmentation_id – VLAN ID of the network.
trunk_details – Trunk information if port is part of a trunk.
default_vlan – Default VLAN ID when port is unconfigured.
- plug_switch_to_network(vni, segmentation_id, physnet=None)¶
Configure L2VNI mapping on the switch.
Not yet supported by NETCONF devices; logs a debug message.
- Parameters:
vni – VXLAN Network Identifier.
segmentation_id – VLAN ID to map to the VNI.
physnet – Physical network name (optional).
- static process_capabilities(server_capabilities)¶
Map NETCONF server capability URIs to short names.
Matches IANA NETCONF capability URIs and OpenConfig YANG module names from the server’s hello message.
- Parameters:
server_capabilities – Iterable of capability URI strings from the NETCONF hello message.
- Returns:
set of short capability names.
- send_config_to_device(config)¶
Edit configuration on the device.
- Parameters:
config – Configuration object or list of configuration objects. Each must implement
to_xml_element().
- property trunk_vlans_converge¶
Whether trunk VLAN list should be fully converged on each operation.
When True, the mechanism driver queries the Neutron DB for all VLAN segments on the physical network and passes the complete set via the physnet_vlans parameter.
- 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_switch_from_network(vni, segmentation_id, physnet=None)¶
Remove L2VNI mapping from the switch.
Not yet supported by NETCONF devices; logs a debug message.
- Parameters:
vni – VXLAN Network Identifier.
segmentation_id – VLAN ID from which to remove the VNI mapping.
physnet – Physical network name (optional).
- update_security_group(sg)¶
Update an existing security group on the switch.
- Parameters:
sg – Security group object including rules.
- vlan_has_ports(segmentation_id)¶
Check if a VLAN has any ports assigned.
Returns
True(conservative default) to prevent premature VNI cleanup.- Parameters:
segmentation_id – VLAN ID to check.
- Returns:
Always
True.
- vlan_has_vni(segmentation_id, vni)¶
Check if a VLAN has a specific VNI mapping.
Returns
Falsesince L2VNI is not supported.- Parameters:
segmentation_id – VLAN ID to check.
vni – VNI to check for.
- Returns:
Always
False.
networking_generic_switch.devices.netconf_devices.openconfig module¶
- class networking_generic_switch.devices.netconf_devices.openconfig.NetconfOpenConfigSwitch(device_cfg, *args, **kwargs)¶
Bases:
NetconfSwitchNETCONF OpenConfig switch driver.
Manages network and port operations using OpenConfig YANG models over NETCONF transport. Callable class variables (ADD_NETWORK, DELETE_NETWORK, ADD_NETWORK_TO_TRUNK, REMOVE_NETWORK_FROM_TRUNK, PLUG_PORT_TO_NETWORK, DELETE_PORT, ENABLE_PORT, DISABLE_PORT) build OpenConfig model objects that the base class serialises to XML and pushes via
send_config_to_device.- static ADD_NETWORK(self, segmentation_id, network_name, **kwargs)¶
Build OpenConfig objects to create a VLAN.
- Parameters:
segmentation_id – VLAN ID.
network_name – Name to assign to the VLAN on the device.
- Returns:
list of OpenConfig model objects.
- static ADD_NETWORK_TO_TRUNK(self, segmentation_id, trunk_ports, **kwargs)¶
Build OpenConfig objects to tag trunk ports with a VLAN.
When physnet_vlans is provided the complete set of trunk VLANs is written with
operation="replace"so that the device converges to the desired state. Falls back to a single-VLAN merge when physnet_vlans isNone.- Parameters:
segmentation_id – VLAN ID to add to trunk ports.
trunk_ports – List of switch interface names.
physnet_vlans – (kwarg) Complete set of VLAN IDs on the physical network, or
None.
- Returns:
list of OpenConfig model objects.
- static DELETE_NETWORK(self, segmentation_id, network_name, **kwargs)¶
Build OpenConfig objects to remove a VLAN.
Not all devices support outright VLAN removal, so the VLAN is also set to SUSPENDED with a
neutron-DELETED-name prefix as a fallback.- Parameters:
segmentation_id – VLAN ID.
network_name – Original network name (unused in the delete payload but accepted for signature compatibility).
- Returns:
list of OpenConfig model objects.
- static DELETE_PORT(self, port_id, segmentation_id, **kwargs)¶
Build OpenConfig objects to remove VLAN config from a port.
- Parameters:
port_id – Switch interface name.
segmentation_id – VLAN ID.
- Returns:
list of OpenConfig model objects.
- static DISABLE_PORT(self, port_id, **kwargs)¶
Build OpenConfig objects to disable an interface.
- Parameters:
port_id – Switch interface name.
- Returns:
list of OpenConfig model objects.
- static ENABLE_PORT(self, port_id, **kwargs)¶
Build OpenConfig objects to enable an interface.
- Parameters:
port_id – Switch interface name.
- Returns:
list of OpenConfig model objects.
- static PLUG_PORT_TO_NETWORK(self, port_id, segmentation_id, **kwargs)¶
Build OpenConfig objects to assign an access VLAN to a port.
- Parameters:
port_id – Switch interface name.
segmentation_id – VLAN ID.
- Returns:
list of OpenConfig model objects.
- static REMOVE_NETWORK_FROM_TRUNK(self, segmentation_id, trunk_ports, **kwargs)¶
Build OpenConfig objects to untag trunk ports from a VLAN.
When physnet_vlans is provided the complete set (which already excludes the deleted VLAN) is written with
operation="replace". Falls back to per-elementoperation="remove"when physnet_vlans isNone.- Parameters:
segmentation_id – VLAN ID to remove from trunk ports.
trunk_ports – List of switch interface names.
physnet_vlans – (kwarg) Complete set of VLAN IDs on the physical network after deletion, or
None.
- Returns:
list of OpenConfig model objects.