Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions cosmo/clients/netbox_v4.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ def _fetch_data(self, kwargs, pool):
"""
query{
interface_list(filters: {
name: {starts_with: "lo"},
type: {exact:"loopback"}
name: {starts_with: "lo"}
}) {
__typename
name,
Expand Down
7 changes: 6 additions & 1 deletion cosmo/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,10 @@ def exe_with_feature(*args, **kwargs):


features = FeatureToggle(
{"interface-auto-descriptions": True, "new-bgp-cpe-group-naming": False}
{
"interface-auto-descriptions": True,
"new-bgp-cpe-group-naming": False,
"allow-private-ips-default-vrf": False,
"netbox-loopback-interface-type": False,
}
)
15 changes: 10 additions & 5 deletions cosmo/netbox_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
head,
CosmoOutputType,
)
from .features import features
from typing import (
Self,
Iterator,
Expand Down Expand Up @@ -675,11 +676,15 @@ def isLoopbackOrParentIsLoopback(self) -> bool:
)
return parent_interface.isLoopbackOrParentIsLoopback()
elif self.getName().startswith("lo"):
raise InterfaceSerializationError(
f"Interface {self.getName()} is named as a loopback but is not marked"
f"as such in the data source, please fix.",
on=self,
)
if self.getAssociatedType() != "loopback" and features.featureIsEnabled(
"netbox-loopback-interface-type"
):
raise InterfaceSerializationError(
f"Interface {self.getName()} is named as a loopback but is not marked"
f"as such in the data source, please fix.",
on=self,
)
return True
return False

def getIPAddresses(self) -> list[IPAddressType]:
Expand Down
5 changes: 4 additions & 1 deletion cosmo/routervisitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from cosmo.vrfhelper import TVRFHelpers
from cosmo.manufacturers import ManufacturerFactoryFromDevice
from cosmo.routerbgpcpevisitor import RouterBgpCpeExporterVisitor
from cosmo.features import features
from cosmo.routerl2vpnvisitor import (
RouterL2VPNValidatorVisitor,
RouterL2VPNExporterVisitor,
Expand Down Expand Up @@ -54,7 +55,9 @@ def __init__(
self.l2vpn_validator = RouterL2VPNValidatorVisitor(loopbacks=loopbacks, asn=asn)
self.bgpcpe_exporter = RouterBgpCpeExporterVisitor()
self.loopbacks = loopbacks
self.allow_private_ips = False
self.allow_private_ips = features.featureIsEnabled(
"allow-private-ips-default-vrf"
)
self.asn = asn

def getASN(self) -> int:
Expand Down
2 changes: 1 addition & 1 deletion cosmo/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def patchPostFunc(url, json, **kwargs):
retVal["interface_list"] = patchKwArgs.get(
"connected_devices_interface_list", []
)
elif "loopback" in q:
elif 'starts_with: "lo"' in q:
retVal["interface_list"] = patchKwArgs.get(
"loopback_interface_list", []
)
Expand Down