#-*- coding:utf8 -*- from fabric import Connection class linuxOper(object): def __init__(self,ipaddr,user='root',password='',port=22,gateway=''): self.gateway = gateway self.connobj = Connection(host=ipaddr,user=user,connect_kwargs={'password':password},port=int(port),gateway=self.gateway,) def getConnObj(self): return self.connobj def run(self,cmd): return self.connobj.run(cmd).stdout if __name__ == '__main__': # 普通模式 lsobj = linuxOper('192.168.2.1','root','qqq') # 执行命令 lsobj.run('ls -l') # 中继模式 newsobj = linuxOper('192.168.1.10','root','qqq',gateway=lsobj.getConnObj()) # 执行命令 newsobj.run('ls -l')
python fabric 编写SSH 连接类
原创
©著作权归作者所有:来自51CTO博客作者suwnoo的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
Day07-压测、ssh连接容器实现
容器内部的压测、ssh 实现容器的连接、容器迁移的概念、docker 镜像、容器的命令配置文件daemon
docker bash centos