diff --git a/resource_management/alembic.ini b/resource_management/alembic.ini index 0aad7a6e5e6cd079ffb64a6c68f290e6dcec4973..22d9b90d7b87f658aeb5b38a234376d320a13e4c 100644 --- a/resource_management/alembic.ini +++ b/resource_management/alembic.ini @@ -4,6 +4,5 @@ # a migration for script_location = migrations 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 # sqlalchemy.url = mysql://dummy:dummy-pass@localhost/resources_db_name diff --git a/resource_management/juniper.py b/resource_management/juniper.py index 4c3eb4dc5f0e277b303d6b382b6d153cdb33a511..6eba0d71813b55c80d650e550e12ddcc31310184 100644 --- a/resource_management/juniper.py +++ b/resource_management/juniper.py @@ -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): """ parses names like 'FPC 2', 'PIC 17' and returns @@ -371,6 +377,8 @@ def load_logical_interfaces(router: 'jnpr.junos.Device'): interfaces = {} for lu in LogicalInterfacesTable(router).get(): assert lu.logical.startswith(lu.physical) # sanity + if not _is_physical_ifc_name(lu.physical): + continue interfaces.setdefault(lu.physical, set()).add(lu.logical) return interfaces @@ -416,6 +424,8 @@ def load_installed_ethernet_ports(router: 'jnpr.junos.Device'): interfaces = {} for ifc in PhysicalInterfacesTable(router).get(): + if not _is_physical_ifc_name(ifc.interface): + continue interfaces[ifc.interface] = { 'admin': ifc.admin == 'up', 'oper': ifc.admin == 'up' diff --git a/test/test_parse_router.py b/test/test_parse_router.py index dfe39da79fb07431852d95bd9a5f2ab472ae7e28..1d0fb0eb985c46cf7cccebbc46697259b5074a20 100644 --- a/test/test_parse_router.py +++ b/test/test_parse_router.py @@ -94,7 +94,7 @@ def test_physical_no_lag(mocked_router): ssh_config=ssh) as 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())