get host system takes a very long time

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
Report Content as Inappropriate

get host system takes a very long time

Hello All
Currently i am using the following code to get host specific info, it takes a very long time roughly 20-30 seconds per host. Definitely number of vm's are more per host in my scenario and would take time
but is there any way i can improve the code to get all the host specific info:

    def get_host_list (self):
        now = time.time()
        if self.logger: self.logger.debug('Getting host list')
        obj_view = self.content.viewManager.CreateContainerView(self.content.rootFolder,[vim.HostSystem],True)
        vc_host_list = obj_view.view

        host_list = []
        for h in vc_host_list:
            i = { 'name':, 'moId': h._moId }

            #Gather VSS networking config from host
            port_group = []
            for n in
                port_group.append({'name':, 'vswitch': n.spec.vswitchName, 'vlanId': n.spec.vlanId })

            vswitch = []
            for v in
                pg = []
                for p in port_group:
                    if p['vswitch'] ==
                        pg.append({'name': p['name'], 'vlan-id': p['vlanId']})
                vswitch.append({ 'name':, 'mtu': v.mtu, 'portgroup': pg })
            i['host-vss'] = vswitch

            datastore = []
            for d in h.datastore:
                datastore.append({'name':, 'moId': d._moId })
            i['datastore'] = datastore

            vm = []
            for v in h.vm:
                if v.runtime.powerState == 'poweredOn':
                    vm.append({'name':, 'moId': v._moId })

            i['vm'] = vm
            i['parent'] = self.get_obj_parent(h)
            i['datacenter'] = self.get_obj_datacenter(h)
            i['cpu'] = {'threads': str(h.hardware.cpuInfo.numCpuThreads), 'cores': str(h.hardware.cpuInfo.numCpuCores) }
            i['memory'] = str(h.hardware.memorySize)