44import paramiko
55import contextlib
66import subprocess
7+ import warnings
78from rrmngmnt .common import normalize_string
89from rrmngmnt .executor import Executor , ExecutorFactory
10+ from rrmngmnt .user import UserWithPKey
911
1012
1113AUTHORIZED_KEYS = os .path .join ("%s" , ".ssh/authorized_keys" )
@@ -42,7 +44,7 @@ def process(self, msg, kwargs):
4244 "[%s@%s/%s] %s" % (
4345 self .extra ['self' ].user .name ,
4446 self .extra ['self' ].address ,
45- self .extra ['self' ].user .password ,
47+ self .extra ['self' ].user .credentials ,
4648 msg ,
4749 ),
4850 kwargs ,
@@ -59,7 +61,11 @@ def __init__(self, executor, timeout=None):
5961 self ._timeout = timeout
6062 self ._ssh = paramiko .SSHClient ()
6163 self ._ssh .set_missing_host_key_policy (paramiko .AutoAddPolicy ())
62- if self ._executor .use_pkey :
64+ if isinstance (self ._executor .user , UserWithPKey ):
65+ self .pkey = paramiko .RSAKey .from_private_key_file (
66+ self ._executor .user .private_key
67+ )
68+ elif self ._executor .use_pkey :
6369 self .pkey = paramiko .RSAKey .from_private_key_file (
6470 os .getenv (
6571 "HOST_SSH_KEY" , ID_RSA_PRV % os .path .expanduser ('~' )
@@ -223,6 +229,11 @@ def __init__(self, user, address, use_pkey=False, port=22, sudo=False):
223229 self .use_pkey = use_pkey
224230 self .port = port
225231 self .sudo = sudo
232+ if use_pkey :
233+ warnings .warn (
234+ "Parameter 'use_pkey' is deprecated and will be removed in "
235+ "future. Please use user.UserWithPKey user instead."
236+ )
226237
227238 def session (self , timeout = None ):
228239 """
@@ -310,6 +321,11 @@ class RemoteExecutorFactory(ExecutorFactory):
310321 def __init__ (self , use_pkey = False , port = 22 ):
311322 self .use_pkey = use_pkey
312323 self .port = port
324+ if use_pkey :
325+ warnings .warn (
326+ "Parameter 'use_pkey' is deprecated and will be removed in "
327+ "future. Please use user.UserWithPKey user instead."
328+ )
313329
314330 def build (self , host , user , sudo = False ):
315331 return RemoteExecutor (
0 commit comments