functions.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:isard 作者: isard-vdi 项目源码 文件源码
def exec_remote_list_of_cmds(hostname, commands, username='root', port=22, sudo=False):
    client = paramiko.SSHClient()
    client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    client.connect(hostname, port=port, username=username)

    returned_array = []

    for command in commands:
        log.debug('command to launch in ssh in {}: {}'.format(hostname, command))
        stdin, stdout, stderr = client.exec_command(command)
        out = stdout.read().decode('utf-8')
        err = stderr.read().decode('utf-8')
        returned_array.append({'out': out, 'err': err})
        log.debug('commnad launched / out: {} / error: {}'.format(out, err))

    client.close()

    return returned_array
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号