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

Allow childrens to have multiple parents #210

Open
chadell opened this issue Feb 27, 2023 · 1 comment
Open

Allow childrens to have multiple parents #210

chadell opened this issue Feb 27, 2023 · 1 comment
Labels
status: accepted This issue has been accepted by the maintainers team for implementation type: enhancement

Comments

@chadell
Copy link
Collaborator

chadell commented Feb 27, 2023

Environment

  • DiffSync version: 1.7.0

Proposed Functionality

children could have multiple parents to represent more real use cases.

Use Case

An ipaddress could belong to an interface but also to a bgppeer

@Kircheneer Kircheneer added status: accepted This issue has been accepted by the maintainers team for implementation type: major feature labels Mar 2, 2023
@Kircheneer
Copy link
Collaborator

Until we have this, here is a pattern you can use to deal with this.

class CustomDiff(Diff):
    # This order is significant to the order in which diffsync actions are performed.
    # Create/update operations happen in this exact order, delete operations in reverse.
    order = ["vpn", "role", "vlan", "prefix"]

    def get_children(self):
        deferred_children = []
        for model in self.order:
            for child in self.children[model].values():
                if child.action == DiffSyncActions.DELETE:
                    # Insert the deferred deletion actions in reverse order from the general model order as to resolve
                    # dependencies correctly.
                    deferred_children.insert(0, child)
                else:
                    yield child
        yield from deferred_children

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: accepted This issue has been accepted by the maintainers team for implementation type: enhancement
Projects
None yet
Development

No branches or pull requests

2 participants