-
-
Notifications
You must be signed in to change notification settings - Fork 227
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
Group membership filter #149
Conversation
Pull Request Test Coverage Report for Build 684
💛 - Coveralls |
So my only concern with this method is that we are using a "special keyword" as an argument and that might mask a legit attribute in someone's inventory. We do that already with So the
What I was thinking is adding to the
Alternatively we could implement a more generic approach and have some syntax for allowing "queries" (we could get inspiration from django for this). For instance:
That advantage of this method is that it is a generic solution that will work for user data as well and that could be expanded to check dictionary values. For instance:
Thoughts? |
I had the same thought about introducing more reserved keys. Another one is what would be default filtering methods. If I want to have all hosts that are a member of group A but not of B. Is that something that should be possible by default, or do we require a user-defined function for that? An option could be that someone would have to run several filters and that you can also negate matches.
I think that the examples from Django might be confusing for people... |
But it's the only way of fixing it in a generic way for nested structures. It also has the advantage you can combine them:
And you could even easily add a
I think it's not as complex to be honest and with proper documentation and plenty of examples it should be easy. We could also add allow the + operator between nornir objects to implement the "OR" functionality:
|
I vote for the Django pattern. I like that better and think it is simpler/easier to understand than the other solution. The fundamental question for the Django pattern is are the enough filtering use cases to justify this or is group_membership just a special one off. I am pretty sure there are enough use cases to justify it (given what @dbarrosop demonstrated and also Patricks multiple group operation case--member group A, but not group B). |
I think there is, mostly because we don't control user's data. For instance, when I implemented nsot plugin I had to do this: https://github.com/nornir-automation/nornir/blob/develop/nornir/plugins/inventory/nsot.py#L73 So I could use nsot data to filter the objects. I had to do something similar at $dayjob because my data there is also heavily nested. |
Closing as we will be using a different, more generic solution probably Django QuerySet style queries. |
Here is the code I used for initial testing against the changes specified in the PR.
The hosts.yaml entry intentionally has multiple groups so you can't just do:
I think this is probably a common enough pattern (host belonging to multiple groups) and wanting to filter by group that we probably should have some pretty simple solution for it.