如何通过 vmware SDK (pyvmomi) 获取 vm 集群名称

How to get vm cluster name via vmware SDK (pyvmomi)

我有获取 VM 容量(名称等)的代码。但有一个问题:我需要获取此 VM 的集群名称。如我所见,我们只能获取 LUN 名称,但不能获取集群名称。

                """Getting data from vCenter and parsing It"""

                try:
                   serviceInstance = connect.SmartConnectNoSSL(host=datacenter,user=user,pwd=password)
                except:
                   print "Connection error or cannot retrieve data"

                content = serviceInstance.RetrieveContent()
                viewType = [vim.VirtualMachine]
                recursive = True
                container = content.rootFolder
                containerView = containerView = content.viewManager.CreateContainerView(container, viewType, recursive)
                children = containerView.view
                return children

        def data_processing(self):
                vcContent = self.getting_data()
                for child in vcContent:
                        print child.summary.config

应该这样做:

print(child.summary.runtime.host.parent.name)