associations: Add conditions support
Allow there to be multiple associations files that are selected based on
an inventory property condition specified inside of them. The file(s)
needs to be located in the same directory as the default associations
file, but can have any name as long as it ends in .json. If a
conditional associations file is found, the default associations file is
ignored.
For example:
{
"condition":
{
"path": "system/chassis/motherboard",
"interface": "xyz.openbmc_project.Inventory.Decorator.Asset",
"property": "Model",
"values": [
"ModelA",
"ModelB"
]
},
"associations":
[
// The same associations syntax as described above.
]
}
This states that the associations in this file are valid if the
motherboard inventory item has a Model property with a value of either
ModelA or ModelB.
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: Ib0f32815dee718ea268715896b5470ed2f25119e
diff --git a/interface_ops.hpp b/interface_ops.hpp
index b16fa57..bc3e926 100644
--- a/interface_ops.hpp
+++ b/interface_ops.hpp
@@ -75,6 +75,28 @@
};
template <typename T, typename Enable = void>
+struct GetPropertyValue
+{
+ static InterfaceVariantType op(const std::string propertyName,
+ std::any& holder)
+ {
+ return InterfaceVariantType{};
+ }
+};
+
+template <typename T>
+struct GetPropertyValue<T, std::enable_if_t<HasProperties<T>::value>>
+{
+ static InterfaceVariantType op(const std::string propertyName,
+ std::any& holder)
+ {
+ auto& iface = *std::any_cast<std::shared_ptr<T>&>(holder);
+ auto property = iface.getPropertyByName(propertyName);
+ return convertVariant<InterfaceVariantType>(property);
+ }
+};
+
+template <typename T, typename Enable = void>
struct AssignInterface
{
static void op(const Interface&, std::any&, bool)
@@ -150,6 +172,8 @@
template <typename Ops>
using DeserializeInterfaceType =
std::add_pointer_t<decltype(DeserializeInterface<DummyInterface, Ops>::op)>;
+using GetPropertyValueType =
+ std::add_pointer_t<decltype(GetPropertyValue<DummyInterface>::op)>;
} // namespace manager
} // namespace inventory