class SSHClient():
    def __init__(self,host=None,port=22,username=None,password=None):
        self.host = host
        self.port = port
        self.username = username
        self.password = password

    def exect(self, cmd):
        # 创建ssh对象
        ssh = paramiko.SSHClient()
        # 允许连接不在know_hosts文件中的文件
        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        ssh.connect(self.host,self.port,self.username,self.password)
        sin, sout, sstr = ssh.exec_command(cmd)
        ret = sout.read()
        return ret

class Tags(APIView,SSHClient):

    def __init__(self):

        self._response = ReturnResponse()

        SSHClient.__init__(self,host=h1['host'],port=h1['port'],username=h1['username'],password=h1['password'])

单继承时初始化父类属性:

super(xxx,self)._ _init _ _(*args)

多继承时

要通过每个父类._ _ init _ _(*args)来初始化父类的属性

posted on 2021-06-25 11:51  x-dai  阅读(879)  评论(0)    收藏  举报