Skip to content

Commit

Permalink
rename my_ prefixed variables
Browse files Browse the repository at this point in the history
  • Loading branch information
loulecrivain committed Feb 27, 2025
1 parent 07cedce commit 11e8d32
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
14 changes: 7 additions & 7 deletions cosmo/routerl2vpnvisitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ def _(self, o: L2VPNType):


class RouterL2VPNExporterVisitor(AbstractRouterExporterVisitor):
def __init__(self, *args, loopbacks_by_device: dict[str, CosmoLoopbackType], my_asn: int, **kwargs):
def __init__(self, *args, loopbacks_by_device: dict[str, CosmoLoopbackType], asn: int, **kwargs):
super().__init__(*args, **kwargs)
self.loopbacks_by_device = loopbacks_by_device
self.my_asn = my_asn
self.asn = asn

@singledispatchmethod
def accept(self, o):
Expand All @@ -58,9 +58,9 @@ def getAssociatedEncapType(o: InterfaceType | VLANType) -> str|None:
elif isinstance(o, InterfaceType) and (len(o.getTaggedVLANS()) or o.getUntaggedVLAN()):
is_eligible_for_vlan_encap = True
elif isinstance(o, InterfaceType) and not (len(o.getTaggedVLANS()) or o.getUntaggedVLAN()):
my_root_name = o.getSubInterfaceParentInterfaceName() if o.isSubInterface() else o.getName()
root_name = o.getSubInterfaceParentInterfaceName() if o.isSubInterface() else o.getName()
sub_units = list(filter( # costlier check it is then
lambda i: i.getName().startswith(my_root_name) and i.isSubInterface(),
lambda i: i.getName().startswith(root_name) and i.isSubInterface(),
o.getParent(DeviceType).getInterfaces()
))
if len(sub_units) == 1: # we can use ethernet ccc encap only when there's 1 sub interface
Expand Down Expand Up @@ -117,7 +117,7 @@ def processL2vpnMplsEvpnTerminationInterface(self, o: InterfaceType):
"protocols": {
"evpn": {},
},
"route_distinguisher": f"{self.my_asn}:{str(parent_l2vpn.getIdentifier())}",
"route_distinguisher": f"{self.asn}:{str(parent_l2vpn.getIdentifier())}",
"vrf_target": f"target:1:{str(parent_l2vpn.getIdentifier())}",
}
}
Expand All @@ -144,7 +144,7 @@ def processL2vpnVpwsTerminationInterface(self, o: InterfaceType):
"interfaces": [ o.getName() ],
"description": f"VPWS: {parent_l2vpn.getName().replace('WAN: VS_', '')}",
"instance_type": "evpn-vpws",
"route-distinguisher": f"{self.my_asn}:{str(parent_l2vpn.getIdentifier())}",
"route-distinguisher": f"{self.asn}:{str(parent_l2vpn.getIdentifier())}",
"vrf-target": f"target:1:{str(parent_l2vpn.getIdentifier())}",
"protocols": {
"evpn": {
Expand Down Expand Up @@ -175,7 +175,7 @@ def spitNameForInterfaces(int_or_vlan: InterfaceType|VLANType):
parent_l2vpn.getName().replace("WAN: ", ""): {
"description": f"Virtual Switch {parent_l2vpn.getName().replace('WAN: VS_', '')}",
"instance-type": "virtual-switch",
"route_distinguisher": f"{self.my_asn}:{str(parent_l2vpn.getIdentifier())}",
"route_distinguisher": f"{self.asn}:{str(parent_l2vpn.getIdentifier())}",
"vrf_target": f"target:1:{str(parent_l2vpn.getIdentifier())}",
"protocols": {
"evpn": {
Expand Down
16 changes: 8 additions & 8 deletions cosmo/routervisitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@


class RouterDeviceExporterVisitor(AbstractRouterExporterVisitor):
def __init__(self, loopbacks_by_device: dict[str, CosmoLoopbackType], my_asn: int, *args, **kwargs):
def __init__(self, loopbacks_by_device: dict[str, CosmoLoopbackType], asn: int, *args, **kwargs):
super().__init__(*args, **kwargs)
# Note: I have to use composition since singledispatchmethod does not work well with inheritance
self.my_l2vpn_exporter = RouterL2VPNExporterVisitor(loopbacks_by_device=loopbacks_by_device, my_asn=my_asn)
self.my_l2vpn_validator = RouterL2VPNValidatorVisitor()
self.my_bgpcpe_exporter = RouterBgpCpeExporterVisitor()
self.l2vpn_exporter = RouterL2VPNExporterVisitor(loopbacks_by_device=loopbacks_by_device, asn=asn)
self.l2vpn_validator = RouterL2VPNValidatorVisitor()
self.bgpcpe_exporter = RouterBgpCpeExporterVisitor()
self.loopbacks_by_device = loopbacks_by_device
self.allow_private_ips = False

Expand All @@ -36,7 +36,7 @@ def accept(self, o):

@accept.register
def _(self, o: L2VPNType):
return self.my_l2vpn_validator.accept(o)
return self.l2vpn_validator.accept(o)

@accept.register
def _(self, o: DeviceType):
Expand Down Expand Up @@ -233,7 +233,7 @@ def _(self, o: InterfaceType):
# guard: do not process VLAN interface info
return
if isinstance(o.getParent(), L2VPNTerminationType):
return self.my_l2vpn_exporter.accept(o)
return self.l2vpn_exporter.accept(o)
if o.isSubInterface():
return self.processSubInterface(o)
if o.isLagInterface():
Expand Down Expand Up @@ -343,7 +343,7 @@ def processUntaggedVLAN(self, o: VLANType):
@accept.register
def _(self, o: VLANType):
if isinstance(o.getParent(), L2VPNTerminationType):
return self.my_l2vpn_exporter.accept(o)
return self.l2vpn_exporter.accept(o)
parent_interface = o.getParent(InterfaceType)
if (
parent_interface and o == parent_interface.getUntaggedVLAN()
Expand Down Expand Up @@ -579,7 +579,7 @@ def _(self, o: TagType):
return self.processBgpUnnumberedTag(o)
case "bgp":
if o.getTagValue() == "cpe":
return self.my_bgpcpe_exporter.accept(o)
return self.bgpcpe_exporter.accept(o)
else:
warnings.warn(f"unkown bgp tag {o.getTagValue()}")
case _:
Expand Down
10 changes: 5 additions & 5 deletions cosmo/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def serialize(self):
device_stub = {}
# like always_merger but with append_unique strategy
# for lists
my_merger = Merger(
merger = Merger(
[
(list, ["append_unique"]),
(dict, ["merge"]),
Expand All @@ -69,12 +69,12 @@ def serialize(self):
# breakpoint()
visitor = RouterDeviceExporterVisitor(
loopbacks_by_device={k: CosmoLoopbackType(v) for k, v in self.loopbacks.items()},
my_asn=9136,
asn=9136,
)
for value in iter(DeviceType(self.device)):
new = visitor.accept(value)
if new:
device_stub = my_merger.merge(device_stub, new)
device_stub = merger.merge(device_stub, new)
return deepsort(device_stub)


Expand All @@ -86,7 +86,7 @@ def serialize(self):
device_stub = {}
# like always_merger but with append_unique strategy
# for lists
my_merger = Merger(
merger = Merger(
[
(list, ["append_unique"]),
(dict, ["merge"]),
Expand All @@ -98,5 +98,5 @@ def serialize(self):
for value in iter(DeviceType(self.device)):
new = SwitchDeviceExporterVisitor().accept(value)
if new:
device_stub = my_merger.merge(device_stub, new)
device_stub = merger.merge(device_stub, new)
return deepsort(device_stub)
10 changes: 5 additions & 5 deletions cosmo/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,17 +317,17 @@ def getRawType(self) -> str:

def getAssociatedType(self):
# TODO: move me in manufacturer strategy?
my_type = self.getRawType().lower()
raw_type_l = self.getRawType().lower()
authorized_types = [ "lag", "loopback", "virtual", "access" ]
access = any([tag.getTagName() == "access" for tag in self.getTags()])
if access and "lag" == my_type:
if access and "lag" == raw_type_l:
return "lag-access"
elif access:
return "access"
elif "base" in my_type:
elif "base" in raw_type_l:
return "physical"
elif my_type in authorized_types:
return my_type
elif raw_type_l in authorized_types:
return raw_type_l

def isLoopback(self):
return self.getAssociatedType() == "loopback"
Expand Down

0 comments on commit 11e8d32

Please sign in to comment.