Problem Statement – Have a list of VMWare Instances and wanted to quickly iterate and see what VMs are powered on, this has nothing to do with Vmware or ESXI, look at the below image, programmatically I want to pick two specific rows and perform dictionary operations on them.

Git – https://github.com/yukthr/auts/blob/master/random_programs/pandas_vmware_esxi.py

for someone like me who is partly into programming and mostly into networking, anything effective is easy, I could have gone with the other way of doing this but  since Pandas are effective i would text parsing with them.

 

I only want two sections which are of interest to me, in a normal way maybe I should have pasted this in excel and Do a text to the column and do a manual data extraction, but wanted to do it with Pandas and they are powerful.

First things first

  • Read with Pandas
  • Read the text
  • If possible convert into CSV (as I have some experience with csv file operations)
  • Then split the Columns and make the dictionary for further use

 

 

Let’s see how this proceeds

Pandas make it so powerful to just pick Columns out of the fly, in this case, I wanted them from [1] and [6], with some code I could write up a sample script which helps in getting the power state. The next operations would be to read the os.system output and parse it but we all know how that can be done in general python use cases.

Final program looks something like this

 

-Rakesh