'Refresh or disable DHCP for a network depending on the current state
of the network.'

def refresh_dhcp_helper(self, network_id):

    old_network = self.cache.get_network_by_id(network_id)
    if (not old_network):
        return self.enable_dhcp_helper(network_id)
    network = self.safe_get_network_info(network_id)
    if (not network):
        return
    if (not any((s for s in network.subnets if s.enable_dhcp))):
        self.disable_dhcp_helper(network.id)
        return
    old_non_local_subnets = getattr(old_network, 'non_local_subnets', [])
    new_non_local_subnets = getattr(network, 'non_local_subnets', [])
    old_cidrs = [s.cidr for s in (old_network.subnets + old_non_local_subnets)]
    new_cidrs = [s.cidr for s in (network.subnets + new_non_local_subnets)]
    if (old_cidrs == new_cidrs):
        self.call_driver('reload_allocations', network)
        self.cache.put(network)
    elif self.call_driver('restart', network):
        self.cache.put(network)
    self.dhcp_ready_ports |= {p.id for p in network.ports}
    self.update_isolated_metadata_proxy(network)
