1

I want to login to different host and get want to execute the below python script

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

in the below tunnel script instead of isi storagepool list command, we want to run the above command. we are not looking for exec_command the python.py script, because we can't create any file on storage host.

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!')`
  • What is the actual question? – schaiba Apr 21 '17 at 7:14
  • I want to create a tunnel to get into the jumphost and then again run a ssh to a server and then run the awk command which gives the output – Shanker Apr 21 '17 at 7:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.