Skip to content

Commit

Permalink
* Add support for VRF links
Browse files Browse the repository at this point in the history
Note: link groups could in theory be supported transparently if the transformation got applied before the plugin gets invoked.
Similarly, it would be easier if link interfaces were normalized before plugins get invoked
  • Loading branch information
jbemmel committed Dec 7, 2024
1 parent 35cac4c commit 715fd67
Show file tree
Hide file tree
Showing 4 changed files with 337 additions and 91 deletions.
5 changes: 2 additions & 3 deletions docs/plugins/node.clone.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@ The plugin adds the following node attributes:

### Caveats

The plugin does not yet support:
The plugin does not support:
* *lag* module links
* link groups
* VRF links
* components
* cloning of components (nodes composed of multiple nodes)

## Examples

Expand Down
19 changes: 15 additions & 4 deletions netsim/extra/node.clone/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ def clone_interfaces(link_data: Box, nodename: str, clones: list[str]) -> list[B
ifs.append(l)
return ifs

def update_vlan_access_links(topology: Box, nodename: str, clones: list) -> None:
for vname,vdata in topology.vlans.items(): # Iterate over global VLANs
"""
update_links - updates 'links' lists in VLAN and VRF objects
"""
def update_links(topo_items: Box, nodename: str, clones: list, topology: Box) -> None:
for vname,vdata in topo_items.items(): # Iterate over global VLANs or VRFs
if not isinstance(vdata,Box): # VLAN not yet a dictionary?
continue # ... no problem, skip it
if not 'links' in vdata: # No VLAN links?
Expand All @@ -47,6 +50,11 @@ def clone_node(node: Box, topology: Box) -> None:
category=AttributeError, module='node.clone')
return

if 'include' in node: # Check for components
log.error("Cannot clone component {node.name}, only elementary nodes",
category=AttributeError, module='node.clone')
return

name_format = topology.defaults.clone.node_name_pattern

orig_name = node.name
Expand Down Expand Up @@ -85,8 +93,11 @@ def clone_node(node: Box, topology: Box) -> None:
gdata.members.extend( clones )

if 'vlans' in topology:
update_vlan_access_links(topology,orig_name,clones)

update_links(topology.vlans,orig_name,clones,topology)

if 'vrfs' in topology:
update_links(topology.vrfs,orig_name,clones,topology)

topology.nodes.pop(orig_name,None) # Finally

"""
Expand Down
Loading

0 comments on commit 715fd67

Please sign in to comment.