2 Replies Latest reply on Apr 9, 2020 4:45 AM by LucD

    Using Python SDK

    Daithi_N Novice



      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)






      for hosts in data:

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




        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: