VPD tool : Read Keyword option
One of the options the VPD tool provides is
to Read the value of the keyword. This commit has its implementation.
The user should provide a valid object path, valid record name
and valid keyword inorder to get the value of the keyword.
Test:
Tested on simics.
Output:
root@rainier:/tmp# ./vpd-tool -r -O /system/chassis/motherboard/vdd_vrm1 -R VINI -K FN
{
"/system/chassis/motherboard/vdd_vrm1": {
"FN": "F190827"
}
}
Signed-off-by: PriyangaRamasamy <priyanga24@in.ibm.com>
Change-Id: I244b9fe276feefa27e4c99063a9e9aa01aeb2f12
diff --git a/vpd_tool_impl.cpp b/vpd_tool_impl.cpp
index ccc2765..d7c8504 100644
--- a/vpd_tool_impl.cpp
+++ b/vpd_tool_impl.cpp
@@ -232,3 +232,60 @@
json output = parseInvJson(jsObject, flag, fruPath);
debugger(output);
}
+
+void VpdTool::readKeyword()
+{
+ string interface = "com.ibm.ipzvpd.";
+ variant<Binary> response;
+
+ try
+ {
+ json output = json::object({});
+ json kwVal = json::object({});
+ makeDBusCall(INVENTORY_PATH + fruPath, interface + recordName, keyword)
+ .read(response);
+
+ if (auto vec = get_if<Binary>(&response))
+ {
+ kwVal.emplace(keyword, string(vec->begin(), vec->end()));
+ }
+
+ output.emplace(fruPath, kwVal);
+
+ debugger(output);
+ }
+ catch (json::exception& e)
+ {
+ json output = json::object({});
+ json kwVal = json::object({});
+
+ if (e.id == 316) // invalid UTF-8 byte exception
+ {
+ stringstream ss;
+ string hexByte;
+ string hexRep = "0x";
+ ss << hexRep;
+ hexByte = ss.str();
+
+ // convert Decimal to Hex
+ if (auto resp = get_if<Binary>(&response))
+ {
+ for (auto& vec : *resp)
+ {
+ if ((int)vec == 0)
+ {
+ ss << hex << (int)vec;
+ hexByte = ss.str();
+ }
+ ss << hex << (int)vec;
+ hexByte = ss.str();
+ }
+ }
+
+ kwVal.emplace(keyword, hexByte);
+ output.emplace(fruPath, kwVal);
+
+ debugger(output);
+ }
+ }
+}