'Sync the local DHCP state with Neutron. If no networks are passed,
or \'None\' is one of the networks, sync all of the networks.'

@_sync_lock
def sync_state(self, networks=None):

    only_nets = set(([] if ((not networks) or (None in networks)) else networks))
    LOG.info(_LI('Synchronizing    state'))
    pool = eventlet.GreenPool(self.conf.num_sync_threads)
    known_network_ids = set(self.cache.get_network_ids())
    try:
        active_networks = self.plugin_rpc.get_active_networks_info()
        LOG.info(_LI('All    active    networks    have    been    fetched    through    RPC.'))
        active_network_ids = set((network.id for network in active_networks))
        for deleted_id in (known_network_ids - active_network_ids):
            try:
                self.disable_dhcp_helper(deleted_id)
            except Exception as e:
                self.schedule_resync(e, deleted_id)
                LOG.exception(_LE('Unable    to    sync    network    state    on    deleted    network    %s'), deleted_id)
        for network in active_networks:
            if ((not only_nets) or (network.id not in known_network_ids) or (network.id in only_nets)):
                pool.spawn(self.safe_configure_dhcp_for_network, network)
        pool.waitall()
        self.dhcp_ready_ports |= set(self.cache.get_port_ids(only_nets))
        LOG.info(_LI('Synchronizing    state    complete'))
    except Exception as e:
        if only_nets:
            for network_id in only_nets:
                self.schedule_resync(e, network_id)
        else:
            self.schedule_resync(e)
        LOG.exception(_LE('Unable    to    sync    network    state.'))
