How to use the ciscoconfparse.models_asa.ASACfgLine 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 / models_asa.py View on Github external
def __init__(self, *args, **kwargs):
        """Accept an ASA line number and initialize family relationship
        attributes"""
        super(ASACfgLine, self).__init__(*args, **kwargs)
github mpenning / ciscoconfparse / ciscoconfparse / models_asa.py View on Github external
(?:\s+
    (?Plog)
    (?:\s+(?P{1}))?
    (?:\s+interval\s+(?P\d+))?
  )?
  (?:\s+(?Pdisable))?
  (?:
    (?:\s+(?Pinactive))
   |(?:\s+time-range\s+(?P\S+))
  )?
  )
)                                                   # Close non-capture parens
""".format(_ACL_PROTOCOLS, _ACL_LOGLEVELS, _ACL_ICMP_PROTOCOLS)
_RE_ACLOBJECT = re.compile(_RE_ACLOBJECT_STR, re.VERBOSE)

class ASAAclLine(ASACfgLine):

    def __init__(self, *args, **kwargs):
        """Provide attributes on Cisco ASA Access-Lists"""
        super(ASAAclLine, self).__init__(*args, **kwargs)
        mm = _RE_ACLOBJECT.search(self.text)
        if not (mm is None):
            self._mm_results = mm.groupdict()   # All regex match results
        else:
            raise ValueError("[FATAL] models_asa cannot parse '{0}'".format(self.text))

    @classmethod
    def is_object_for(cls, line="", re=re):
        #if _RE_ACLOBJECT.search(line):
        if 'access-list ' in line[0:13].lower():
            return True
        return False
github mpenning / ciscoconfparse / ciscoconfparse / models_asa.py View on Github external
def __init__(self, *args, **kwargs):
        """Accept an ASA line number and initialize family relationship
        attributes"""
        super(ASAObjNetwork, self).__init__(*args, **kwargs)

    @classmethod
    def is_object_for(cls, line="", re=re):
        if 'object network ' in line[0:15].lower():
            return True
        return False

##
##-------------  ASA object service
##

class ASAObjService(ASACfgLine):

    def __init__(self, *args, **kwargs):
        """Accept an ASA line number and initialize family relationship
        attributes"""
        super(ASAObjService, self).__init__(*args, **kwargs)

    @classmethod
    def is_object_for(cls, line="", re=re):
        if 'object service ' in line[0:15].lower():
            return True
        return False

##
##-------------  ASA object-group network
##
_RE_NETOBJECT_STR = r"""(?:                         # Non-capturing parenthesis
github GoSecure / Cisco2Checkpoint / lib / ciscoconfparse_patch.py View on Github external
IOSAclLine, \
                  IOSIPAclLine, \
                  IOSIPAclChildLine, \
                  models_cisco.IOSCfgLine]
    elif syntax=='asa':
        classes = [ASAName, \
                  ASAObjNetwork, \
                  ASAObjService, \
                  ASAObjGroupNetwork, \
                  ASAObjGroupService, \
                  ASAObjGroupProtocol, \
                  models_asa.ASAIntfLine, \
                  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)
github mpenning / ciscoconfparse / ciscoconfparse / models_asa.py View on Github external
    @property
    def result_dict(self):
        mm_r = self._mm_results
        retval = dict()

        retval['name'] = self._mm_results['name']
        retval['addr'] = self._mm_results['addr']

        return retval

##
##-------------  ASA object network
##

class ASAObjNetwork(ASACfgLine):

    def __init__(self, *args, **kwargs):
        """Accept an ASA line number and initialize family relationship
        attributes"""
        super(ASAObjNetwork, self).__init__(*args, **kwargs)

    @classmethod
    def is_object_for(cls, line="", re=re):
        if 'object network ' in line[0:15].lower():
            return True
        return False

##
##-------------  ASA object service
##
github mpenning / ciscoconfparse / ciscoconfparse / models_asa.py View on Github external
if self.re_match(intf_regex):
            return True
        return False

##
##-------------  ASA Interface ABC
##

# Valid method name substitutions:
#    switchport -> switch
#    spanningtree -> stp
#    interfce -> intf
#    address -> addr
#    default -> def

class BaseASAIntfLine(ASACfgLine):
    def __init__(self, *args, **kwargs):
        super(BaseASAIntfLine, self).__init__(*args, **kwargs)
        self.ifindex = None    # Optional, for user use
        self.default_ipv4_addr_object = IPv4Obj('127.0.0.1/32', 
            strict=False)

    def __repr__(self):
        if not self.is_switchport:
            if self.ipv4_addr_object==self.default_ipv4_addr_object:
                addr = "No IPv4"
            else:
                addr = self.ipv4_addr_object
            return "<%s # %s '%s' info: '%s'>" % (self.classname, 
                self.linenum, self.name, addr)
        else:
            return "<%s # %s '%s' info: 'switchport'>" % (self.classname, self.linenum, self.name)
github mpenning / ciscoconfparse / ciscoconfparse / models_asa.py View on Github external
return retval

    @property
    def access_vlan(self):
        """Return an integer with the access vlan number.  Return 0, if the port has no explicit vlan configured."""
        retval = self.re_match_iter_typed(r'^\s*switchport\s+access\s+vlan\s+(\d+)$',
            result_type=int, default=0)
        return retval

##
##-------------  ASA name
##

_RE_NAMEOBJECT_STR = r'^name\s+(?P\d+\.\d+\.\d+\.\d+)\s(?P\S+)'
_RE_NAMEOBJECT = re.compile(_RE_NAMEOBJECT_STR, re.VERBOSE)
class ASAName(ASACfgLine):

    def __init__(self, *args, **kwargs):
        """Accept an ASA line number and initialize family relationship
        attributes"""
        super(ASAName, self).__init__(*args, **kwargs)
        mm = _RE_NAMEOBJECT.search(self.text)
        if not (mm is None):
            self._mm_results = mm.groupdict()   # All regex match results
        else:
            raise ValueError

        self.name = self._mm_results['name']
        self.addr = self._mm_results['addr']

    @classmethod
    def is_object_for(cls, line="", re=re):
github mpenning / ciscoconfparse / ciscoconfparse / models_asa.py View on Github external
def is_object_for(cls, line="", re=re):
        if 'object service ' in line[0:15].lower():
            return True
        return False

##
##-------------  ASA object-group network
##
_RE_NETOBJECT_STR = r"""(?:                         # Non-capturing parenthesis
 (^\s*network-object\s+host\s+(?P\S+))
|(^\s*network-object\s+(?P\S+)\s+(?P\d+\.\d+\.\d+\.\d+))
|(^\s*group-object\s+(?P\S+))
)                                                   # Close non-capture parens
"""
_RE_NETOBJECT = re.compile(_RE_NETOBJECT_STR, re.VERBOSE)
class ASAObjGroupNetwork(ASACfgLine):

    def __init__(self, *args, **kwargs):
        """Accept an ASA line number and initialize family relationship
        attributes"""
        super(ASAObjGroupNetwork, self).__init__(*args, **kwargs)

        self.name = self.re_match_typed(r'^object-group\s+network\s+(\S+)', group=1, 
            result_type=str)

    @classmethod
    def is_object_for(cls, line="", re=re):
        if 'object-group network ' in line[0:21].lower():
            return True
        return False

    @property