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.
This pull request is a quick and incomplete implementation of adding an Inventory Data Plugin. The idea is to have a base to discuss this idea and what would be needed to accept such a change.
At the moment, the inventory data is stored in a Python dictionary. This works great. However, I found myself in a situation where I would like to replace the dictionary with objects. More specifically, I would like to use a pydantic model for the data structure. Firstly, to have input validation and, secondly, to be able to add functions to the pedantic objects to reduce logic in templates.
This PR adds a new plugin type called InventoryDataPlugin. The idea is to allow the default dict object to be replaced with another object. For now, I implemented it in a way that does not break any tests, as the new datatype used to store the data needs to provide methods similar to a dictionary. The code and plugin are most likely more complex because of this.
To use pydantic I would try to implement a plugin to use a model similar to this (just "random" pseudocode, untested):
The model, of course, would be much more complex with nested models. What already works well is to store multiple models in the data dictionary. So, in this case, only the first level would be a dictionary.