Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding node linking feature #27

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

ppajersk
Copy link

Added cml_link_node.py with code to link two nodes together
supports create update delete, and nodes are specified using their name
three node names are supported to allow for an update feature (node1->node2, can update to node1->node3)

added get_link_by_nodes method in cml_utils to allow searching the lab for a link between two specified nodes

@ppajersk
Copy link
Author

ppajersk commented Mar 31, 2023

Unsure if cml_utils.py line 72 works:
link.node_a.label

documentation does not specify if link.node_a is an object or a string. Currently attempting to test this and will confirm if it works or not

@ppajersk
Copy link
Author

ppajersk commented Apr 1, 2023

Tested all features of the module locally and all work as intended

Comment on lines +74 to +94
x:
description: X coordinate on topology canvas
required: false
type: int

y:
description: Y coordinate on topology canvas
required: false
type: int

tags:
description: List of tags
required: false
type: list
elements: str

wait:
description: Wait for lab virtual machines to boot before continuing
required: false
type: bool
default: False

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

obsolete for this module, should be deleted

Comment on lines +157 to +160
tags=dict(type='list', elements='str'),
x=dict(type='int'),
y=dict(type='int'),
wait=dict(type='bool', default=False),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

obsolete for this module, should be deleted

cml.exit_json(**cml.result)
return

link = cml.get_link_by_nodes(lab, source_node, destination_node)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

virl2-client node supports this natively:

link = source_node.get_link_to(destination_node)

as per:
https://github.com/CiscoDevNet/virl2-client/blob/22693cd1be5f321f3848fe591436524abdb804fe/virl2_client/models/node.py#L635

        def get_link_to(self, other_node: Node) -> Link | None:
        """
        Return one link between this node and another.

        :param other_node: The other node.
        :returns: A link between this node and the other node, if one exists.
        """
        for link in self.links():
            if other_node in link.nodes:
                return link
        return None

Comment on lines +70 to +76
def get_link_by_nodes(self, lab, node1, node2):
for link in lab.links():
if ((link.node_a.label == node1.label and link.node_b.label == node2.label)
or (link.node_b.label == node1.label and link.node_a.label == node2.label)):
return link
return None

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tvarohohlavy
Copy link

I am working on adjusting this to support specifying interfaces for nodes by labels (or maybe even slots).
But I guess I cant make changes so I will do that through comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants