xref: /openbmc/phosphor-inventory-manager/README.md (revision c121f56cbb9dbc090a790378a70550d8735836cd)
1c9199471SPatrick Williams# Phosphor Inventory Manager (PIM)
2c9199471SPatrick Williams
3bf066a63SBrad BishopPhosphor Inventory Manager (PIM) is an implementation of the
4c9199471SPatrick Williams`xyz.openbmc_project.Inventory.Manager` DBus interface, and supporting tools.
5c9199471SPatrick WilliamsPIM uses a combination of build-time YAML files, run-time calls to the Notify
6c9199471SPatrick Williamsmethod of the Manager interface, and association definition JSON files to
7c9199471SPatrick Williamsprovide a generalized inventory state management solution.
8bf066a63SBrad Bishop
9bf066a63SBrad Bishop## YAML
109c053fbfSPatrick Williams
119c053fbfSPatrick WilliamsPIM includes a YAML parser (pimgen.py). For PIM to do anything useful, a set of
129c053fbfSPatrick WilliamsYAML files must be provided externally that tell it what to do. Examples can be
139c053fbfSPatrick Williamsfound in the examples directory.
14bf066a63SBrad Bishop
15bf066a63SBrad BishopThe following top level YAML tags are supported:
16bf066a63SBrad Bishop
179c053fbfSPatrick Williams- description - An optional description of the file.
189c053fbfSPatrick Williams- events - One or more events that PIM should monitor.
19bf066a63SBrad Bishop
20c9199471SPatrick Williams### events
21afbd28efSBrad Bishop
22bf066a63SBrad BishopSupported event tags are:
23bf066a63SBrad Bishop
249c053fbfSPatrick Williams- name - A globally unique event name.
259c053fbfSPatrick Williams- description - An optional description of the event.
269c053fbfSPatrick Williams- type - The event type. Supported types are: _match_ and _startup_.
279c053fbfSPatrick Williams- actions - The responses to the event.
28bf066a63SBrad Bishop
29bf066a63SBrad BishopSubsequent tags are defined by the event type.
30bf066a63SBrad Bishop
31c9199471SPatrick Williams### match
32afbd28efSBrad Bishop
33bf066a63SBrad BishopSupported match tags are:
34bf066a63SBrad Bishop
359c053fbfSPatrick Williams- signatures - A DBus match specification.
369c053fbfSPatrick Williams- filters - Filters to apply when a match occurs.
373d57f507SBrad Bishop
38c9199471SPatrick Williams### startup
39828df832SBrad Bishop
40828df832SBrad BishopSupported startup tags are:
41828df832SBrad Bishop
429c053fbfSPatrick Williams- filters - Filters to apply at startup.
43828df832SBrad Bishop
44c9199471SPatrick Williams### filters
45afbd28efSBrad Bishop
463d57f507SBrad BishopSupported filter tags are:
473d57f507SBrad Bishop
489c053fbfSPatrick Williams- name - The filter to use.
49c93bcc97SBrad Bishop
50c93bcc97SBrad BishopSubsequent tags are defined by the filter type.
513d57f507SBrad Bishop
523d57f507SBrad BishopThe available filters provided by PIM are:
533d57f507SBrad Bishop
549c053fbfSPatrick Williams- propertyChangedTo - Only match events when the specified property has the
559c053fbfSPatrick Williams  specified value.
569c053fbfSPatrick Williams- propertyIs - Only match events when the specified property has the specified
579c053fbfSPatrick Williams  value.
58d0f48adcSBrad Bishop
59c9199471SPatrick Williams### propertyChangedTo
609c053fbfSPatrick Williams
619c053fbfSPatrick WilliamsThe property under test is obtained from an sdbus message generated from an
629c053fbfSPatrick Williamsorg.freedesktop.DBus.Properties.PropertiesChanged signal payload.
639c053fbfSPatrick Williams
649c053fbfSPatrick WilliamsSupported arguments for the propertyChangedTo filter are:
659c053fbfSPatrick Williams
669c053fbfSPatrick Williams- interface - The interface hosting the property to be checked.
679c053fbfSPatrick Williams- property - The property to check.
689c053fbfSPatrick Williams- value - The value to check.
699c053fbfSPatrick Williams
70c9199471SPatrick Williams### propertyIs
719c053fbfSPatrick Williams
729c053fbfSPatrick WilliamsThe property under test is obtained by invoking org.freedesktop.Properties.Get
739c053fbfSPatrick Williamson the specified interface.
749c053fbfSPatrick Williams
759c053fbfSPatrick WilliamsSupported arguments for the propertyIs filter are:
769c053fbfSPatrick Williams
779c053fbfSPatrick Williams- path - The object hosting the property to be checked.
789c053fbfSPatrick Williams- interface - The interface hosting the property to be checked.
799c053fbfSPatrick Williams- property - The property to check.
809c053fbfSPatrick Williams- value - The value to check.
819c053fbfSPatrick Williams- service - An optional DBus service name.
829c053fbfSPatrick Williams
839c053fbfSPatrick WilliamsThe service argument is optional. If provided that service will be called
849c053fbfSPatrick Williamsexplicitly. If omitted, the service will be obtained with an
85c9199471SPatrick Williams`xyz.openbmc_project.ObjectMapper` lookup.
869c053fbfSPatrick Williams
879c053fbfSPatrick WilliamspropertyIs can be used in an action condition context when the action operates
889c053fbfSPatrick Williamson a dbus object path.
899c053fbfSPatrick Williams
90c9199471SPatrick Williams### actions
91e4b1b1e7SBrad Bishop
92e4b1b1e7SBrad BishopSupported action tags are:
93e4b1b1e7SBrad Bishop
949c053fbfSPatrick Williams- name - The action to perform.
95c93bcc97SBrad Bishop
96c93bcc97SBrad BishopSubsequent tags are defined by the action type.
97e4b1b1e7SBrad Bishop
98e4b1b1e7SBrad BishopThe available actions provided by PIM are:
99e4b1b1e7SBrad Bishop
1009c053fbfSPatrick Williams- destroyObject - Destroy the specified DBus object.
1019c053fbfSPatrick Williams- setProperty - Set the specified property on the specified DBus object.
102e4b1b1e7SBrad Bishop
103c9199471SPatrick Williams### destroyObject
104e4b1b1e7SBrad Bishop
105e4b1b1e7SBrad BishopSupported arguments for the destroyObject action are:
106d0f48adcSBrad Bishop
1079c053fbfSPatrick Williams- paths - The paths of the objects to remove from DBus.
1089c053fbfSPatrick Williams- conditions - An array of conditions.
109e4b1b1e7SBrad Bishop
1109c053fbfSPatrick WilliamsConditions are tested and logically ANDed. If the conditions do not pass, the
1119c053fbfSPatrick Williamsobject is not destroyed. Any condition that accepts a path parameter is
1129c053fbfSPatrick Williamssupported.
1139c053fbfSPatrick Williams
114c9199471SPatrick Williams### setProperty
115e4b1b1e7SBrad Bishop
116e4b1b1e7SBrad BishopSupported arguments for the setProperty action are:
117d0f48adcSBrad Bishop
1189c053fbfSPatrick Williams- interface - The interface hosting the property to be set.
1199c053fbfSPatrick Williams- property - The property to set.
1209c053fbfSPatrick Williams- paths - The objects hosting the property to be set.
1219c053fbfSPatrick Williams- value - The value to set.
1229c053fbfSPatrick Williams- conditions - An array of conditions.
123e4b1b1e7SBrad Bishop
1249c053fbfSPatrick WilliamsConditions are tested and logically ANDed. If the conditions do not pass, the
1259c053fbfSPatrick Williamsproperty is not set. Any condition that accepts a path parameter is supported.
1269c053fbfSPatrick Williams
127c9199471SPatrick Williams### createObjects
128db92c28aSBrad Bishop
129db92c28aSBrad BishopSupported arguments for the createObjects action are:
130db92c28aSBrad Bishop
1319c053fbfSPatrick Williams- objs - A dictionary of objects to create.
1329c053fbfSPatrick Williams
133fa4c837cSMatt Spinler## Creating Associations
1349c053fbfSPatrick Williams
1359c053fbfSPatrick WilliamsPIM can create [associations][1] between inventory items and other D-Bus
1369c053fbfSPatrick Williamsobjects.
137fa4c837cSMatt Spinler
138fa4c837cSMatt SpinlerThis functionality is optional and is controlled with the
139fa4c837cSMatt Spinler`--enable-associations` configure option. It defaults to disabled.
140fa4c837cSMatt Spinler
141fa4c837cSMatt SpinlerTo use this, the associations to create should be defined in a JSON file which
142fa4c837cSMatt Spinleris specified by the `ASSOCIATIONS_FILE_PATH` configure variable, which defaults
143fa4c837cSMatt Spinlerto `/usr/share/phosphor-inventory-manager/associations.json`. This file is
144fa4c837cSMatt Spinlerprocessed at runtime.
145fa4c837cSMatt Spinler
146fa4c837cSMatt SpinlerAn example of this JSON is:
1479c053fbfSPatrick Williams
148c9199471SPatrick Williams```json
149fa4c837cSMatt Spinler[
150fa4c837cSMatt Spinler  {
151fa4c837cSMatt Spinler    "path": "system/chassis/motherboard/cpu0/core1",
152c9199471SPatrick Williams    "endpoints": [
153fa4c837cSMatt Spinler      {
154c9199471SPatrick Williams        "types": {
155fa4c837cSMatt Spinler          "fType": "sensors",
156fa4c837cSMatt Spinler          "rType": "inventory"
157fa4c837cSMatt Spinler        },
158c9199471SPatrick Williams        "paths": ["/xyz/openbmc_project/sensors/temperature/p0_core0_temp"]
159fa4c837cSMatt Spinler      }
160fa4c837cSMatt Spinler    ]
161fa4c837cSMatt Spinler  }
162fa4c837cSMatt Spinler]
163fa4c837cSMatt Spinler```
164fa4c837cSMatt Spinler
165fa4c837cSMatt SpinlerThen, when/if PIM creates the
1669c053fbfSPatrick Williams`xyz/openbmc_project/system/chassis/motherboard/cpu0/core1` inventory object, it
1679c053fbfSPatrick Williamswill add an `xyz.openbmc_project.Association.Definitions` interface on it such
1689c053fbfSPatrick Williamsthat the object mapper creates the 2 association objects:
169fa4c837cSMatt Spinler
170c9199471SPatrick Williams```text
171fa4c837cSMatt Spinler    /xyz/openbmc_project/inventory/system/chassis/motherboard/cpu0/core1/sensors
172fa4c837cSMatt Spinler       endpoints property:
173fa4c837cSMatt Spinler       ['/xyz/openbmc_project/sensors/temperature/p0_core0_temp']
174fa4c837cSMatt Spinler
175fa4c837cSMatt Spinler    /xyz/openbmc_project/sensors/temperature/p0_core0_temp/inventory
176fa4c837cSMatt Spinler       endpoints property:
177fa4c837cSMatt Spinler       ['/xyz/openbmc_project/inventory/system/chassis/motherboard/cpu0/core1']
178fa4c837cSMatt Spinler```
179fa4c837cSMatt Spinler
180fa4c837cSMatt SpinlerThe JSON description is:
1819c053fbfSPatrick Williams
182c9199471SPatrick Williams```json
183fa4c837cSMatt Spinler[
184fa4c837cSMatt Spinler    {
185fa4c837cSMatt Spinler        "path": "The relative path of the inventory object to create the
186fa4c837cSMatt Spinler                 xyz.openbmc_project.Association.Definitions interface on."
187fa4c837cSMatt Spinler        "endpoints":
188fa4c837cSMatt Spinler        [
189fa4c837cSMatt Spinler            {
190fa4c837cSMatt Spinler                "types":
191fa4c837cSMatt Spinler                {
192fa4c837cSMatt Spinler                    "fType": "The forward association type."
193fa4c837cSMatt Spinler                    "rType": "The reverse association type."
194fa4c837cSMatt Spinler                },
195fa4c837cSMatt Spinler                "paths":
196fa4c837cSMatt Spinler                [
197fa4c837cSMatt Spinler                    "The list of association endpoints for this inventory path
198fa4c837cSMatt Spinler                     and association type."
199fa4c837cSMatt Spinler                ]
200fa4c837cSMatt Spinler            }
201fa4c837cSMatt Spinler        ]
202fa4c837cSMatt Spinler    }
203fa4c837cSMatt Spinler]
204fa4c837cSMatt Spinler```
205e4b1b1e7SBrad Bishop
20659521e87SMatt SpinlerIn the case where different systems that require different associations reside
20759521e87SMatt Spinlerin the same flash image, multiple JSON files must be used. These files must be
2089c053fbfSPatrick Williamsin the same directory as the default associations file would go, but it does not
2099c053fbfSPatrick Williamsmatter what they are named as long as the name ends in '.json'. Each file then
2109c053fbfSPatrick Williamscontains a 'condition' entry that specifies an inventory path, interface,
21159521e87SMatt Spinlerproperty, and list of values. If the actual value of that property is in the
21259521e87SMatt Spinlerlist of values, then the condition is met and those associations are activated.
21359521e87SMatt Spinler
2149c053fbfSPatrick WilliamsIf a file with a conditions section is found, then the default associations file
2159c053fbfSPatrick Williamsis ignored. The end result is that associations are only ever loaded from one
2169c053fbfSPatrick Williamsfile, either the default file if there aren't any files with conditions in them,
2179c053fbfSPatrick Williamsor the first file that had a condition that matched.
21859521e87SMatt Spinler
21959521e87SMatt SpinlerAn example is:
22059521e87SMatt Spinler
221c9199471SPatrick Williams```json
22259521e87SMatt Spinler{
223c9199471SPatrick Williams  "condition": {
22459521e87SMatt Spinler    "path": "system/chassis/motherboard",
22559521e87SMatt Spinler    "interface": "xyz.openbmc_project.Inventory.Decorator.Asset",
22659521e87SMatt Spinler    "property": "Model",
227c9199471SPatrick Williams    "values": ["ModelA", "ModelB"]
22859521e87SMatt Spinler  },
229c9199471SPatrick Williams  "associations": [
23059521e87SMatt Spinler    {
23159521e87SMatt Spinler      "path": "system/chassis/motherboard/cpu0/core1",
232c9199471SPatrick Williams      "endpoints": [
23359521e87SMatt Spinler        {
234c9199471SPatrick Williams          "types": { "fType": "sensors", "rType": "inventory" },
235c9199471SPatrick Williams          "paths": ["/xyz/openbmc_project/sensors/temperature/p0_core0_temp"]
23659521e87SMatt Spinler        }
23759521e87SMatt Spinler      ]
23859521e87SMatt Spinler    }
23959521e87SMatt Spinler  ]
24059521e87SMatt Spinler}
24159521e87SMatt Spinler```
24259521e87SMatt Spinler
24359521e87SMatt SpinlerThis states that these associations are valid if the system/chassis/motherboard
2449c053fbfSPatrick Williamsinventory object has a Model property with a value of either ModelA or ModelB.
24559521e87SMatt Spinler
246c9199471SPatrick WilliamsThe values field supports the same types as in the inventory, so either a `bool`
247c9199471SPatrick Williams(true/false), `int64_t`, `std::string`, or `std::vector<uint8_t>`([1, 2]).
2489c053fbfSPatrick Williams
249bf066a63SBrad Bishop## Building
2509c053fbfSPatrick Williams
251bf066a63SBrad BishopAfter running pimgen.py, build PIM using the following steps:
252bf066a63SBrad Bishop
253c9199471SPatrick Williams```sh
254*c121f56cSPatrick Williamsmeson setup builddir
255*c121f56cSPatrick Williamsninja -C builddir
25673b776bdSBrad Bishop```
2579c053fbfSPatrick Williams
2589c053fbfSPatrick Williams[1]:
2599c053fbfSPatrick Williams  https://github.com/openbmc/docs/blob/master/architecture/object-mapper.md#associations
260