0

Below is the code:

client = paramiko.SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect("1.1.1.1",  username=username, password=password)
stdin, stdout, stderr = client.exec_command("set -units GB")
stdin, stdout, stderr = client.exec_command("vol show -vserver vs1 -volume test_volume -fields size")
return stdout.read()

Output getting from code:

 vserver                          volume             size
 ------------------------  ------------------         ------
 vs1                       test_volume               1.07TB

Output from device:

 test01::> set -units GB

 test01::> vol show -vserver vs1 -volume test_volume -fields size

 vserver                          volume             size
 ------------------------  ------------------         ------
 vs1                       test_volume               1100GB

Looks like paramiko not executing commands in same channel. How do i get value "1100GB" in python script also?

Hint: Both command should execute in same session so that i will get expected output like in device

1 Answer 1

2

When you run client.exec_command(), the commands are actually running in different exec sessions, so your call to set -units GB isn't actually active for your second call to vol show -vserver vs1 -volume test_volume -fields size

You could try separating the commands with a semi-colon and running them in one session

stdin, stdout, stderr = client.exec_command(
    "set -units GB; vol show -vserver vs1 -volume test_volume -fields size")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.