def get_vrf(arg = None, default_var = 'default_vrf_rt', abort = False):
    """ Returns VRF to work in

        Returns a pynipap.VRF object representing the VRF we are working
        in. If there is a VRF set globally, return this. If not, fetch the
        VRF named 'arg'. If 'arg' is None, fetch the default_vrf
        attribute from the config file and return this VRF.
    """

    # yep, global variables are evil
    global vrf

    # if there is a VRF set, return it
    if vrf is not None:
        return vrf

    if arg is None:
        # fetch default vrf
        try:
            vrf_rt = cfg.get('global', default_var)
        except ConfigParser.NoOptionError:
            # default to all VRFs
            vrf_rt = 'all'
    else:
        vrf_rt = arg

    if vrf_rt.lower() == 'all':
        vrf = VRF()
        vrf.rt = 'all'
    else:
        if vrf_rt.lower() in ('-', 'none'):
            vrf_rt = None

        try:
            vrf = VRF.search({ 'val1': 'rt',
                'operator': 'equals',
                'val2': vrf_rt
                })['result'][0]
        except (__HOLE__, IndexError):
            if abort:
                print >> sys.stderr, "VRF with [RT: %s] not found." % str(vrf_rt)
                sys.exit(1)
            else:
                vrf = False

    return vrf
dataset/ETHPy150Open SpriteLink/NIPAP/nipap-cli/nipap_cli/nipap_cli.py/get_vrf