@@ -254,13 +254,45 @@ int VpdTool::fixSystemVpd() const noexcept
254254
255255 printSystemVpd (l_backupRestoreCfgJsonObj);
256256
257- printFixSystemVpdOption (types::UserOption::UseBackupDataForAll);
258- printFixSystemVpdOption (types::UserOption::UseSystemBackplaneDataForAll);
259- printFixSystemVpdOption (types::UserOption::MoreOptions);
260- printFixSystemVpdOption (types::UserOption::Exit);
257+ do
258+ {
259+ printFixSystemVpdOption (types::UserOption::UseBackupDataForAll);
260+ printFixSystemVpdOption (
261+ types::UserOption::UseSystemBackplaneDataForAll);
262+ printFixSystemVpdOption (types::UserOption::MoreOptions);
263+ printFixSystemVpdOption (types::UserOption::Exit);
264+
265+ int l_userSelectedOption = types::UserOption::Exit;
266+ std::cin >> l_userSelectedOption;
267+
268+ std::cout << std::endl << std::string (191 , ' =' ) << std::endl;
261269
262- l_rc = constants::SUCCESS;
263- // ToDo: Implementation needs to be added
270+ if (types::UserOption::UseBackupDataForAll == l_userSelectedOption)
271+ {
272+ l_rc = updateAllKeywords (l_backupRestoreCfgJsonObj, true );
273+ break ;
274+ }
275+ else if (types::UserOption::UseSystemBackplaneDataForAll ==
276+ l_userSelectedOption)
277+ {
278+ l_rc = updateAllKeywords (l_backupRestoreCfgJsonObj, false );
279+ break ;
280+ }
281+ else if (types::UserOption::MoreOptions == l_userSelectedOption)
282+ {
283+ // ToDo: Implementation needs to be added
284+ break ;
285+ }
286+ else if (types::UserOption::Exit == l_userSelectedOption)
287+ {
288+ std::cout << " Exit successfully" << std::endl;
289+ break ;
290+ }
291+ else
292+ {
293+ std::cout << " Provide a valid option. Retry." << std::endl;
294+ }
295+ } while (true );
264296
265297 return l_rc;
266298}
@@ -850,4 +882,100 @@ void VpdTool::printSystemVpd(
850882 }
851883 }
852884}
885+
886+ int VpdTool::updateAllKeywords (const nlohmann::json& i_parsedJsonObj,
887+ bool i_useBackupData) const noexcept
888+ {
889+ int l_rc = constants::FAILURE;
890+
891+ if (i_parsedJsonObj.empty () || !i_parsedJsonObj.contains (" source" ) ||
892+ !i_parsedJsonObj.contains (" backupMap" ))
893+ {
894+ // TODO: Enable logging when verbose is enabled.
895+ std::cerr << " Invalid JSON" << std::endl;
896+ return l_rc;
897+ }
898+
899+ std::string l_srcVpdPath;
900+ if (auto l_vpdPath = i_parsedJsonObj[" source" ].value (" hardwarePath" , " " );
901+ !l_vpdPath.empty ())
902+ {
903+ l_srcVpdPath = l_vpdPath;
904+ }
905+ else if (auto l_vpdPath = i_parsedJsonObj[" source" ].value (" inventoryPath" ,
906+ " " );
907+ !l_vpdPath.empty ())
908+ {
909+ l_srcVpdPath = l_vpdPath;
910+ }
911+ else
912+ {
913+ // TODO: Enable logging when verbose is enabled.
914+ std::cerr << " source path information is missing in JSON" << std::endl;
915+ return l_rc;
916+ }
917+
918+ bool l_anyMismatchFound = false ;
919+ for (const auto & l_aRecordKwInfo : i_parsedJsonObj[" backupMap" ])
920+ {
921+ if (!l_aRecordKwInfo.contains (" sourceRecord" ) ||
922+ !l_aRecordKwInfo.contains (" sourceKeyword" ) ||
923+ !l_aRecordKwInfo.contains (" destinationkeywordValue" ) ||
924+ !l_aRecordKwInfo.contains (" sourcekeywordValue" ))
925+ {
926+ // TODO: Enable logging when verbose is enabled.
927+ std::cerr << " Missing required information in the JSON"
928+ << std::endl;
929+ continue ;
930+ }
931+
932+ if (l_aRecordKwInfo[" sourcekeywordValue" ] !=
933+ l_aRecordKwInfo[" destinationkeywordValue" ])
934+ {
935+ l_anyMismatchFound = true ;
936+
937+ auto l_keywordValue =
938+ i_useBackupData ? l_aRecordKwInfo[" destinationkeywordValue" ]
939+ : l_aRecordKwInfo[" sourcekeywordValue" ];
940+
941+ auto l_paramsToWrite = std::make_tuple (
942+ l_aRecordKwInfo[" sourceRecord" ],
943+ l_aRecordKwInfo[" sourceKeyword" ], l_keywordValue);
944+
945+ try
946+ {
947+ l_rc = utils::writeKeyword (l_srcVpdPath, l_paramsToWrite);
948+ if (l_rc > 0 )
949+ {
950+ l_rc = constants::SUCCESS;
951+ }
952+ }
953+ catch (const std::exception& l_ex)
954+ {
955+ // TODO: Enable logging when verbose is enabled.
956+ std::cerr << " write keyword failed for record: "
957+ << l_aRecordKwInfo[" sourceRecord" ]
958+ << " , keyword: " << l_aRecordKwInfo[" sourceKeyword" ]
959+ << " , error: " << l_ex.what () << std::ends;
960+ }
961+ }
962+ }
963+
964+ std::string l_dataUsed = (i_useBackupData ? " data from backup"
965+ : " data from primary VPD" );
966+ if (l_anyMismatchFound)
967+ {
968+ std::cout << " Data updated successfully for all mismatching "
969+ " record-keyword pairs by choosing their corresponding "
970+ << l_dataUsed << " . Exit successfully." << std::endl;
971+ }
972+ else
973+ {
974+ std::cout << " No mismatch found for any of the above mentioned "
975+ " record-keyword pair. Exit successfully."
976+ << std::endl;
977+ }
978+
979+ return l_rc;
980+ }
853981} // namespace vpd
0 commit comments