functions.py 文件源码

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

项目:isard 作者: isard-vdi 项目源码 文件源码
def exec_remote_list_of_cmds_dict(hostname, list_dict_commands, username='root', port=22, ssh_key_str='', sudo=False):
    client = paramiko.SSHClient()
    client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    if len(ssh_key_str) > 0:
        # TODO: make ssh_key login
        pass
    else:
        client.connect(hostname, port=port, username=username)

    returned_array = list_dict_commands.copy()

    i = 0
    for command in list_dict_commands:
        log.debug('command to launch in ssh in {}: {}'.format(hostname, command['cmd']))
        stdin, stdout, stderr = client.exec_command(command['cmd'])
        returned_array[i]['out'] = stdout.read().decode('utf-8')
        returned_array[i]['err'] = stderr.read().decode('utf-8')
        log.debug('commnad launched / out: {} / error: {}'.format(returned_array[i]['out'], returned_array[i]['err']))
        i = i + 1

    client.close()

    return returned_array
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号