diff options
| author | Patrick Venture <venture@google.com> | 2019-08-06 09:24:46 -0700 |
|---|---|---|
| committer | Patrick Venture <venture@google.com> | 2019-08-06 09:30:10 -0700 |
| commit | 9cce5a26729f4485676999e3f8eae0aec4fffaa0 (patch) | |
| tree | 533333ccf33771dbf681fee7783a3a1395e4c1dc | |
| parent | cf066ace76d6f99b73a7c55793d6f475c058321a (diff) | |
| download | phosphor-ipmi-flash-9cce5a26729f4485676999e3f8eae0aec4fffaa0.tar.gz phosphor-ipmi-flash-9cce5a26729f4485676999e3f8eae0aec4fffaa0.zip | |
bmc: buildjson: provide helper for common filesystemd type
Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: If0c106301538a6a11e199c8033cf7328f21575e6
| -rw-r--r-- | bmc/buildjson.cpp | 49 |
1 files changed, 21 insertions, 28 deletions
diff --git a/bmc/buildjson.cpp b/bmc/buildjson.cpp index 0fd40ef..6f9c319 100644 --- a/bmc/buildjson.cpp +++ b/bmc/buildjson.cpp @@ -34,6 +34,25 @@ namespace ipmi_flash { +std::unique_ptr<TriggerableActionInterface> + buildFileSystemd(const nlohmann::json& data) +{ + /* This type of action requires a path and unit, and optionally a mode. */ + const auto& path = data.at("path"); + const auto& unit = data.at("unit"); + + /* the mode parameter is optional. */ + std::string systemdMode = "replace"; + const auto& mode = data.find("mode"); + if (mode != data.end()) + { + systemdMode = data.at("mode").get<std::string>(); + } + + return SystemdWithStatusFile::CreateSystemdWithStatusFile( + sdbusplus::bus::new_default(), path, unit, systemdMode); +} + std::vector<HandlerConfig> buildHandlerFromJson(const nlohmann::json& data) { std::vector<HandlerConfig> handlers; @@ -89,20 +108,7 @@ std::vector<HandlerConfig> buildHandlerFromJson(const nlohmann::json& data) const std::string verifyType = verify.at("type"); if (verifyType == "fileSystemdVerify") { - const auto& path = verify.at("path"); - const auto& unit = verify.at("unit"); - - /* the mode parameter is optional. */ - std::string systemdMode = "replace"; - const auto& mode = verify.find("mode"); - if (mode != verify.end()) - { - systemdMode = verify.at("mode").get<std::string>(); - } - - pack->verification = - SystemdWithStatusFile::CreateSystemdWithStatusFile( - sdbusplus::bus::new_default(), path, unit, systemdMode); + pack->verification = std::move(buildFileSystemd(verify)); } else { @@ -121,20 +127,7 @@ std::vector<HandlerConfig> buildHandlerFromJson(const nlohmann::json& data) } else if (updateType == "fileSystemdUpdate") { - const auto& path = update.at("path"); - const auto& unit = update.at("unit"); - - /* the mode parameter is optional. */ - std::string systemdMode = "replace"; - const auto& mode = update.find("mode"); - if (mode != update.end()) - { - systemdMode = update.at("mode").get<std::string>(); - } - - pack->update = - SystemdWithStatusFile::CreateSystemdWithStatusFile( - sdbusplus::bus::new_default(), path, unit, systemdMode); + pack->update = std::move(buildFileSystemd(update)); } else if (updateType == "systemd") { |

