-
Notifications
You must be signed in to change notification settings - Fork 20
CMLDEV-12: Add posibility to switch serial console used by PyAts conn… #177
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
base: dev
Are you sure you want to change the base?
CMLDEV-12: Add posibility to switch serial console used by PyAts conn… #177
Conversation
virl2_client/models/cl_pyats.py
Outdated
| except KeyError: | ||
| raise PyatsDeviceNotFound(node_label) | ||
|
|
||
| node: Node = [node for node in self._lab.nodes()if node.label == node_label].pop() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| node: Node = [node for node in self._lab.nodes()if node.label == node_label].pop() | |
| node = self._lab.get_node_by_label(node_label) |
| node: Node = [node for node in self._lab.nodes()if node.label == node_label].pop() | ||
|
|
||
| # will raise API error inside if console does not exist for device | ||
| node.console_key(console_number) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you don't want to store and use the key? what's the reason of calling it then? I'd let it fail later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, let it fail on connect if the console cannot get actually connected
virl2_client/models/cl_pyats.py
Outdated
| pattern = rf"({re.escape(node_label)})/\d+" | ||
| new_console_cfg = f"/{console_number}" | ||
|
|
||
| new_connect_command = re.sub(pattern, rf"\1{new_console_cfg}", old_connect_command) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wouldn't this work?
| new_connect_command = re.sub(pattern, rf"\1{new_console_cfg}", old_connect_command) | |
| new_connect_command = re.sub(pattern, rf"\1/{console_number}", old_connect_command) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that the original console number is always 0, so a simpler replace command should work as well, e.g.,
pyats_device.connections["a"]["command"] = pyats_device.connections["a"]["command"][:-1] + console_number
ab65bf3 to
e00ddee
Compare
|
I rebased this from dev and changed the target branch to the same. |
| node: Node = [node for node in self._lab.nodes()if node.label == node_label].pop() | ||
|
|
||
| # will raise API error inside if console does not exist for device | ||
| node.console_key(console_number) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, let it fail on connect if the console cannot get actually connected
| new_console_cfg = f"/{console_number}" | ||
|
|
||
| new_connect_command = re.sub( | ||
| pattern, rf"\1{new_console_cfg}", old_connect_command |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should rather check that the console number is 0-3, and only change the last character. No need to use regex here
| """ | ||
| Switch to different serial console that is used to execute PyAts commands | ||
| should be executed after sync_testbed | ||
| and re-executed after every sync_testbed call. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
speaking of - if you use console 0, then switch to console 1 using this method, will the next command perhaps reuse the connection it already has established with console 0? Maybe coordinate with the other ticket about closing an existing connection if the connection number does not match.
…ections