-
Notifications
You must be signed in to change notification settings - Fork 30
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
Filter optimize #12
Open
velotiger
wants to merge
23
commits into
datacenter:master
Choose a base branch
from
velotiger:filter-optimize
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Filter optimize #12
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Comments/explanations added to the code. Optimizations: * Use closure for listify function to encapsulate internal vars. * Eliminated some intermediate vars. * Replaced last loop by direct key lookup.
MOD: plugins/filter/aci.py
MOD: .gitignore
MOD: .gitignore
The original filter needs alternating dicts/lists in the inventory. This alternative filter accepts lists and dicts in any order. The result for an inventory with alternating dicts/lists is unchanged. NEW: plugins/filter/aci2.py
MOD: plugins/filter/aci2.py
This fixes a bug in commit ad32ff5: Attributes in intermediate items (neither top-level nor bottom) do not appear in output. E.g. if you look for keywords «tenant», «vrf», «bd», «subnet» some attributes for «vrf» might be missing because they were evaluated after the cache had been transferred to the result list. To avoid this, all flat key/value pairs are evaluated before any dict or list at the same level. MOD: plugins/filter/aci2.py
* You can append a regex to each key (separated by an =–sign). * Only keys whose name-attribute matches the regex will be included in the result. * If the regex is omitted, all keys will be included (same behavior as before – backwards compatible). * Example: "{{ aci_topology|aci_listify2('access_policy', 'interface_policy_profile=.+998', 'interface_selector') }}" All paths in the output match interface policy profiles that end in «998». E.g. interface selectors below a non-matching interface policy profile will be suppressed from the output. MOD: plugins/filter/aci2.py
MOD: plugins/filter/aci2.py
Do not hard-code the attribute used for regex matching of keys. The variable «NameAttr» specifies the name of this attribute. MOD: plugins/filter/aci2.py
Fixes this issue: Program ended with error if name-attribut's value was not a string (used pattern matching on a non-string object). MOD: plugins/filter/aci2.py
* Short description of alternative filter. * One more example how to use the alternative filter (dynamically specify match pattern for keys at runtime). MOD: README.md MOD: plugins/filter/aci2.py
No functional changes or fixes. Add more patterns to .gitignore MOD: .gitignore MOD: plugins/filter/aci2.py
* Get rid of extra loop that deletes flat key/value pairs after copying them to the cache. MOD: plugins/filter/aci2.py
Instances of objects can be organized in lists (as before) or dicts (new). * This is useful if you need direct lookups by key. * This is partly incompatible to previous versions! Nested dicts and lists in any order down the object tree are not supported any more. This feature was not not useful and therefore has been dropped. MOD: README.md MOD: plugins/filter/aci2.py
MOD: .gitignore
* Use a closure to set fixed values once for all (avoid setting them in every new call of the filter).
Previously scalar attributes have been deleted after evaluation. This simplified further processing of lists and dicts. However, if the object tree uses anchors and aliases, deleting attributes invalidates the aliases.
+ minor code formatting.
* This is a backport of commit eed6b9a to the old listify filter (aci.py). * Add an example for a subnet to the example inventory. Ref: CiscoDevNet/ansible-aci#517 (comment)
Accetable attribute values: Replace negated check for list or dict by explicit check for scalar types.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi, I added comments to aci.py to explain the code and did a few optimizations:
I hope you'll find this contribution useful.