def auto_fs_granter(selexp):
    """
    Grants flowspaces for previously conflictive slices at Flowvisor.
    Used in conjunction **and after** the script with the same name
    at expedient.
    
    Flow:
        1. Expedient: manage.py standardize_flowvisor_slices stop
        2. Expedient: manage.py standardize_flowvisor_slices start
        3. Opt-in: manage.py standardize_flowvisor_slices
    """
    from django.conf import settings
    from openflow.optin_manager.xmlrpc_server.models import FVServerProxy
    from openflow.optin_manager.users.models import Priority, UserProfile
    from django.contrib.auth.models import User
    from openflow.optin_manager.opts.helper import opt_fs_into_exp
    from openflow.optin_manager.flowspace.helper import multi_fs_intersect, single_fs_intersect
    from openflow.optin_manager.opts.models import Experiment, ExperimentFLowSpace, UserFlowSpace, AdminFlowSpace, UserOpts

    # If 'slice_ids_to_grant_fs' file exists, do the following.
    # Otherwise warn and skip.
    try:
        user = User.objects.filter(username=settings.ROOT_USERNAME)[0]
        adminFS = AdminFlowSpace.objects.filter(user = user)
        profile = UserProfile.get_or_create_profile(user)
        fv = FVServerProxy.objects.all()[0]
        assigned_priority = profile.max_priority_level - Priority.Strict_Priority_Offset - 1
        all_this_admin_opts = UserOpts.objects.filter(user=user,nice=True)
        for admin_opt in all_this_admin_opts:
            if admin_opt.priority <= assigned_priority:
                assigned_priority = admin_opt.priority - 1
        # Filter by slice "keywords" (name), same as in the previous steps
        flow_space = ExperimentFLowSpace.objects.filter(exp=selexp.id)
        if not flow_space:
            print "No matched flowspaces for slice %s" % selexp.slice_id
            raise Exception('No matched flowspaces for slice %s' % selexp.slice_id)		
        #intersected_flowspace = multi_fs_intersect(flow_space,adminFS,FlowSpace)
        intersected_flowspace = get_used_fs(flow_space)
        fv_args,match_list = opt_fs_into_exp(intersected_flowspace,selexp,user,assigned_priority,True)
        returned_ids = fv.proxy.api.changeFlowSpace(fv_args)
        for i in range(len(match_list)):
            match_list[i].fv_id = returned_ids[i]
            match_list[i].save()
        allopts = UserOpts.objects.filter(user = user).order_by('-priority')
     
        for opt in allopts:
            this_opt_fses = opt.optsflowspace_set.all()
            fs_project = opt.experiment.project_name or ""
            fs_slice = opt.experiment.slice_name or ""
            fs_description = ""
            for fs in this_opt_fses:
                if fs_description != "":
                    fs_description = fs_description + "\n%s" % fs
                else:
                    fs_description = "%s" % fs
        print "Flowspace for slice %s was successfully granted" % selexp.slice_id 
    except Exception as e:
        raise e
dataset/ETHPy150Open fp7-ofelia/ocf/optin_manager/src/python/openflow/optin_manager/opts/autofsgranter.py/auto_fs_granter/original