Skip to content

Commit

Permalink
node.clone plugin cleanup (#1639)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbemmel authored Dec 10, 2024
1 parent 743db8a commit 1afe688
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 623 deletions.
13 changes: 8 additions & 5 deletions netsim/extra/node.clone/defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
clone:
node_name_pattern: "{name[:13]}-{id:02d}" # Result should be a valid identifier, can use '-' in node names

attributes:
node:
clone: { type: int, min_value: 1, _required: True } # Create N copies of this node anywhere it's used in groups or links
start: int # Optional ID to start with, default 1
step: int # Optional increment between clones, default 1
#
# As the plugin runs before attribute validation, this structure is never checked. Left for documentation purposes
#
# attributes:
# node:
# count: { type: int, min_value: 1, _required: True } # Create N copies of this node anywhere it's used in groups or links
# start: int # Optional ID to start with, default 1
# step: int # Optional increment between clones, default 1
7 changes: 6 additions & 1 deletion netsim/extra/node.clone/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,14 @@ def update_links(topo_items: str, nodename: str, clones: list, topology: Box) ->
def clone_node(node: Box, topology: Box) -> None:
_p = { 'start': 1, 'step': 1 } + node.pop('clone',{}) # Define cloning parameters
if 'count' not in _p:
log.error("Node {node.name} missing required attribute clone.count", # Not validated by Netlab yet
log.error("Node {node.name} missing required attribute clone.count", # Not validated by Netlab
category=AttributeError, module='node.clone')
return
for attr in _p:
if not data.is_true_int(_p[attr]) or _p[attr]<=0:
log.error(f"Attribute {attr} for node.clone must be a positive int",
category=AttributeError, module='node.clone')
return

if 'include' in node: # Check for components
log.error("Cannot clone component {node.name}, only elementary nodes",
Expand Down
Loading

0 comments on commit 1afe688

Please sign in to comment.