def load_index_data(): """Load data from index file.""" index_data = [] with open('%s%sindex' % (_get_template_dir(), os.sep)) as indexfs: data = csv.reader(indexfs) for row in data: if len(row) > 2 and row[0] != 'Template': index_data.append(row) return index_data
def load_index_data(): """Load data from index file.""" index_data = [] with open("{0}{1}index".format(_get_template_dir(), os.sep)) as indexfs: data = csv.reader(indexfs) for row in data: if len(row) > 2 and row[0] != "Template": index_data.append(row) return index_data
def _parse_textfsm(self, platform=None, command=None, raw=None): """ textfsm returns list of dict, make it JSON/dict :param platform: vendor platform, for ex cisco_xr :param command: cli command to be parsed :param raw: string blob output from the cli command execution :return: dict of parsed data. """ attrs = dict(Command=command, Platform=platform) template = None template_dir = None if self.template_dir is not None: # we dont need index file for lookup index = None template_path = os.path.join( self.template_dir, "{}_{}.textfsm".format(platform, "_".join(command.split())), ) if not os.path.exists(template_path): msg = "Template file %s missing" % template_path logger.error(msg) raise FileNotFoundError(msg) else: template = template_path template_dir = self.template_dir if template_dir is None: index = "index" template_dir = ntc_parse._get_template_dir() cli_table = ntc_parse.clitable.CliTable(index, template_dir) try: cli_table.ParseCmd(raw, attrs, template) except ntc_parse.clitable.CliTableError as ex: logger.error('Unable to parse command "%s" on platform %s' % (command, platform)) raise ex return self._filter_output(cli_table)