Skip to content
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

IPAM Namespace Data Migrations #3759

Conversation

jathanism
Copy link
Contributor

@jathanism jathanism commented May 16, 2023

Closes: DNE

What's Changed

Note: Current model changes are there to be able to debug and work with the data in its v1.x form. As data migrations are completed, model changes will continue to progress. Same with the data migrations where certain operations have been commented out. This is absolutely not fit for consumption...yet.

Done

  • VRF
    • VRFs with enforce_unique=True moved to their own "VRF" namespaces
    • VRFs with enforce_unique=False moved to a Cleanup namespace
  • Prefix
    • Duplicate prefixes from Global namespace moved to Cleanup namespaces
  • IPAddress
    • Parenting with a discovered existing parent Prefix
    • Parenting with a newly-created containing prefixes for orphaned IPAddress (where no parent could be determined)

To Do

  • Mapping an IPAddress to a parent Prefix with matching Tenant if possible
  • Moving an IPAddress assigned VRF to its assigned Interface IFF Parent VRF is the same or null
  • Status messages for Prefix parenting (if we think it's useful)
  • Making sure the descriptions for the objects created by the migrations are clear
  • Bolting on the uniqueness constraints at the database and removing the old fields
  • Rename the migration files to make more sense
  • Akin to trace_paths, a mgmt command that will iterate each Prefix and call save to trigger reparenting. This should be a post-upgrade step as well.

TODO

  • Explanation of Change(s)
  • Added change log fragment(s) (for more information see the documentation)
  • Attached Screenshots, Payload Example
  • Documentation Updates (when adding/changing features)
  • Example Plugin Updates (when adding/changing features)
  • Outline Remaining Work, Constraints from Design

@jathanism jathanism marked this pull request as draft May 16, 2023 23:03
nautobot/ipam/migrations/0029_ipam__namespaces.py Outdated Show resolved Hide resolved
nautobot/ipam/models.py Outdated Show resolved Hide resolved
nautobot/ipam/utils/migrations.py Outdated Show resolved Hide resolved
nautobot/ipam/utils/migrations.py Outdated Show resolved Hide resolved
nautobot/ipam/utils/migrations.py Outdated Show resolved Hide resolved
nautobot/ipam/utils/migrations.py Outdated Show resolved Hide resolved
nautobot/ipam/utils/migrations.py Outdated Show resolved Hide resolved
@jathanism jathanism force-pushed the u/jathanism-namespace-data-migrations branch from 507af41 to e92f4cb Compare May 19, 2023 23:46
nautobot/ipam/models.py Outdated Show resolved Hide resolved
nautobot/ipam/models.py Outdated Show resolved Hide resolved
nautobot/ipam/utils/migrations.py Outdated Show resolved Hide resolved
vrf.prefixes.update(namespace=vrf.namespace)
print(f" VRF {vrf.name!r} migrated to Namespace {vrf.namespace.name!r}")

# Case 00: Unique fields vs. Namespaces (name/rd) move to a Cleanup Namespace.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Case 1?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IPAM Namespace data migrations progress report.

Need to move VRF from IP Address to Interface: Done.

Move duplicate Prefixes from Global Namespace to Cleanup Namespaces.

VMInterface migrations to go along with Interface.

- Had to augment `VRFDeviceAssignment` to take either `device` or `virtual_machine` and relax the constraints to allow the fields to be nullable, asserting their correctnext in the `clean()`  method
- Made black and flake8 happy.

Implemented migrations for parenting IPAddresses to Prefixes in the correct Namespace.

Make migrations a little prettier, and remove dead code.

Re-remove the `Prefix.save()` uniqueness checks for `VRF.enforce_unique`

Make the IPAddress migration code a little easier to read.

Revised parent-finding algorithm to have affinity for Tenants

- Additionally the Namepaces lookup will now always start with "Global" NS to try to keep as many objects in there as reasonably possible.
- If an IP has a tenant, it'll try to filter possible ancestors by it.
@jathanism jathanism force-pushed the u/jathanism-namespace-data-migrations branch from 3f3e23a to 4804e90 Compare May 23, 2023 05:37
Copy link
Contributor

@glennmatthews glennmatthews left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fun times!

Comment on lines +364 to +367
# TODO(jathan): This might be flawed if an IPAddress has a prefix_length that excludes it from a
# parent that should otherwise contain it. If we encounter issues in the future for
# identifying closest parent prefixes, this might be a starting point.
"prefix_length__lte": cidr.prefixlen,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this comment still accurate/relevant? This is a method on PrefixQuerySet, not IPAddressQuerySet so it seems wrong to me?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's correct so long as we also continue to include broadcast, which we currently are. @gsnider2195 please keep me honest.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IPAddress should probably just be:

Prefix.objects.filter(network__lte=cidr.ip, broadcast__gte=cidr.ip)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, like we discussed for the data migrations, prefix_length needs to be lt for Prefixes, not lte

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, we decided that with the uniqueness constraints we should never have a matching prefix with the same prefix length?

nautobot/ipam/tables.py Outdated Show resolved Hide resolved
nautobot/ipam/models.py Outdated Show resolved Hide resolved
nautobot/ipam/models.py Show resolved Hide resolved
nautobot/ipam/utils/migrations.py Outdated Show resolved Hide resolved
nautobot/ipam/utils/migrations.py Outdated Show resolved Hide resolved
nautobot/ipam/utils/migrations.py Outdated Show resolved Hide resolved
nautobot/ipam/utils/migrations.py Outdated Show resolved Hide resolved
nautobot/ipam/utils/migrations.py Outdated Show resolved Hide resolved
gsnider2195 and others added 17 commits May 31, 2023 09:35
* Broadcast fixes

* PR Feedback
* Cleanup namespaces detail, related views

* Black

* Apply suggestions from code review

Co-authored-by: Gary Snider <75227981+gsnider2195@users.noreply.github.com>

---------

Co-authored-by: Gary Snider <75227981+gsnider2195@users.noreply.github.com>
…utobot/nautobot into u/jathanism-namespace-data-migrations
- Added/clarified docstrings to ALL functions
- Renamed functions for clarity
- Moved things around
- Removed lingering TODO comments
- Had an existential crisis
It is now: "Created by Nautobot 2.0 IPAM data migrations."
@jathanism jathanism changed the title [WIP] IPAM Namespace Data Migrations IPAM Namespace Data Migrations Jun 1, 2023
@jathanism jathanism marked this pull request as ready for review June 1, 2023 17:46
@gsnider2195 gsnider2195 merged commit 35c59e8 into prototype/jathanism-3337-ipam-namespace Jun 1, 2023
19 checks passed
@gsnider2195 gsnider2195 deleted the u/jathanism-namespace-data-migrations branch June 1, 2023 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants