1+ import time
2+ import re
3+
14from netmiko .no_config import NoConfig
25from netmiko .base_connection import BaseConnection
36
@@ -7,17 +10,45 @@ class CheckPointGaiaSSH(NoConfig, BaseConnection):
710 Implements methods for communicating with Check Point Gaia
811 firewalls.
912 """
13+ prompt_pattern = r"[>#]"
1014
1115 def session_preparation (self ) -> None :
1216 """
1317 Prepare the session after the connection has been established.
1418
1519 Set the base prompt for interaction ('>').
1620 """
17- self ._test_channel_read (pattern = r"[>#]" )
21+ self ._test_channel_read (pattern = self . prompt_pattern )
1822 self .set_base_prompt ()
1923 self .disable_paging (command = "set clienv rows 0" )
2024
25+ # Clear read buffer
26+ time .sleep (0.3 * self .global_delay_factor )
27+ self .clear_buffer ()
28+
29+ def command_echo_read (self , cmd : str , read_timeout : float ) -> str :
30+ """Check Point clish double echoes the command (at least sometimes)"""
31+
32+ re_cmd = re .escape (cmd )
33+ pattern = f"{ self .prompt_pattern } \s{ re_cmd } "
34+
35+ # Make sure you read until you detect the command echo (avoid getting out of sync)
36+ new_data = self .read_until_pattern (
37+ pattern = pattern , read_timeout = read_timeout
38+ )
39+
40+ # There can be echoed prompts that haven't been cleared before the cmd echo
41+ # this can later mess up the trailing prompt pattern detection. Clear this out.
42+ lines = new_data .split (cmd )
43+ if len (lines ) in [2 , 3 ]:
44+ # lines[-1] should realistically just be the null string
45+ new_data = f"{ cmd } { lines [- 1 ]} "
46+ else :
47+ # cmd exists in the output multiple times? Just retain the original output
48+ pass
49+
50+ return new_data
51+
2152 def save_config (
2253 self , cmd : str = "" , confirm : bool = False , confirm_response : str = ""
2354 ) -> str :
0 commit comments