Get Inventory list using unexpanded location code
This commit implements an api to get inventory list with respect to
a given location code in un-expanded format.
Along with location code node also needs to be passed.
In case no inventory is found at the given location or location code
is not correct, corresponding error is returned to the caller.
Tested on simics.
This api is under com.ibm.vpd.Manager interface. So vpd-manager app
needs to be running for this api to work.
Sample command for simics:
busctl call com.ibm.VPD.Manager /com/ibm/VPD/Manager com.ibm.VPD.Manager
GetFRUsByUnexpandedLocationCode sq <location_code> <node_number>
Signed-off-by: Sunny Srivastava <sunnsr25@in.ibm.com>
Change-Id: I87159d2a3c293e82c9e82d21a9d281bd176a30e7
diff --git a/vpd-manager/reader_impl.cpp b/vpd-manager/reader_impl.cpp
index 21660d9..a40aa44 100644
--- a/vpd-manager/reader_impl.cpp
+++ b/vpd-manager/reader_impl.cpp
@@ -1,10 +1,14 @@
+#include "config.h"
+
#include "reader_impl.hpp"
#include "utils.hpp"
+#include <algorithm>
#include <com/ibm/VPD/error.hpp>
#include <map>
#include <phosphor-logging/elog-errors.hpp>
+#include <vector>
#include <xyz/openbmc_project/Common/error.hpp>
namespace openpower
@@ -25,14 +29,24 @@
using Argument = xyz::openbmc_project::Common::InvalidArgument;
using LocationNotFound = sdbusplus::com::ibm::VPD::Error::LocationNotFound;
-std::string ReaderImpl::getExpandedLocationCode(
- const std::string& locationCode, const uint16_t& nodeNumber,
- const LocationCodeMap& frusLocationCode) const
+bool ReaderImpl::isValidLocationCode(const std::string& locationCode) const
{
if ((locationCode.length() < UNEXP_LOCATION_CODE_MIN_LENGTH) ||
((locationCode.find("fcs", 1, 3) == std::string::npos) &&
(locationCode.find("mts", 1, 3) == std::string::npos)))
{
+ return false;
+ }
+
+ return true;
+}
+
+std::string ReaderImpl::getExpandedLocationCode(
+ const std::string& locationCode, const uint16_t& nodeNumber,
+ const LocationCodeMap& frusLocationCode) const
+{
+ if (!isValidLocationCode(locationCode))
+ {
// argument is not valid
elog<InvalidArgument>(Argument::ARGUMENT_NAME("LOCATIONCODE"),
Argument::ARGUMENT_VALUE(locationCode.c_str()));
@@ -54,6 +68,40 @@
return expandedLocationCode;
}
+ListOfPaths
+ ReaderImpl::getFrusAtLocation(const std::string& locationCode,
+ const uint16_t& nodeNumber,
+ const LocationCodeMap& frusLocationCode) const
+{
+ if (!isValidLocationCode(locationCode))
+ {
+ // argument is not valid
+ elog<InvalidArgument>(Argument::ARGUMENT_NAME("LOCATIONCODE"),
+ Argument::ARGUMENT_VALUE(locationCode.c_str()));
+ }
+
+ auto range = frusLocationCode.equal_range(locationCode);
+
+ if (range.first == frusLocationCode.end())
+ {
+ // TODO: Implementation of error logic till then throwing invalid
+ // argument
+ // the location code was not found in the system
+ // elog<LocationNotFound>();
+ elog<InvalidArgument>(Argument::ARGUMENT_NAME("LOCATIONCODE"),
+ Argument::ARGUMENT_VALUE(locationCode.c_str()));
+ }
+
+ ListOfPaths inventoryPaths;
+
+ for_each(range.first, range.second,
+ [&inventoryPaths](
+ const inventory::LocationCodeMap::value_type& mappedItem) {
+ inventoryPaths.push_back(INVENTORY_PATH + mappedItem.second);
+ });
+ return inventoryPaths;
+}
+
} // namespace reader
} // namespace manager
} // namespace vpd