networktocode/diffsync

Allow childrens to have multiple parents

chadell opened this issue · 1 comments

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

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