How to use the ciscoconfparse.ciscoconfparse.IOSConfigList function in ciscoconfparse

To help you get started, we’ve selected a few ciscoconfparse examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mpenning / ciscoconfparse / ciscoconfparse / ciscoconfparse.py View on Github external
CiscoConfParse=self)
            else:
                raise ValueError("FATAL: '{}' is an unknown syntax".format(syntax))

        ## Accept either a string or unicode...
        elif getattr(config, 'encode', False):
            # Try opening as a file
            try:
                if syntax=='ios':
                    # string - assume a filename... open file, split and parse
                    if self.debug:
                        _log.debug("parsing from '{0}' with ios syntax".format(config))
                    f = open(config, mode="rU")
                    text = f.read()
                    rgx = re.compile(linesplit_rgx)
                    self.ConfigObjs = IOSConfigList(rgx.split(text), 
                        comment_delimiter=comment, 
                        debug=debug,
                        factory=factory,
                        ignore_blank_lines=ignore_blank_lines,
                        syntax='ios',
                        CiscoConfParse=self)
                elif syntax=='asa':
                    # string - assume a filename... open file, split and parse
                    if self.debug:
                        _log.debug("parsing from '{0}' with asa syntax".format(config))
                    f = open(config, mode="rU")
                    text = f.read()
                    rgx = re.compile(linesplit_rgx)
                    self.ConfigObjs = ASAConfigList(rgx.split(text), 
                        comment_delimiter=comment, 
                        debug=debug,
github mpenning / ciscoconfparse / ciscoconfparse / ciscoconfparse.py View on Github external
- comment (str): A comment delimiter.  This should only be changed when parsing non-Cisco IOS configurations, which do not use a !  as the comment delimiter.  ``comment`` defaults to '!'
            - debug (bool): ``debug`` defaults to False, and should be kept that way unless you're working on a very tricky config parsing problem.  Debug output is not particularly friendly
            - ignore_blank_lines (bool): ``ignore_blank_lines`` defaults to True; when this is set True, ciscoconfparse ignores blank configuration lines.  You might want to set ``ignore_blank_lines`` to False if you intentionally use blank lines in your configuration (ref: Github Issue #2).

        Returns:
           - An instance of an :class:`~ciscoconfparse.IOSConfigList` object.

        """
        #data = kwargs.get('data', None)
        #comment_delimiter = kwargs.get('comment_delimiter', '!')
        #debug = kwargs.get('debug', False)
        #factory = kwargs.get('factory', False)
        #ignore_blank_lines = kwargs.get('ignore_blank_lines', True)
        #syntax = kwargs.get('syntax', 'ios')
        #CiscoConfParse = kwargs.get('CiscoConfParse', None)
        super(IOSConfigList, self).__init__()

        self._list = list()
        self.CiscoConfParse = CiscoConfParse
        self.comment_delimiter = comment_delimiter
        self.factory = factory
        self.ignore_blank_lines = ignore_blank_lines
        self.syntax = syntax
        self.dna = 'IOSConfigList'
        self.debug = debug

        ## Support either a list or a generator instance
        if getattr(data, '__iter__', False):
            self._list = self._bootstrap_obj_init(data)
        else:
            self._list = list()
github mpenning / ciscoconfparse / ciscoconfparse / ciscoconfparse.py View on Github external
factory=factory,
                        ignore_blank_lines=ignore_blank_lines,
                        syntax='asa',
                        CiscoConfParse=self)

                elif syntax=='junos':
                    # string - assume a filename... open file, split and parse
                    if self.debug:
                        _log.debug("parsing from '{0}' with junos syntax".format(config))
                    f = open(config, mode="rU")
                    text = f.read()
                    rgx = re.compile(linesplit_rgx)

                    config = self.convert_braces_to_ios(rgx.split(text))
                    ## FIXME I am shamelessly abusing the IOSConfigList for now...
                    self.ConfigObjs = IOSConfigList(config,
                        comment_delimiter=comment, 
                        debug=debug,
                        factory=factory,
                        ignore_blank_lines=ignore_blank_lines,
                        syntax='junos',
                        CiscoConfParse=self)
                else:
                    raise ValueError("FATAL: '{}' is an unknown syntax".format(syntax))

            except IOError:
                print("[FATAL] CiscoConfParse could not open '%s'" % config)
                raise RuntimeError
        else:
            raise RuntimeError("[FATAL] CiscoConfParse() received" + 
                " an invalid argument\n")
        self.ConfigObjs.CiscoConfParse = self
github GoSecure / Cisco2Checkpoint / lib / ciscoconfparse_patch.py View on Github external
factory=factory,
                        ignore_blank_lines=ignore_blank_lines,
                        syntax='asa',
                        CiscoConfParse=self)

                elif syntax=='junos':
                    # string - assume a filename... open file, split and parse
                    if self.debug:
                        _log.debug("parsing from '{0}' with junos syntax".format(config))
                    f = open(config, mode="rU")
                    text = f.read()
                    rgx = re.compile(linesplit_rgx)

                    config = self.convert_braces_to_ios(rgx.split(text))
                    ## FIXME I am shamelessly abusing the IOSConfigList for now...
                    self.ConfigObjs = ccp.IOSConfigList(config,
                        comment_delimiter=comment, 
                        debug=debug,
                        factory=factory,
                        ignore_blank_lines=ignore_blank_lines,
                        syntax='junos',
                        CiscoConfParse=self)
                else:
                    raise ValueError("FATAL: '{}' is an unknown syntax".format(syntax))

            except IOError:
                print("[FATAL] CiscoConfParse could not open '%s'" % config)
                raise RuntimeError
        else:
            raise RuntimeError("[FATAL] CiscoConfParse() received" + 
                " an invalid argument\n")
        self.ConfigObjs.CiscoConfParse = self
github mpenning / ciscoconfparse / ciscoconfparse / ciscoconfparse.py View on Github external
if self.debug:
                    _log.debug("parsing from a python list with asa syntax")
                self.ConfigObjs = ASAConfigList(data=config, 
                    comment_delimiter=comment, 
                    debug=debug, 
                    factory=factory, 
                    ignore_blank_lines=ignore_blank_lines,
                    syntax='asa',
                    CiscoConfParse=self)
            elif syntax=='junos':
                ## FIXME I am shamelessly abusing the IOSConfigList for now...
                # we already have a list object, simply call the parser
                config = self.convert_braces_to_ios(config)
                if self.debug:
                    _log.debug("parsing from a python list with junos syntax")
                self.ConfigObjs = IOSConfigList(data=config, 
                    comment_delimiter=comment, 
                    debug=debug, 
                    factory=factory, 
                    ignore_blank_lines=ignore_blank_lines,
                    syntax='junos',
                    CiscoConfParse=self)
            else:
                raise ValueError("FATAL: '{}' is an unknown syntax".format(syntax))

        ## Accept either a string or unicode...
        elif getattr(config, 'encode', False):
            # Try opening as a file
            try:
                if syntax=='ios':
                    # string - assume a filename... open file, split and parse
                    if self.debug:
github GoSecure / Cisco2Checkpoint / lib / ciscoconfparse_patch.py View on Github external
You will find a great class description in ccp.CiscoConfParse
        """

        # all IOSCfgLine object instances...
        self.comment_delimiter = comment
        self.factory = factory
        self.ConfigObjs = None
        self.syntax = syntax
        self.debug = debug

        if isinstance(config, list) or isinstance(config, Iterator):
            if syntax=='ios':
                # we already have a list object, simply call the parser
                if self.debug:
                    _log.debug("parsing from a python list with ios syntax")
                self.ConfigObjs = ccp.IOSConfigList(data=config, 
                    comment_delimiter=comment, 
                    debug=debug, 
                    factory=factory, 
                    ignore_blank_lines=ignore_blank_lines,
                    syntax='ios',
                    CiscoConfParse=self)
            elif syntax=='asa':
                # we already have a list object, simply call the parser
                if self.debug:
                    _log.debug("parsing from a python list with asa syntax")
                self.ConfigObjs = ASAConfigList(data=config, 
                    comment_delimiter=comment, 
                    debug=debug, 
                    factory=factory, 
                    ignore_blank_lines=ignore_blank_lines,
                    syntax='asa',