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
评论列表
文章目录