def namespace_haproxy_for_cell(services, cell_name):
    """Add namespacing to HAProxy configuration for a cell.

    :param services: dict defining service configuration.
    :param cell_name: name of the cell, or empty if cell has no name.
    :returns: the services dict, with haproxy configuration modified to
            provide namespacing between cells.
    """
    def _namespace(name):
        # Backwards compatibility - no cell name suffix for cells without a
        # name.
        return "{}_{}".format(name, cell_name) if cell_name else name

    # Service name must be namespaced as haproxy-config uses this as the
    # config file name.
    services = {
        _namespace(service_name): service
        for service_name, service in services.items()
    }
    for service in services.values():
        if service.get('haproxy'):
            service['haproxy'] = {
                _namespace(name): service['haproxy'][name]
                for name in service['haproxy']
            }
    return services