How to use the ciscoconfparse.ccp_util.CiscoRange 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 / tests / test_Ccp_Util.py View on Github external
def test_CiscoRange_contanis():
    assert 'Ethernet1/2' in CiscoRange('Ethernet1/1-20')
github mpenning / ciscoconfparse / tests / test_Ccp_Util.py View on Github external
def test_CiscoRange_11():
    """Basic interface slot range test"""
    result_correct = ['interface Eth2/1/1', 'interface Eth2/1/2', 'interface Eth2/1/3', 'interface Eth2/1/4', 'interface Eth2/1/5']
    assert CiscoRange('interface Eth2/1/1-3,4,5').as_list==result_correct
github mpenning / ciscoconfparse / tests / test_Ccp_Util.py View on Github external
def test_CiscoRange_10():
    """Basic slot range test"""
    result_correct = ['2/1/1', '2/1/2', '2/1/3', '2/1/4', '2/1/5']
    assert CiscoRange('2/1/1,2,3-5').as_list==result_correct
github mpenning / ciscoconfparse / tests / test_Ccp_Util.py View on Github external
def test_CiscoRange_13():
    """Basic interface slot range test"""
    result_correct = ['interface Eth2/1/1', 'interface Eth2/1/2', 'interface Eth2/1/3', 'interface Eth2/1/4', 'interface Eth2/1/5']
    assert CiscoRange('interface Eth2/1/1,2,3-5').as_list==result_correct
github mpenning / ciscoconfparse / tests / test_Ccp_Util.py View on Github external
def test_CiscoRange_03():
    """Basic vlan range test"""
    result_correct = ['1', '2', '3', '4', '5']
    assert CiscoRange('1,2-4,5').as_list==result_correct
github mpenning / ciscoconfparse / tests / test_Ccp_Util.py View on Github external
def test_CiscoRange_01():
    """Basic vlan range test"""
    result_correct = ['1']
    assert CiscoRange('1').as_list==result_correct
github mpenning / ciscoconfparse / ciscoconfparse / models_cisco.py View on Github external
'except_str': exc_str,
                'remove_str': rem_str,
            }

            ## Analyze each vdict in sequence and apply to retval sequentially
            for key, val in vdict.items():
                if val!='_nomatch_':
                    ## absolute in the key overrides previous values
                    if 'absolute' in key:
                        if val.lower()=='all':
                            retval = CiscoRange('1-{0}'.format(MAX_VLAN), 
                                result_type=int)
                        elif val.lower()=='none':
                            retval = CiscoRange(result_type=int)
                        else:
                            retval = CiscoRange(val, result_type=int)
                    elif 'add' in key:
                        retval.append(val)
                    elif 'except' in key:
                        retval = CiscoRange('1-{0}'.format(MAX_VLAN), 
                            result_type=int)
                        retval.remove(val)
                    elif 'remove' in key:
                        retval.remove(val)

        return retval
github mpenning / ciscoconfparse / ciscoconfparse / models_nxos.py View on Github external
'except_str': exc_str,
                'remove_str': rem_str,
            }

            ## Analyze each vdict in sequence and apply to retval sequentially
            for key, val in vdict.items():
                if val!='_nomatch_':
                    ## absolute in the key overrides previous values
                    if 'absolute' in key:
                        if val.lower()=='all':
                            retval = CiscoRange('1-{0}'.format(MAX_VLAN),
                                result_type=int)
                        elif val.lower()=='none':
                            retval = CiscoRange(result_type=int)
                        else:
                            retval = CiscoRange(val, result_type=int)
                    elif 'add' in key:
                        retval.append(val)
                    elif 'except' in key:
                        retval = CiscoRange('1-{0}'.format(MAX_VLAN),
                            result_type=int)
                        retval.remove(val)
                    elif 'remove' in key:
                        retval.remove(val)

        return retval
github mpenning / ciscoconfparse / ciscoconfparse / models_nxos.py View on Github external
def trunk_vlans_allowed(self):
        """Return a CiscoRange() with the list of allowed vlan numbers (as int).  Return 0 if the port isn't a switchport in trunk mode"""

        # The default values...
        if self.is_switchport and not self.has_manual_switch_access:
            retval = CiscoRange('1-{0}'.format(MAX_VLAN), result_type=int)
        else:
            return 0

        ## Iterate over switchport trunk statements
        for obj in self.children:

            ## For every child object, check whether the vlan list is modified
            abs_str = obj.re_match_typed(
                '^\s+switchport\s+trunk\s+allowed\s+vlan\s(all|none|\d.*?)$',
                default='_nomatch_', result_type=str).lower()
            add_str = obj.re_match_typed(
                '^\s+switchport\s+trunk\s+allowed\s+vlan\s+add\s+(\d.*?)$',
                default='_nomatch_', result_type=str).lower()
            exc_str = obj.re_match_typed(
                '^\s+switchport\s+trunk\s+allowed\s+vlan\s+except\s+(\d.*?)$',
                default='_nomatch_', result_type=str).lower()
github mpenning / ciscoconfparse / ciscoconfparse / models_cisco.py View on Github external
'absolute_str': abs_str,
                'add_str': add_str,
                'except_str': exc_str,
                'remove_str': rem_str,
            }

            ## Analyze each vdict in sequence and apply to retval sequentially
            for key, val in vdict.items():
                if val!='_nomatch_':
                    ## absolute in the key overrides previous values
                    if 'absolute' in key:
                        if val.lower()=='all':
                            retval = CiscoRange('1-{0}'.format(MAX_VLAN), 
                                result_type=int)
                        elif val.lower()=='none':
                            retval = CiscoRange(result_type=int)
                        else:
                            retval = CiscoRange(val, result_type=int)
                    elif 'add' in key:
                        retval.append(val)
                    elif 'except' in key:
                        retval = CiscoRange('1-{0}'.format(MAX_VLAN), 
                            result_type=int)
                        retval.remove(val)
                    elif 'remove' in key:
                        retval.remove(val)

        return retval