How to use the ciscoconfparse.ciscoconfparse 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 GoSecure / Cisco2Checkpoint / lib / ciscoconfparse_patch.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 = ccp.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 / sphinx-doc / conf.py View on Github external
# The encoding of source files.
#source_encoding = 'utf-8'

# The master toctree document.
master_doc = 'index'

# General information about the project.
project = u'ciscoconfparse'
copyright = u'2007-%s, %s' % (time.strftime('%Y'), ciscoconfparse.ciscoconfparse.__author__)

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '.'.join(ciscoconfparse.ciscoconfparse.__version__.split('.')[0:2])
# The full version, including alpha/beta/rc tags.
release = ciscoconfparse.ciscoconfparse.__version__

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#language = None

# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
#today = ''
# Else, today_fmt is used as the format for a strftime call.
#today_fmt = '%B %d, %Y'

# List of documents that shouldn't be included in the build.
#unused_docs = []
github mpenning / ciscoconfparse / sphinx-doc / conf.py View on Github external
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# The suffix of source filenames.
source_suffix = '.rst'

# The encoding of source files.
#source_encoding = 'utf-8'

# The master toctree document.
master_doc = 'index'

# General information about the project.
project = u'ciscoconfparse'
copyright = u'2007-%s, %s' % (time.strftime('%Y'), ciscoconfparse.ciscoconfparse.__author__)

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '.'.join(ciscoconfparse.ciscoconfparse.__version__.split('.')[0:2])
# The full version, including alpha/beta/rc tags.
release = ciscoconfparse.ciscoconfparse.__version__

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#language = None

# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
github GoSecure / Cisco2Checkpoint / lib / ciscoconfparse_patch.py View on Github external
mm_r = self._mm_results
        return mm_r['inactive1'] or mm_r['inactive2']

    @property
    def time_range(self):
        mm_r = self._mm_results
        return mm_r['time_range1'] or mm_r['time_range2']

    # TODO: This should not be needed
    # Otherwise: fix code to support this attribute.
    @property
    def established(self):
        mm_r = self._mm_results
        return mm_r['established']

class ASAConfigList(ccp.ASAConfigList):
    def __init__(self, data=None, comment_delimiter='!', debug=False, 
        factory=False, ignore_blank_lines=True, syntax='asa', CiscoConfParse=None):
        super(ASAConfigList, self).__init__(data, comment_delimiter, debug, factory, \
                                   ignore_blank_lines, syntax, CiscoConfParse)

        ### New Internal structures
        self._RE_NETS  = re.compile(r'^\s*object\s+network\s+(\S+)')
        self._RE_SVCS  = re.compile(r'^\s*object\s+service\s+(\S+)')
        self._RE_OBJPRO = re.compile(r'^\s*object-group\s+protocol\s+(\S+)')

    @property
    def object_network(self):
        """Return a dictionary of name to object network mappings"""
        retval = dict()
        obj_rgx = self._RE_NETS
        for obj in self.CiscoConfParse.find_objects(obj_rgx):
github GoSecure / Cisco2Checkpoint / lib / ciscoconfparse_patch.py View on Github external
comment_delimiter=comment_delimiter) # instance of the proper subclass
            return inst
    raise ValueError("Could not find an object for '%s'" % line)

##
##------------- Monkey Patching
## Temporary patch. Goal is to send a pull request to the project.
##
ccp.ConfigLineFactory = ConfigLineFactory
models_asa.ASAConfigList = ASAConfigList

##
##------------- New CiscoConfParse definition
## Reason: Have a good reference to ASAConfigList
##
class CiscoConfParse(ccp.CiscoConfParse):
    """Parses Cisco IOS configurations and answers queries about the configs"""

    def __init__(self, config="", comment="!", debug=False, factory=False, 
        linesplit_rgx=r"\r*\n+", ignore_blank_lines=True, syntax='ios'):
        """
            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):
github GoSecure / Cisco2Checkpoint / lib / ciscoconfparse_patch.py View on Github external
models_asa.ASAIntfGlobal, \
                  models_asa.ASAHostnameLine, \
                  ASAAclLine, \
                  models_asa.ASACfgLine]
    for cls in classes:
        if cls.is_object_for(text):
            inst = cls(text=text, 
                comment_delimiter=comment_delimiter) # instance of the proper subclass
            return inst
    raise ValueError("Could not find an object for '%s'" % line)

##
##------------- Monkey Patching
## Temporary patch. Goal is to send a pull request to the project.
##
ccp.ConfigLineFactory = ConfigLineFactory
models_asa.ASAConfigList = ASAConfigList

##
##------------- New CiscoConfParse definition
## Reason: Have a good reference to ASAConfigList
##
class CiscoConfParse(ccp.CiscoConfParse):
    """Parses Cisco IOS configurations and answers queries about the configs"""

    def __init__(self, config="", comment="!", debug=False, factory=False, 
        linesplit_rgx=r"\r*\n+", ignore_blank_lines=True, syntax='ios'):
        """
            You will find a great class description in ccp.CiscoConfParse
        """

        # all IOSCfgLine object instances...