summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Tritz <mtritz@us.ibm.com>2017-09-05 16:38:11 -0500
committerBrad Bishop <bradleyb@fuzziesquirrel.com>2017-09-26 21:06:55 +0000
commitd50f65787a81b021e42c9b066e65ca11e080bd3c (patch)
tree336d27cc9d62119c0168771ac5adc9338dd4ad61
parente39f379014439fc2f200c083b39a3cbeb8cbb766 (diff)
downloadphosphor-state-manager-d50f65787a81b021e42c9b066e65ca11e080bd3c.tar.gz
phosphor-state-manager-d50f65787a81b021e42c9b066e65ca11e080bd3c.zip
discover_system_state: Accept a node parameter
In this commit, discover_system_state is extended to accept a command line argument such that the user can specify a particular host. This will allow discover_system_state to run for host1, host2, or any other host! Resolves openbmc/openbmc#1466 Change-Id: Ib58a4bc1fd5dfe10a6455778eac779eb0b2085e0 Signed-off-by: Michael Tritz <mtritz@us.ibm.com>
-rw-r--r--discover_system_state.cpp34
1 files changed, 28 insertions, 6 deletions
diff --git a/discover_system_state.cpp b/discover_system_state.cpp
index 303b4a4..d403671 100644
--- a/discover_system_state.cpp
+++ b/discover_system_state.cpp
@@ -1,3 +1,4 @@
+#include <getopt.h>
#include <iostream>
#include <map>
#include <string>
@@ -28,8 +29,6 @@ constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper";
constexpr auto PROPERTY_INTERFACE = "org.freedesktop.DBus.Properties";
-constexpr auto HOST_PATH = "/xyz/openbmc_project/state/host0";
-
std::string getService(sdbusplus::bus::bus& bus, std::string path,
std::string interface)
{
@@ -116,10 +115,33 @@ void setProperty(sdbusplus::bus::bus& bus, std::string path,
} // namespace state
} // namepsace phosphor
-int main()
+int main(int argc, char** argv)
{
using namespace phosphor::logging;
+ std::string hostPath = "/xyz/openbmc_project/state/host0";
+ int arg;
+ int optIndex = 0;
+
+ static struct option longOpts[] =
+ {
+ {"host", required_argument, 0, 'h'},
+ {0, 0, 0, 0}
+ };
+
+ while((arg = getopt_long(argc, argv, "h:", longOpts, &optIndex)) != -1)
+ {
+ switch (arg)
+ {
+ case 'h':
+ hostPath = std::string("/xyz/openbmc_project/state/host") +
+ optarg;
+ break;
+ default:
+ break;
+ }
+ }
+
auto bus = sdbusplus::bus::new_default();
using namespace settings;
@@ -156,7 +178,7 @@ int main()
RestorePolicy::convertPolicyFromString(powerPolicy))
{
log<level::INFO>("power_policy=ALWAYS_POWER_ON, powering host on");
- setProperty(bus, HOST_PATH, HOST_BUSNAME,
+ setProperty(bus, hostPath, HOST_BUSNAME,
"RequestedHostTransition",
convertForMessage(server::Host::Transition::On));
}
@@ -166,10 +188,10 @@ int main()
log<level::INFO>("power_policy=RESTORE, restoring last state");
// Read last requested state and re-request it to execute it
- auto hostReqState = getProperty(bus, HOST_PATH,
+ auto hostReqState = getProperty(bus, hostPath,
HOST_BUSNAME,
"RequestedHostTransition");
- setProperty(bus, HOST_PATH, HOST_BUSNAME,
+ setProperty(bus, hostPath, HOST_BUSNAME,
"RequestedHostTransition",
hostReqState);
}
OpenPOWER on IntegriCloud