add test
This commit is contained in:
parent
75a75dac55
commit
b93e3013d0
|
|
@ -4,6 +4,7 @@
|
|||
# @Author :qiangyanwen
|
||||
# @File :ssh_client.py
|
||||
import paramiko
|
||||
from config.log import logger
|
||||
|
||||
|
||||
class SSHConnection(object):
|
||||
|
|
@ -17,7 +18,7 @@ class SSHConnection(object):
|
|||
self._client = None
|
||||
|
||||
def __enter__(self):
|
||||
print("客户端开始创建连接.....")
|
||||
logger.info("ssh开始创建链接")
|
||||
transport = paramiko.Transport((self._host, self._port))
|
||||
transport.connect(username=self._username, password=self._password)
|
||||
self._transport = transport
|
||||
|
|
@ -52,7 +53,7 @@ class SSHConnection(object):
|
|||
self._transport.close()
|
||||
if self._client:
|
||||
self._client.close()
|
||||
print("客户端关闭已成功.....")
|
||||
logger.info("ssh 关闭连接")
|
||||
|
||||
|
||||
with SSHConnection("47.96.135.132", 22, "root", "Qyw1994@520") as ssh:
|
||||
|
|
|
|||
Loading…
Reference in New Issue