11import time
22import re
3+ from typing import Optional , Any
34
45from netmiko .no_config import NoConfig
56from netmiko .base_connection import BaseConnection
@@ -13,6 +14,13 @@ class CheckPointGaiaSSH(NoConfig, BaseConnection):
1314
1415 prompt_pattern = r"[>#]"
1516
17+ def __init__ (self , * args : Any , ** kwargs : Any ) -> None :
18+ # Kept running into issues with command_echo and duplicate echoes of commands.
19+ self .fast_cli = False
20+ fast_cli = kwargs .get ("fast_cli" ) or False
21+ kwargs ["fast_cli" ] = fast_cli
22+ return super ().__init__ (* args , ** kwargs )
23+
1624 def session_preparation (self ) -> None :
1725 """
1826 Prepare the session after the connection has been established.
@@ -27,26 +35,63 @@ def session_preparation(self) -> None:
2735 time .sleep (0.3 * self .global_delay_factor )
2836 self .clear_buffer ()
2937
30- def command_echo_read (self , cmd : str , read_timeout : float ) -> str :
31- """Check Point clish double echoes the command (at least sometimes)"""
38+ def check_enable_mode (self , check_string : str = "#" ) -> bool :
39+ """Check if in enable mode. Return boolean."""
40+ return super ().check_enable_mode (check_string = check_string )
3241
33- re_cmd = re .escape (cmd )
34- pattern = rf"{ self .prompt_pattern } \s{ re_cmd } "
42+ def enable_secret_handler (
43+ self ,
44+ pattern : str ,
45+ output : str ,
46+ re_flags : int = re .IGNORECASE ,
47+ ) -> str :
48+ """
49+ Check Point Gaia requires very particular timing for this 'expert'
50+ password handling to work.
3551
36- # Make sure you read until you detect the command echo (avoid getting out of sync)
37- new_data = self .read_until_pattern (pattern = pattern , read_timeout = read_timeout )
52+ Send the "secret" in response to password pattern
53+ """
54+ if re .search (pattern , output , flags = re_flags ):
55+ self .write_channel (self .secret )
56+ time .sleep (0.3 * self .global_delay_factor )
57+ self .write_channel (self .RETURN )
58+ time .sleep (0.3 * self .global_delay_factor )
59+ new_output = self .read_until_pattern (pattern = self .prompt_pattern )
60+ return new_output
3861
39- # There can be echoed prompts that haven't been cleared before the cmd echo
40- # this can later mess up the trailing prompt pattern detection. Clear this out.
41- lines = new_data .split (cmd )
42- if len (lines ) in [2 , 3 ]:
43- # lines[-1] should realistically just be the null string
44- new_data = f"{ cmd } { lines [- 1 ]} "
45- else :
46- # cmd exists in the output multiple times? Just retain the original output
47- pass
62+ def enable (
63+ self ,
64+ cmd : str = "expert" ,
65+ pattern : str = r"expert password" ,
66+ enable_pattern : Optional [str ] = r"\#" ,
67+ check_state : bool = True ,
68+ re_flags : int = re .IGNORECASE ,
69+ ) -> str :
70+ """
71+ Enter expert mode.
72+
73+ Check Point Gaia is very finicky on the timing of sending this 'expert' password.
74+ """
75+ output = super ().enable (
76+ cmd = cmd ,
77+ pattern = pattern ,
78+ enable_pattern = enable_pattern ,
79+ check_state = check_state ,
80+ re_flags = re_flags ,
81+ )
82+ self .set_base_prompt ()
83+ return output
4884
49- return new_data
85+ def exit_enable_mode (self , exit_command : str = "exit" ) -> str :
86+ """Exit expert mode."""
87+ output = ""
88+ if self .check_enable_mode ():
89+ self .write_channel (self .normalize_cmd (exit_command ))
90+ output += self .read_until_pattern (pattern = r">" )
91+ self .set_base_prompt ()
92+ if self .check_enable_mode ():
93+ raise ValueError ("Failed to exit enable mode." )
94+ return output
5095
5196 def save_config (
5297 self , cmd : str = "" , confirm : bool = False , confirm_response : str = ""
0 commit comments