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

    Using Python SDK

    Daithi_N Novice

      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)