Skip to content
Snippets Groups Projects
Commit ca13d19b authored by Erik Reid's avatar Erik Reid
Browse files

filter non-eth physical interfaces

parent b45f08ef
No related branches found
No related tags found
No related merge requests found
...@@ -4,6 +4,5 @@ ...@@ -4,6 +4,5 @@
# a migration for # a migration for
script_location = migrations script_location = migrations
sqlalchemy.url = sqlite:////absolute/path/to/foo.db sqlalchemy.url = sqlite:////absolute/path/to/foo.db
sqlalchemy.url = sqlite:////Users/reid/workspace/nat/resource-management/resource_management/foo.db
# or here is an example of a mysql dsn # or here is an example of a mysql dsn
# sqlalchemy.url = mysql://dummy:dummy-pass@localhost/resources_db_name # sqlalchemy.url = mysql://dummy:dummy-pass@localhost/resources_db_name
...@@ -77,6 +77,12 @@ LINE_CARDS_LIST_SCHEMA = { ...@@ -77,6 +77,12 @@ LINE_CARDS_LIST_SCHEMA = {
} }
def _is_physical_ifc_name(name):
# TODO: is there a better way to filter out lags? other interfaces?
# cf. https://github.com/Juniper/py-junos-eznc/blob/master/lib/jnpr/junos/op/ethport.yml#L6 # noqa: E501
return re.match('[fgxe][et]-', name) is not None
def _slot_number(name): def _slot_number(name):
""" """
parses names like 'FPC 2', 'PIC 17' and returns parses names like 'FPC 2', 'PIC 17' and returns
...@@ -371,6 +377,8 @@ def load_logical_interfaces(router: 'jnpr.junos.Device'): ...@@ -371,6 +377,8 @@ def load_logical_interfaces(router: 'jnpr.junos.Device'):
interfaces = {} interfaces = {}
for lu in LogicalInterfacesTable(router).get(): for lu in LogicalInterfacesTable(router).get():
assert lu.logical.startswith(lu.physical) # sanity assert lu.logical.startswith(lu.physical) # sanity
if not _is_physical_ifc_name(lu.physical):
continue
interfaces.setdefault(lu.physical, set()).add(lu.logical) interfaces.setdefault(lu.physical, set()).add(lu.logical)
return interfaces return interfaces
...@@ -416,6 +424,8 @@ def load_installed_ethernet_ports(router: 'jnpr.junos.Device'): ...@@ -416,6 +424,8 @@ def load_installed_ethernet_ports(router: 'jnpr.junos.Device'):
interfaces = {} interfaces = {}
for ifc in PhysicalInterfacesTable(router).get(): for ifc in PhysicalInterfacesTable(router).get():
if not _is_physical_ifc_name(ifc.interface):
continue
interfaces[ifc.interface] = { interfaces[ifc.interface] = {
'admin': ifc.admin == 'up', 'admin': ifc.admin == 'up',
'oper': ifc.admin == 'up' 'oper': ifc.admin == 'up'
......
...@@ -94,7 +94,7 @@ def test_physical_no_lag(mocked_router): ...@@ -94,7 +94,7 @@ def test_physical_no_lag(mocked_router):
ssh_config=ssh) as dev: ssh_config=ssh) as dev:
physical = juniper.load_installed_ethernet_ports(dev) physical = juniper.load_installed_ethernet_ports(dev)
assert all(p['name'].startswith('ae') is False for p in physical) assert all(p.startswith('ae') is False for p in physical.keys())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment