I writing a python code which connect to remote Vm using paramiko and issue some command. I want to be able to issue a command to get pod information eg: "oc get pod".
The code works fine when sending normal Linux command eg: "df -h" and also works fine with kubectl, but when I try to send command to openShift cluster for the pod information like "oc get pod" I got no response.
script:
import paramiko
from time import sleep
ip_add = "IP_address"
uname = "username"
password = "password"
port = 22
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(hostname=ip_add, username=uname, password=password)
def get_pod_name(client):
pod_name = ""
command = 'oc get pod'
stdin, stdout, stderr = client.exec_command(command)
result = str(stdout.read().decode())
print(stderr)
client.close()
output:
<paramiko.ChannelFile from <paramiko.Channel 0 (EOF received) (open) window=2097152 -> <paramiko.Transport at 0x9ae84b50 (cipher aes128-ctr, 128 bits) (active; 1 open channel(s))>>>
Process finished with exit code 0
more details:
pyhton3.9
vm OS - Red Hat Enterprise Linux 8.4 (Ootpa)
openShift cluster