-
Notifications
You must be signed in to change notification settings - Fork 0
Refactoring: transform serializer to visitor, suppress state, isolate logic #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
129 commits
Select commit
Hold shift + click to select a range
3918b4a
refactoring WIP draft ideas
loulecrivain 6dddb34
add object-transformation of netbox data
loulecrivain 43482d5
remove breakpoint
loulecrivain 01ac195
add some properties
loulecrivain 73b6816
more sophisticated getters for special interfaces
loulecrivain 4b7e2b6
remove dead code
loulecrivain fa32396
add the possibility to get item parent in composite tree
loulecrivain 85f8908
add __typename in graphql query
loulecrivain 2670f43
remove the need for deepcopy
loulecrivain f2b2c2b
passing 1st test
loulecrivain fe39631
make AbstractNetboxType iterable
loulecrivain 4246668
start passing tests again and building upon new visitor/iterator pattern
loulecrivain 8811a58
pass mgmt interface test
loulecrivain 7bced48
pass LAG test
loulecrivain 022b181
pass speed test
loulecrivain f50d0dc
pass FEC test
loulecrivain db22a6c
refactor tag processing
loulecrivain 64a03f3
delete unreachable code
loulecrivain 2f2889b
return device with sorted lists
loulecrivain e216623
small fix
loulecrivain a37da61
add manufacturer strategies
loulecrivain a81a2e8
speed up manufacturer class lookup
loulecrivain 38254d3
fix missing info on lag
loulecrivain 3f30453
fix missing description for LAG members
loulecrivain cf0d4b7
fix tagged/untagged VLANs corner case
loulecrivain 42b1107
take into account cases where device might not have manufacturer info
loulecrivain 2861b64
fix overwritten descriptions for LAG members
loulecrivain 7582547
move switch visitor to dedicated file
loulecrivain 928342d
use empty router visitor
loulecrivain 0944a07
add global state info into router visitor
loulecrivain 45cb87d
pass 1st router test
loulecrivain 9e9fef9
pass 2nd test
loulecrivain 5496925
allow for more flexibility regarding sub interface / interface treatment
loulecrivain 423f0ec
pass local_l2x test
loulecrivain 5c42ba8
fix failing integration tests
loulecrivain ded9f81
pass lag test
loulecrivain 69bac05
pass fec test
loulecrivain fee620d
pass router ips test
loulecrivain 025d21b
pass router vrf rib test
loulecrivain 357bd0f
pass mpls evpn test
loulecrivain 22a81ca
pass vpws test
loulecrivain 6ab386a
pass l3vpn test
loulecrivain cf712ae
pass bgp cpe test
loulecrivain 4e5cfe6
pass policer test
loulecrivain 4a101e3
fix inconsistent object cache hashing
loulecrivain f4d68ed
put all dunder methods together
loulecrivain d36d916
improve bgp cpe processing code clarity
loulecrivain 8be700d
fix undue warnings
loulecrivain a631f61
yeet objcache to improve performance
loulecrivain faacb41
add guard for processing l2vpn terminations
loulecrivain 95aa9ae
extract bgp cpe processing
loulecrivain 7acf4db
extracting l2vpn validation
loulecrivain 9952a56
extract l2vpn processing
loulecrivain 4035893
make composition pattern clearer
loulecrivain c1b0104
add reverse path filtering
loulecrivain 1ad0204
fixup! add reverse path filtering
loulecrivain 684f580
add ipv6 router advertisement
loulecrivain 66969e7
use match/case statement instead
loulecrivain 720417b
add core tag processing
loulecrivain 0516aec
add dhcp tag processing
loulecrivain d16c6b5
add unnumbered tag processing
loulecrivain 769055a
add ethernet-ccc encap
loulecrivain c90e1fc
add specific management interface ip address processing
loulecrivain 8444233
add vxlan termination processing
loulecrivain 442751c
fixup! use match/case statement instead
loulecrivain b404803
fix eq dunder for AbstractNetboxType
loulecrivain ad90eaf
register sonderlocke tag as known
loulecrivain 51dd7ad
add missing device properties
loulecrivain 9f1ba51
fix enabled/disabled interface logic
loulecrivain 98cc1be
fix horrible bug where child interfaces were wrongly processed
loulecrivain cd0f2fa
make description and mtu optional
loulecrivain 990240c
make arp policer property completely optional
loulecrivain a89b934
fix ethernet-ccc encapsulation
loulecrivain abd74aa
fix missing properties for sub interfaces
loulecrivain 7bf938f
fix test for sub interfaces
loulecrivain d1a7d26
output type only for root interfaces, not sub interfaces
loulecrivain 51fb9ce
fix missing specific descriptions linked to some tags
loulecrivain 107599c
fix condition for using ethernet-ccc encap
loulecrivain 4f2412e
fix missing check for property
loulecrivain 414a67d
fix test data missing __typename for tag
loulecrivain 84c5167
add outer_tag feature
loulecrivain 1f31afa
serial should be empty string instead of null
loulecrivain 93b5d5e
fix crash, fix "unkown" tag
loulecrivain a88eb0a
add bmc to management interfaces for rtbrick
loulecrivain 1791d25
fix missing feature process access tag
loulecrivain af23c2d
fix dhcp tag processing
loulecrivain c695919
fix interface associated type
loulecrivain 682ef02
fix and simplify lag guard
loulecrivain 73d8e09
fix missing mac address feature
loulecrivain 00436bb
add some documentation on why so many getters
loulecrivain 2036502
fix l2vpn termination test
loulecrivain 7a81bda
remove unneeded code
loulecrivain c26af01
fix loopback addr restrictions
loulecrivain a1750cc
forbid configuring IPs directly on interfaces
loulecrivain 3e35b88
rename my_ prefixed variables
loulecrivain b8719a6
simplify logic
loulecrivain a994bd4
add documentation
loulecrivain f1c86d7
simplify getters
loulecrivain 0d3f7ad
add doc
loulecrivain 7952de9
fix error message
loulecrivain c86b26c
simplify default route for mgmt interface
loulecrivain aebf531
fix error message
loulecrivain 035c2e5
drop vrf_list
loulecrivain 49e5f6e
add warning for misconfigured outer_tag
loulecrivain 21ec23f
fix l2vpn terminations check
loulecrivain d65f59c
fix misnomer
loulecrivain 1a3d4f4
delete unneeded else
loulecrivain 9b5238f
l2vpn helper types
loulecrivain bf7d299
add encapsulation traits
loulecrivain 8e99904
finish l2vpn type helpers
loulecrivain 3621508
accept vlan and interface for mpls evpn l2vpn
loulecrivain 195bb5b
format
loulecrivain 2b7638b
fix test
loulecrivain ad07d39
re-add forgotten guard
loulecrivain bed5015
fix minimal required terminations number for any2any type
loulecrivain 1e9ee91
enhance error messages
loulecrivain b1f292c
fix encap_type not optional
loulecrivain 8865979
remove unneeded / buggy method
loulecrivain 1aefadd
fix guard which was always false
loulecrivain 61f2f74
fix VLANType L2VPN processing
loulecrivain b671485
add guard: only sub-interfaces must be processed for VRFs
loulecrivain 69dbbf0
fix: mac addresses should only exist on sub interfaces
loulecrivain 3b5a4a2
fix omitted native_vlan field case
loulecrivain b6dc863
cleanup dead code
loulecrivain aeaf54c
fix casing
loulecrivain 7e89a73
documentation
loulecrivain 72f6146
naming
loulecrivain 644448b
use typevar instead of repeating
loulecrivain 1496a4a
naming
loulecrivain File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from abc import ABC | ||
|
||
from cosmo.types import CosmoLoopbackType | ||
from cosmo.visitors import AbstractNoopNetboxTypesVisitor | ||
|
||
|
||
class AbstractRouterExporterVisitor(AbstractNoopNetboxTypesVisitor, ABC): | ||
_vrf_key = "routing_instances" | ||
_interfaces_key = "interfaces" | ||
_mgmt_vrf_name = "MGMT-ROUTING-INSTANCE" | ||
_l2circuits_key = "l2circuits" | ||
_allowed_core_mtus = [9216, 9600, 9230, 9586, 9116] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,30 @@ | ||
import abc | ||
|
||
class AbstractRecoverableError(Exception, abc.ABC): | ||
pass | ||
|
||
|
||
class DeviceSerializationError(AbstractRecoverableError): | ||
pass | ||
|
||
|
||
class InterfaceSerializationError(AbstractRecoverableError): | ||
pass | ||
|
||
|
||
# next() can raise StopIteration, so that's why I use this function | ||
def head(l): | ||
return None if not l else l[0] | ||
|
||
def deepsort(e): | ||
if isinstance(e, list): | ||
return sorted(deepsort(v) for v in e) | ||
elif isinstance(e, dict): | ||
return {k: deepsort(v) for k, v in e.items()} | ||
return e | ||
|
||
|
||
def without_keys(d, keys) -> dict: | ||
if type(keys) != list: | ||
keys = [keys] | ||
return {k: v for k,v in d.items() if k not in keys} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from functools import singledispatchmethod | ||
|
||
from cosmo.types import IPAddressType, DeviceType | ||
from cosmo.visitors import AbstractNoopNetboxTypesVisitor | ||
|
||
|
||
class CpeRouterExporterVisitor(AbstractNoopNetboxTypesVisitor): | ||
""" | ||
This visitor creates a list of networks which are exported from the router | ||
via unnumbered bgp. We allow all configured IP networks on a CPE to be | ||
exported. By definition the primary IP is our management IP and this IP | ||
should not be allowed to be exported via BGP from the router. | ||
""" | ||
|
||
@singledispatchmethod | ||
def accept(self, o): | ||
return super().accept(o) | ||
|
||
@accept.register | ||
def _(self, o: IPAddressType): | ||
primary_ip4 = o.getParent(DeviceType)["primary_ip4"] | ||
if primary_ip4 and primary_ip4.getIPAddress() == o.getIPAddress(): | ||
loulecrivain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return # skip | ||
ip_interface = o.getIPInterfaceObject() | ||
return type(ip_interface), ip_interface.network.with_prefixlen |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.