Add optional filtering of get_lcps() based on type of interface
This commit is contained in:
		@@ -13,11 +13,12 @@
 | 
			
		||||
#
 | 
			
		||||
import logging
 | 
			
		||||
 | 
			
		||||
def get_lcps(yaml):
 | 
			
		||||
    """ Returns a list of all LCPs configured in the system, or an empty list if there are none. """
 | 
			
		||||
def get_lcps(yaml, interfaces=True, loopbacks=True, bridgedomains=True):
 | 
			
		||||
    """ Returns a list of LCPs configured in the system. Optionally (de)select the different
 | 
			
		||||
    types of LCP. Return an empty list if there are none of the given type(s). """
 | 
			
		||||
 | 
			
		||||
    ret = []
 | 
			
		||||
    if 'interfaces' in yaml:
 | 
			
		||||
    if interfaces and 'interfaces' in yaml:
 | 
			
		||||
        for ifname, iface in yaml['interfaces'].items():
 | 
			
		||||
            if 'lcp' in iface:
 | 
			
		||||
                ret.append(iface['lcp'])
 | 
			
		||||
@@ -26,11 +27,11 @@ def get_lcps(yaml):
 | 
			
		||||
                    if 'lcp' in sub_iface:
 | 
			
		||||
                        ret.append(sub_iface['lcp'])
 | 
			
		||||
 | 
			
		||||
    if 'loopbacks' in yaml:
 | 
			
		||||
    if loopbacks and 'loopbacks' in yaml:
 | 
			
		||||
        for ifname, iface in yaml['loopbacks'].items():
 | 
			
		||||
            if 'lcp' in iface:
 | 
			
		||||
                ret.append(iface['lcp'])
 | 
			
		||||
    if 'bridgedomains' in yaml:
 | 
			
		||||
    if bridgedomains and 'bridgedomains' in yaml:
 | 
			
		||||
        for ifname, iface in yaml['bridgedomains'].items():
 | 
			
		||||
            if 'lcp' in iface:
 | 
			
		||||
                ret.append(iface['lcp'])
 | 
			
		||||
 
 | 
			
		||||
@@ -13,6 +13,9 @@ class TestLCPMethods(unittest.TestCase):
 | 
			
		||||
        self.assertIn("e1", lcps)
 | 
			
		||||
        self.assertIn("foo", lcps)
 | 
			
		||||
        self.assertIn("e2", lcps)
 | 
			
		||||
        loopback_lcps = lcp.get_lcps(self.cfg, interfaces=False, bridgedomains=False)
 | 
			
		||||
        self.assertIn("thrice", loopback_lcps)
 | 
			
		||||
        self.assertNotIn("e1", loopback_lcps)
 | 
			
		||||
 | 
			
		||||
    def test_lcp(self):
 | 
			
		||||
        self.assertTrue(lcp.is_unique(self.cfg, "e1"))
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user