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
|

get host system takes a very long time

badveli
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': h.name, 'moId': h._moId }

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

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

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

            vm = []
            for v in h.vm:
                if v.runtime.powerState == 'poweredOn':
                    vm.append({'name': v.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)

            host_list.append(i)