VMware Cloud Community
Daithi_N
Enthusiast
Enthusiast

Using Python SDK

Hi,

Does any one know how I can get all ESXi Hosts within a vCenter that are in Maintenance Mode using Python SDK ?

Using the below Code I'm able to print out all the ESXi Servers. but not able to figure out only to print out the ESXi that are currently in Maintenance Mode

from pyVim.connect import SmartConnect

from pyVmomi import vim

import ssl

import os


with open("vCenterServer.csv", 'r') as f:

    reader = csv.reader(f, delimiter=',')

    data = list(reader)

    f.close()

s=ssl.SSLContext(ssl.PROTOCOL_TLSv1)

s.verify_mode=ssl.CERT_NONE

for hosts in data:

  si= SmartConnect(host=" ", user="", pwd="",sslContext=s)

  content=si.content

  def get_all_objs(content, vimtype😞

          obj = {}

          container = content.viewManager.CreateContainerView(content.rootFolder, vimtype, True)

          for managed_object_ref in container.view:

                  obj.update({managed_object_ref: managed_object_ref.name})

          return obj

  getESXi=get_all_objs(content, [vim.HostSystem])

  for vm in getESXi:

          print(vm.name)

Reply
0 Kudos
2 Replies
LucD
Leadership
Leadership

I think you better post that question on the vSphere Automation SDK for Python Forum


Sorry, can't move it there.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Daithi_N
Enthusiast
Enthusiast

Hi,

I have now Created a Topic on that Forum Thanks.

Reply
0 Kudos