tunnel no script python com execução do comando python

1

Eu quero fazer login no host diferente e quero executar o script abaixo

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" }'

no script de encapsulamento abaixo, em vez do comando isi storagepool list, queremos executar o comando acima. nós não estamos procurando exec_command o script python.py , porque não podemos criar nenhum arquivo no host de armazenamento.

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!')'
    
por Shanker 21.04.2017 / 08:59

0 respostas