Retrieve data from a Junos device using Tables/Views

    table (required)
        Name of PyEZ Table

    table_file (required)
        YAML file that has the table specified in table parameter

    path:
        Path of location of the YAML file.
        defaults to op directory in jnpr.junos.op

    target:
        if command need to run on FPC, can specify fpc target

    key:
        To overwrite key provided in YAML

    key_items:
        To select only given key items

    filters:
        To select only filter for the dictionary from columns

    template_args:
        key/value pair which should render Jinja template command

    CLI Example:

    .. code-block:: bash

        salt 'device_name' junos.get_table

def get_table(table, table_file, path=None, target=None, key=None, key_items=None,
              filters=None, template_args=None):
    '''
    Retrieve data from a Junos device using Tables/Views

    table (required)
        Name of PyEZ Table

    table_file (required)
        YAML file that has the table specified in table parameter

    path:
        Path of location of the YAML file.
        defaults to op directory in jnpr.junos.op

    target:
        if command need to run on FPC, can specify fpc target

    key:
        To overwrite key provided in YAML

    key_items:
        To select only given key items

    filters:
        To select only filter for the dictionary from columns

    template_args:
        key/value pair which should render Jinja template command

    CLI Example:

    .. code-block:: bash

        salt 'device_name' junos.get_table
    '''
    conn = __proxy__['junos.conn']()
    ret = {}
    ret['out'] = True
    ret['hostname'] = conn._hostname
    ret['tablename'] = table
    get_kvargs = {}
    if target is not None:
        get_kvargs['target'] = target
    if key is not None:
        get_kvargs['key'] = key
    if key_items is not None:
        get_kvargs['key_items'] = key_items
    if filters is not None:
        get_kvargs['filters'] = filters
    if template_args is not None and isinstance(template_args, dict):
        get_kvargs['args'] = template_args
    pyez_tables_path = os.path.dirname(os.path.abspath(tables_dir.__file__))
    try:
        if path is not None:
            file_loc = glob.glob(os.path.join(path, '{}'.format(table_file)))
        else:
            file_loc = glob.glob(os.path.join(pyez_tables_path, '{}'.format(table_file)))
        if len(file_loc) == 1:
            file_name = file_loc[0]
        else:
            ret['message'] = 'Given table file {} cannot be located'.format(table_file)
            ret['out'] = False
            return ret
        try:
            with salt.utils.files.fopen(file_name) as fp:
                ret['table'] = yaml.load(fp.read(),
                                         Loader=yamlordereddictloader.Loader)
                globals().update(FactoryLoader().load(ret['table']))
        except IOError as err:
            ret['message'] = 'Uncaught exception during YAML Load - please ' \
                             'report: {0}'.format(six.text_type(err))
            ret['out'] = False
            return ret
        try:
            data = globals()[table](conn)
            data.get(**get_kvargs)
        except KeyError as err:
            ret['message'] = 'Uncaught exception during get API call - please ' \
                             'report: {0}'.format(six.text_type(err))
            ret['out'] = False
            return ret
        except ConnectClosedError:
            ret['message'] = 'Got ConnectClosedError exception. Connection lost ' \
                             'with {}'.format(conn)
            ret['out'] = False
            return ret
        ret['reply'] = json.loads(data.to_json())
        if data.__class__.__bases__[0] == OpTable:
            # Sets key value if not present in YAML. To be used by returner
            if ret['table'][table].get('key') is None:
                ret['table'][table]['key'] = data.ITEM_NAME_XPATH
            # If key is provided from salt state file.
            if key is not None:
                ret['table'][table]['key'] = data.KEY
        else:
            if target is not None:
                ret['table'][table]['target'] = data.TARGET
            if key is not None:
                ret['table'][table]['key'] = data.KEY
            if key_items is not None:
                ret['table'][table]['key_items'] = data.KEY_ITEMS
            if template_args is not None:
                ret['table'][table]['args'] = data.CMD_ARGS
                ret['table'][table]['command'] = data.GET_CMD
    except Exception as err:
        ret['message'] = 'Uncaught exception - please report: {0}'.format(
            str(err))
        traceback.print_exc()
        ret['out'] = False
        return ret
    return ret