def execute(config, state):
    log.info('Started an iteration')
    vm_path = common.build_local_vm_path(config['local_data_directory'])
    host_path = common.build_local_host_path(config['local_data_directory'])
    data_length = int(config['data_collector_data_length'])
    vms_previous = get_previous_vms(vm_path)
    vms_current = get_current_vms(state['vir_connection'])

    vms_added = get_added_vms(vms_previous, vms_current.keys())
    added_vm_data = dict()
    if vms_added:
        if log.isEnabledFor(logging.DEBUG):
            log.debug('Added VMs: %s', str(vms_added))

        for i, vm in enumerate(vms_added):
            if vms_current[vm] != libvirt.VIR_DOMAIN_RUNNING:
                del vms_added[i]
                del vms_current[vm]
                if log.isEnabledFor(logging.DEBUG):
                    log.debug('Added VM %s skipped as migrating in', vm)

        added_vm_data = fetch_remote_data(state['db'],
                                          data_length,
                                          vms_added)
        if log.isEnabledFor(logging.DEBUG):
            log.debug('Fetched remote data: %s', str(added_vm_data))
        write_vm_data_locally(vm_path, added_vm_data, data_length)

    vms_removed = get_removed_vms(vms_previous, vms_current.keys())
    if vms_removed:
        if log.isEnabledFor(logging.DEBUG):
            log.debug('Removed VMs: %s', str(vms_removed))
        cleanup_local_vm_data(vm_path, vms_removed)
        for vm in vms_removed:
            del state['previous_cpu_time'][vm]
            del state['previous_cpu_mhz'][vm]

    log.info('Started VM data collection')
    current_time = time.time()
    (cpu_time, cpu_mhz) = get_cpu_mhz(state['vir_connection'],
                                      state['physical_core_mhz'],
                                      state['previous_cpu_time'],
                                      state['previous_time'],
                                      current_time,
                                      vms_current.keys(),
                                      state['previous_cpu_mhz'],
                                      added_vm_data)
    log.info('Completed VM data collection')

    log.info('Started host data collection')
    (host_cpu_time_total,
     host_cpu_time_busy,
     host_cpu_mhz) = get_host_cpu_mhz(state['physical_cpu_mhz'],
                                      state['previous_host_cpu_time_total'],
                                      state['previous_host_cpu_time_busy'])
    log.info('Completed host data collection')

    if state['previous_time'] > 0:
        append_vm_data_locally(vm_path, cpu_mhz, data_length)
        append_vm_data_remotely(state['db'], cpu_mhz)

        total_vms_cpu_mhz = sum(cpu_mhz.values())
        host_cpu_mhz_hypervisor = host_cpu_mhz - total_vms_cpu_mhz
        if host_cpu_mhz_hypervisor < 0:
            host_cpu_mhz_hypervisor = 0
        total_cpu_mhz = total_vms_cpu_mhz + host_cpu_mhz_hypervisor
        append_host_data_locally(host_path, host_cpu_mhz_hypervisor, data_length)
        append_host_data_remotely(state['db'],
                                  state['hostname'],
                                  host_cpu_mhz_hypervisor)

        if log.isEnabledFor(logging.DEBUG):
            log.debug('Collected VM CPU MHz: %s', str(cpu_mhz))
            log.debug('Collected total VMs CPU MHz: %s', str(total_vms_cpu_mhz))
            log.debug('Collected hypervisor CPU MHz: %s', str(host_cpu_mhz_hypervisor))
            log.debug('Collected host CPU MHz: %s', str(host_cpu_mhz))
            log.debug('Collected total CPU MHz: %s', str(total_cpu_mhz))

        state['previous_overload'] = log_host_overload(
            state['db'],
            state['host_cpu_overload_threshold'],
            state['hostname'],
            state['previous_overload'],
            state['physical_cpu_mhz'],
            total_cpu_mhz)

    state['previous_time'] = current_time
    state['previous_cpu_time'] = cpu_time
    state['previous_cpu_mhz'] = cpu_mhz
    state['previous_host_cpu_time_total'] = host_cpu_time_total
    state['previous_host_cpu_time_busy'] = host_cpu_time_busy

    log.info('Completed an iteration')
    return state
Execute a data collection iteration.
dataset/ETHPy150Open beloglazov/openstack-neat/neat/locals/collector.py/execute