Skip to content

Commit

Permalink
Working around #11 until the next Netmiko release
Browse files Browse the repository at this point in the history
Until there will be a more permanent solution in Netmiko, in order to
have this driver usable with version 4.x, we need to "help" Netmiko when
it fails to detect the prompt. Strictly speaking, as discussed under
ktbyers/netmiko#2866 Netmiko works as
designed, the ``base_prompt`` attribute is what we'd expect to be, but
when OpenGear doesn't set anything on the prompt other than ``$`` or ``#``
depending on the user elevation, then Netmiko fails to properly read
(more specifically, won't know when to stop).

I also took this chance to change the behaviour in ``open()`` to only
invoke ``enable()`` when the user is not root -- this saves one
unnecessary operation when we use the root user.
  • Loading branch information
mirceaulinic committed Jul 26, 2022
1 parent a217ddc commit 6417574
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion napalm_opengear/opengear.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,14 @@ def open(self):
global_delay_factor=2,
**self.netmiko_optional_args
)
self.device.enable()
if not self.device.base_prompt:
# If Netmiko fails to detect the prompt due to OpenGear not setting
# anything before the pound sign, we set the base_prompt attribute
# so Netmiko is able to read (either # when the username is root, or
# $ for anything else)
self.base_prompt = "#" if self.username == "root" else "$"
if self.username != "root":
self.device.enable()

def close(self):
self._netmiko_close()
Expand Down

0 comments on commit 6417574

Please sign in to comment.