def clone_network(network_id, recipient_user_id=None, new_network_name=None, project_id=None, project_name=None,  new_project=True, **kwargs):
    """
     Create an exact clone of the specified network for the specified user.

     If project_id is specified, put the new network in there.

     Otherwise create a new project with the specified name and put it in there.

    """

    user_id = kwargs['user_id']

    ex_net = db.DBSession.query(Network).filter(Network.id==network_id).one()

    ex_net.check_read_permission(user_id)

    if project_id is None and new_project == True:

        log.info("Creating a new project for cloned network")

        ex_proj = db.DBSession.query(Project).filter(Project.id==ex_net.project_id).one()

        user = db.DBSession.query(User).filter(User.id==user_id).one()

        project = Project()
        if project_name is None or project_name=="":
            project_name=ex_proj.name + " (Cloned by %s)" % user.display_name

        #check a project with this name doesn't already exist:
        ex_project =  db.DBSession.query(Project).filter(Project.name==project_name,
                                                         Project.created_by==user_id).all()
        #If it exists, use it.
        if len(ex_project) > 0:
            project=ex_project[0]
        else:
            project.name = project_name
            project.created_by = user_id

            project.set_owner(user_id)

        if recipient_user_id!=None:
            project.set_owner(recipient_user_id)

        db.DBSession.add(project)
        db.DBSession.flush()

        project_id=project.id

    elif project_id is None:
        log.info("Using current project for cloned network")
        project_id=ex_net.project_id

    if new_network_name is None or new_network_name == "":
        new_network_name=ex_net.name

    log.info('Cloning Network...')

    #Find if there's any projects with this name in the project already
    ex_network =  db.DBSession.query(Network).filter(Network.project_id==project_id,
                                                     Network.name.like("{0}%".format(new_network_name))).all()

    if len(ex_network) > 0:
        new_network_name = new_network_name + " " + str(len(ex_network))

    newnet = Network()

    newnet.project_id = project_id
    newnet.name = new_network_name
    newnet.description = ex_net.description
    newnet.layout = ex_net.layout
    newnet.status = ex_net.status
    newnet.projection = ex_net.projection
    newnet.created_by = user_id

    newnet.set_owner(user_id)
    if recipient_user_id is not None:
        newnet.set_owner(recipient_user_id)

    db.DBSession.add(newnet)

    db.DBSession.flush()

    newnetworkid = newnet.id

    log.info('CLoning Nodes')
    node_id_map = _clone_nodes(network_id, newnetworkid)

    log.info('Cloning Links')
    link_id_map = _clone_links(network_id, newnetworkid, node_id_map)

    log.info('CLoning Groups')
    group_id_map = _clone_groups(network_id,
                                          newnetworkid,
                                          node_id_map,
                                          link_id_map)

    log.info("Cloning Resource Attributes")
    ra_id_map = _clone_resourceattrs(network_id, newnetworkid, node_id_map, link_id_map, group_id_map)

    log.info("Cloning Resource Types")
    _clone_resourcetypes(network_id, newnetworkid, node_id_map, link_id_map, group_id_map)

    log.info('Cloning Scenarios')
    _clone_scenarios(network_id, newnetworkid, ra_id_map, node_id_map, link_id_map, group_id_map, user_id)

    db.DBSession.flush()

    return newnetworkid