다른 호스트에 로그인하고 다음 python 스크립트를 실행하고 싶습니다.
isi storagepool list -v |
awk ' /Requested Protection:/ { parity=substr($NF,length($NF)-1,1) }
/Nodes:/ { nodes=$NF }
/HDD Total/ { hdd_total=$NF }
/HDD Used/ { hdd_used=$NF }
END {
multiplier=nodes-parity
total=hdd_total/nodes*multiplier
used=hdd_used/nodes
print "parity =" parity
print "NodeNumber =" nodes
print "Total = " total " TB"
print "Effective Total volume = " total*0.8 " TB"
print "USED =" used
print "Effective used=" used*multiplier*0.8 " TB"
print "Available volume=" (hdd_total-hdd_used)/nodes*multiplier*0.8 " TB" }'
아래 터널 스크립트에서는 isi Storagepool list 명령 대신 위 명령을 실행하려고 합니다. python.py
스토리지 호스트에서 파일을 생성할 수 없기 때문에 exec_command 스크립트를 찾고 있지 않습니다 .
import paramiko
from sshtunnel import SSHTunnelForwarder
with SSHTunnelForwarder(
('jump_host_ip', 222),
ssh_username="User.name",
ssh_pkey=paramiko.RSAKey.from_private_key_file("/tmp/id_rsa"),
# ssh_private_key_password="user_pass",
remote_bind_address=("host_ip", 22),
local_bind_address=('127.0.0.1', 10022)
) as tunnel:
client = paramiko.SSHClient()
# client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(hostname='127.0.0.1', username='user.name, password='user_pass', port=10022)
# client.connect('127.0.0.1', 10022)
# do some operations with client session
stdin, stdout, stderr = client.exec_command('sshpass -p ******* ssh root@Storage_host_ip "isi storagepool list"')
print stdout.readlines()
print stderr.readlines()
client.close()
print('FINISH!')`