The search functionality described at auto_storage.md is pretty powerful. But the current implementation only allows to:
search by name
return 0 or 1 devices per search
Solution
This implements several parts of the missing functionality, like:
Ability to match more than one device per search section
Limit the number of matches by using max.
This pull request does not add the ability to use other conditions or matching order beyond name. So it's only possible to search either for a device with a given name, either for all the devices sorted by name. The syntax for the latter would be this (a search with no conditions):
{ "search": {} }
For readability, the following alternative syntax is also introduced at this pull request:
{ "search": "*" }
The new default for drive entries (if omitted) becomes:
{ "search": { "max": 1 } }
If several devices match with a given search section, the corresponding configuration containing the search is replicated as many times as needed. Eg. in a system with two disks, the following config...
This also makes sure everything keeps working when an alias is used together with a search that matches several devices (so all the resulting config objects share the same alias).
Testing
Adapted existing unit tests and added a new ones regarding the search functionality
Added a new unit test to check that resolving a config into several ones (potentially with a shared alias) works as expected.
Problem
The search functionality described at
auto_storage.md
is pretty powerful. But the current implementation only allows to:Solution
This implements several parts of the missing functionality, like:
search
sectionmax
.This pull request does not add the ability to use other conditions or matching order beyond
name
. So it's only possible to search either for a device with a given name, either for all the devices sorted by name. The syntax for the latter would be this (a search with no conditions):For readability, the following alternative syntax is also introduced at this pull request:
The new default for drive entries (if omitted) becomes:
If several devices match with a given
search
section, the corresponding configuration containing thesearch
is replicated as many times as needed. Eg. in a system with two disks, the following config......is expanded into:
This also makes sure everything keeps working when an
alias
is used together with asearch
that matches several devices (so all the resulting config objects share the same alias).Testing
search
functionality