I have written a python code to convert string into list and then compare status of each items.
Able to convert the list as: Each field is separated by more than one spaces(or tab):
['abc 2/2 Running 2 5h', 'def 3/3 Running 0 6h', 'xyz 1/1 Running 0 5h']
- I want to convert this into :
[['abc','2/2','Running','2','5h'], ['def','3/3','Running','0','6h'], ['xyz','1/1','Running','0', '5h']]
I want to verify all the status of the items(3rd field). If status of all 3 items are
"Running"
,flag_variable
is set toTrue
elseFalse
.from pexpect import pxssh import pexpect def Login_Server(hostip,user,passwd): User_Info_out = [] Cmd_Out = ' ' try: Cmd = pxssh.pxssh() Cmd.login(hostip, user, passwd) Cmd_Out = Execute_Script4(Cmd) except pxssh.ExceptionPxssh as e: User_Info_out = 'None' return User_Info_out,Cmd_Out def Execute_Script4(Cmd): getpod_out,Cmd_Out1b = ' ', ' ' pod_status = [] print("********************") Cmd.sendline('sudo su ') Cmd.prompt() Cmd.sendline('kubectl get pods') Cmd.prompt() getpod_out = Cmd.before pod_status = getpod_out.split() print("script output:") print (getpod_out) print("****************") getpod_out=getpod_out.splitlines()[3:-1] print(getpod_out) print(type(getpod_out)) Login_Server('XXX.XXX.X.XX','usera','password')
output:
******************** script output: sudo su root@workernode8:/home/ubuntu# kubectl get pods NAME READY STATUS RESTARTS AGE abc 2/2 Running 2 5h def 3/3 Running 0 6h xyz 1/1 Running 0 5h root@workernode8:/home/ubuntu# **************** ['abc 2/2 Running 2 5h', 'def 3/3 Running 0 6h', 'xyz 1/1 Running 0 5h'] <type 'list'>