@@ -174,9 +174,9 @@ def __init__(
174174 port : typing .Optional [int ] = None ,
175175 username : typing .Optional [str ] = None ,
176176 password : typing .Optional [str ] = None ,
177+ * ,
177178 private_keys : typing .Optional [typing .Iterable [paramiko .RSAKey ]] = None ,
178179 auth : typing .Optional [ssh_auth .SSHAuth ] = None ,
179- * ,
180180 verbose : bool = True ,
181181 ssh_config : typing .Union [
182182 str ,
@@ -186,6 +186,7 @@ def __init__(
186186 None ,
187187 ] = None ,
188188 sock : typing .Optional [typing .Union [paramiko .ProxyCommand , paramiko .Channel , socket .socket ]] = None ,
189+ keepalive : bool = True ,
189190 ) -> None :
190191 """Main SSH Client helper.
191192
@@ -214,25 +215,39 @@ def __init__(
214215 ]
215216 :param sock: socket for connection. Useful for ssh proxies support
216217 :type sock: typing.Optional[typing.Union[paramiko.ProxyCommand, paramiko.Channel, socket.socket]]
218+ :param keepalive: keepalive mode
219+ :type keepalive: bool
217220
218221 .. note:: auth has priority over username/password/private_keys
222+ .. note::
223+
224+ for proxy connection auth information is collected from SSHConfig
225+ if ssh_auth_map record is not available
226+
227+ .. versionchanged:: 6.0.0 private_keys, auth and vebose became keyword-only arguments
228+ .. versionchanged:: 6.0.0 added optional ssh_config for ssh-proxy & low level connection parameters handling
229+ .. versionchanged:: 6.0.0 added optional sock for manual proxy chain handling
230+ .. versionchanged:: 6.0.0 keepalive exposed to constructor
219231 """
220232 super (SSHClientBase , self ).__init__ (
221233 logger = logging .getLogger (self .__class__ .__name__ ).getChild (f"({ host } :{ port } )" )
222234 )
223235
236+ # Init ssh config. It's main source for connection parameters
224237 if isinstance (ssh_config , HostsSSHConfigs ):
225238 self .__ssh_config : HostsSSHConfigs = ssh_config
226239 else :
227240 self .__ssh_config = _ssh_helpers .parse_ssh_config (ssh_config , host )
228241
242+ # Get config. We are not resolving full chain. If you are have a chain by some reason - init config manually.
229243 config : SSHConfig = self .__ssh_config [host ]
230244
245+ # Save resolved hostname and port
231246 self .__hostname : str = config .hostname
232247 self .__port : int = port if port is not None else config .port if config .port is not None else 22
233248
234249 self .__sudo_mode = False
235- self .__keepalive_mode = True
250+ self .__keepalive_mode : bool = keepalive
236251 self .__verbose : bool = verbose
237252 self .__sock = sock
238253
@@ -688,9 +703,9 @@ def proxy_to(
688703 port : typing .Optional [int ] = None ,
689704 username : typing .Optional [str ] = None ,
690705 password : typing .Optional [str ] = None ,
706+ * ,
691707 private_keys : typing .Optional [typing .Iterable [paramiko .RSAKey ]] = None ,
692708 auth : typing .Optional [ssh_auth .SSHAuth ] = None ,
693- * ,
694709 verbose : bool = True ,
695710 ssh_config : typing .Union [
696711 str ,
@@ -699,6 +714,7 @@ def proxy_to(
699714 HostsSSHConfigs ,
700715 None ,
701716 ] = None ,
717+ keepalive : bool = True ,
702718 ) -> "SSHClientBase" :
703719 """Start new SSH connection using current as proxy.
704720
@@ -725,6 +741,8 @@ def proxy_to(
725741 HostsSSHConfigs,
726742 None
727743 ]
744+ :param keepalive: keepalive mode
745+ :type keepalive: bool
728746 :returns: new ssh client instance using current as a proxy
729747 :rtype: SSHClientBase
730748
@@ -751,6 +769,7 @@ def proxy_to(
751769 verbose = verbose ,
752770 ssh_config = ssh_config ,
753771 sock = sock ,
772+ keepalive = keepalive ,
754773 )
755774
756775 def execute_through_host (
@@ -814,9 +833,8 @@ def execute_through_host(
814833 auth = self .auth
815834
816835 with self .proxy_to ( # type: ignore
817- host = hostname , port = target_port , auth = auth , verbose = verbose , ssh_config = self .ssh_config
836+ host = hostname , port = target_port , auth = auth , verbose = verbose , ssh_config = self .ssh_config , keepalive = False
818837 ) as conn :
819- conn .keepalive_mode = False # pylint: disable=assigning-non-slot
820838 return conn .execute (
821839 command ,
822840 timeout = timeout ,
0 commit comments