Skip to content

Commit

Permalink
Mikrotik free version ssh login fix (with minor updates) (#3458)
Browse files Browse the repository at this point in the history
Co-authored-by: meganerd <[email protected]>
  • Loading branch information
ktbyers and meganerd committed Jul 10, 2024
1 parent 3d4680e commit e3acedd
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions netmiko/mikrotik/mikrotik_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,25 @@ def __init__(self, **kwargs: Any) -> None:
return super().__init__(**kwargs)

def special_login_handler(self, delay_factor: float = 1.0) -> None:
# Mikrotik might prompt to read software licenses before displaying the initial prompt.
"""Handles special case scenarios for logins that might be encountered.
Special cases:
Mikrotik might prompt to read software licenses before displaying the initial prompt.
Mikrotik might also prompt for acknowledging no software key message if unlicensed.
"""
no_license_message = 'Please press "Enter" to continue!'
license_prompt = "Do you want to see the software license"
combined_pattern = rf"(?:{self.prompt_pattern}|{license_prompt})"
combined_pattern = (
rf"(?:{self.prompt_pattern}|{no_license_message}|{license_prompt})"
)

data = self.read_until_pattern(pattern=combined_pattern, re_flags=re.I)
if license_prompt in data:
if no_license_message in data:
# Handle "no license" message
self.write_channel(self.RETURN)
self.read_until_pattern(pattern=self.prompt_pattern)
elif license_prompt in data:
# Handle software license prompt
self.write_channel("n")
self.read_until_pattern(pattern=self.prompt_pattern)

Expand Down

0 comments on commit e3acedd

Please sign in to comment.