import argparse
from pyVmomi import vim
from pyVim.connect import SmartConnect,Disconnect
import atexit
import ssl
def validate_options():
parser = argparse.ArgumentParser(description='input parameters')
parser.add_argument('-d','--dest_host',dest='dhost',required=True,help='The ESxi destination host IP')
parser.add_argument('-v','--vc_host',dest='vchost',required=False,help='The VC ip')
parser.add_argument('-u','--vc_user',dest='vcuser',required=True,help='VC username')
parser.add_argument('-p','--vc_pass',dest='vcpasswd',required=True,help='VC passwd')
args = parser.parse_args()
return args
def getHostID(content,dhost):
if content.searchIndex.FindByIp(None,dhost,False):
host = content.searchIndex.FindByIp(None,dhost,False)
else:
host = content.searchIndex.FindByDnsName(None,dhost,False)
return host
def get_HostInfo(content,dhost):
search_index = content.searchIndex
root_folder = content.rootFolder
view_ref = content.viewManager.CreateContainerView(container=root_folder,type=[vim.HostSystem], recursive=True)
host = view_ref.view[0]
#print host.name
print 'UUID INFO %s' %(host.summary.hardware.uuid)
print 'Hardware Model %s' %(host.summary.hardware.model)
print '%s Server has %s Biosversion'%(host.hardware.biosInfo.vendor,host.hardware.biosInfo.biosVersion)
pcilist=host.hardware.pciDevice
print '{0}'.format("Vendor Name").ljust(20)+ '{0}'.format("Device Name").ljust(120)+ '{0}'.format("Slot").ljust(30)+ '{0}'.format('Device ID').ljust(10)
print '*************************************************************************************************************************************************************************************************'
for i in pcilist:
a = i.vendorName
b = i.deviceName
c = i.deviceId
d = i.slot
print '{0}'.format(a).ljust(20)+ '{0}'.format(b).ljust(120)+ '{0}'.format(d).ljust(30)+ '{0}'.format(c).ljust(10)
#print '%s has devicename %s and device ID %s'%(i.vendorName,i.deviceName,i.deviceId)
print '*********************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************'
def main():
opts = validate_options()
if opts.vchost:
print 'Connecting to vcenter and collecting sensor info for %s' %opts.dhost
else:
print 'Connecting to esxi host for %s' %opts.dhost
opts.vchost = opts.dhost
si = SmartConnect(host=opts.vchost, user=opts.vcuser, pwd=opts.vcpasswd)
content = si.RetrieveContent()
#print content
hostinfo = get_HostInfo(content,opts.dhost)
hostid = getHostID(content,opts.dhost)
sensorinfo=hostid.runtime.healthSystemRuntime.systemHealthInfo.numericSensorInfo
print '{0}'.format("Sensor").ljust(30)+ '{0}'.format("Sensor Detail").ljust(90)+ '{0}'.format('Status').ljust(10)+ '{0}'.format('Reading').ljust(10) +'{0}'.format('Units').ljust(13)+ '{0}'.format('Summary').ljust(20)
print '**************************************************************************************************************************************************************************************************************'
for i in sensorinfo:
j = i.healthState
a=str(i.currentReading)
b=i.baseUnits
c=i.sensorType
print '{0}'.format(c).ljust(30)+ '{0}'.format(i.name).ljust(90)+ '{0}'.format(j.label).ljust(10)+ '{0}'.format(a).ljust(10) + '{0}'.format(b).ljust(13)+ '{0}'.format(j.summary).ljust(20)
if __name__ =='__main__':
main()
How to run this script : python <name of script> -v <vc server> -d <esxi host which hardware want to list> -u <vc user name> -p <vc password>
This script is written in python. I have used the pyVmomi module.