Conversation
|
Need to change terminology to "CIDR", even though it's not used a lot throughout the codebase. We usually use the field name |
network_cidr field to community serializer
terjekv
left a comment
There was a problem hiding this comment.
For lenient clients this should be a fairly safe and sound extension. One thing is that get_network_cidr() always dereferences obj.network so unless we use select_related("network"), list/nested responses will probably add one network lookup per serialized community? How often do we serlalize out the community?
6c0a7b4 to
f350f69
Compare
Only when fetching hosts, right? So this does affect endpoints that list hosts, because each host deserializes its community: Lines 328 to 335 in bbe8fa7 Potential regression for I'll look at this in late July/early August. |
This PR adds a new
network_cidrfield to serialized communities, which is the network CIDR of the network it is bound to. Improves API ergonomics.Rationale
In order to contact a community's endpoint, we are reliant on the network CIDR the community is bound to, i.e.
But what we receive from the API for a Community object currently is something like this:
{ "name": "mycommunity", "id": 1, "network": 123, // ... }Thus, consumers cannot construct the URL for the community based on just that object.
New field:
network_cidrBy adding the network CIDR to the serialized community, we can now construct the URL based exclusively on the community data without having to perform extra lookups or stitching together data from multiple objects:
{ "name": "mycommunity", "id": 1, "network": 123, "network_cidr": "10.0.0.1/24", // ... }Improves mreg-api ergonomics
Interacting with communities is awkward in mreg-api currently, because we need to manually fetch the network first, and pass that to every method that interacts with communities:
With this PR, the network CIDR is bound to the community object, and we can thus fetch the network as part of the community fetch operation (and , and we don't need pass around the network object: