-
-
Notifications
You must be signed in to change notification settings - Fork 32
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
Add filter_by_tags option #117
base: master
Are you sure you want to change the base?
Conversation
- This option allows the inventory instances to be filtered by one or more tags.
Using the existing get_filters() function wasn't possible since it only applies to the CS list API, as far as I can tell. Thus I think the only way is to check all instances the API returned for their tags. Suggestions for improvements are welcome. |
Normally I have been using tags to define groups, but I think this implementation adds value. Ultimately you would be able to use tags to cherry pick what goes into the inventory. |
However, there was another addition to the inventory plugin pending to implement because it was dependent on ACS api changes that were being implemented. That was re. the ability to group by VPC. see #106 @martialblog would you be confortable if we abuse this PR to include support for VPC groups? |
My guess is that adding support for groups by VPC would require the following addition too:
Unfortunately I need to update my ACS to the required version in order to fully test this works. but if you can, I appreciate. |
@rvalle Thanks for the feedback. Cherry picking the inventory was the use case that I had in front of me. I can add the instance.vpc in a Commit, not sure if I be able to test it anytime soon though. But seems like a minor change |
Ok, I just reviewed the VPC implementation in ACS and this is actually per NIC. |
Have you tried this route? The current implementation builds the filter in the query to ACS, and there is the possibility to add a filter do deal with tags. Did you notice? https://cloudstack.apache.org/api/apidocs-4.17/apis/listVirtualMachines.html it is possible to filter by tags when querying virtual machines, this is what we need. I can see that the current In the case of tag filters we don't need any indirection, because the query is not based on another entity but a direct value, so add_filter is not applicable because we already have the value we are going to use for filtering: the tag dictionary. I think a bit of refractory is required to differentiate between adding a filter that involves an entity, and a filter that deals with a direct value. perhaps we could rename the current What do you think? |
I came across a nice implementation of a "generic" filter which filters out after the api query: https://github.com/vultr/ansible-collection-vultr/blob/main/plugins/inventory/vultr.py#L119 IMHO we should implement the additional |
Hi, I don't have a ACS API in front of me at the moment to refactor this. The filter_by_x option sounds good. |
2e1f31b
to
52fcebc
Compare
Hi,
this PR adds a
filter_by_tags
option which allows the inventory instances to be filtered by one or more tags.Fixes #115