Finding the list of VMs and their properties from a particular host

138 views
Skip to first unread message

Padmanabhan Rajan

unread,
Jan 23, 2017, 12:42:15 PM1/23/17
to pysphere
Hi all,

Thanks for sharing useful info related to pyshere.

I am trying to write a program to list VMs and its properties for a particular host in a cluster.  The following program lists several other VMs that are not a part of the host. 
Help improving the program with listing of properties of the VM too will be of great help.. Thanks!! 

# Import the pysphere library
from pysphere import *
import ssl

#Disabling Certificate verification
try:
_create_unverified_https_context = ssl._create_unverified_context
except AttributeError:
# Legacy Python that doesn't verify HTTPS certificates by default
pass
else:
# Handle target environment that doesn't support HTTPS verification
ssl._create_default_https_context = _create_unverified_https_context

#Create an object to work with
server = VIServer()

#Connect to the server
esxi_host = "XXXX"
esxi_user = "Username_here"
esxi_password = "Password_here"
print "Connecting to ESXi Host: " + esxi_host
server.connect(esxi_host, esxi_user, esxi_password)

print "Connected."
host_pl= server.get_hosts()["host-XXX"]
print "The connected host is: " + host_pl
vmlist=server.get_registered_vms(cluster="YYYY",status='poweredOn',)
i=0
for vms in vmlist:
print vms
i+=1
server.disconnect()
print "Disconnected."
Reply all
Reply to author
Forward
0 new messages