bmcweb: Implement single Redfish "system" endpoint
This commit changes the redfish behavior to move to a single, known name
under the /redfish/v1/Systems/system path. This is advantageous for a
lot of reasons.
1. Lots fewer dbus calls to determine the system name for every path.
This could be optimized in other ways, like checking the system name on
startup, but because redfish paths are not intended to be informative,
this patchset takes the opinion that less code is better.
2. Lots of lowered complexity, given that each endpoint underneath
/system doesn't need an individual "does this system exist, and is the
name right" check.
3. This makes it possible to correctly implement the "Links" property in
Chassis, which is required for the OCP base server profile
Tested By:
Very minimal testing done, but it seems to pass the validator.
Change-Id: Iea3cb5081b92a3843b6877decd009936de00561c
Signed-off-by: Ed Tanous <ed.tanous@intel.com>
Signed-off-by: Gunnar Mills <gmills@us.ibm.com>
diff --git a/redfish-core/lib/ethernet.hpp b/redfish-core/lib/ethernet.hpp
index 9147585..aecfc21 100644
--- a/redfish-core/lib/ethernet.hpp
+++ b/redfish-core/lib/ethernet.hpp
@@ -40,9 +40,10 @@
std::vector<std::pair<
std::string,
boost::container::flat_map<
- std::string,
- std::variant<std::string, bool, uint8_t, int16_t, uint16_t, int32_t,
- uint32_t, int64_t, uint64_t, double>>>>>>;
+ std::string, sdbusplus::message::variant<
+ std::string, bool, uint8_t, int16_t, uint16_t,
+ int32_t, uint32_t, int64_t, uint64_t, double,
+ std::vector<std::string>>>>>>>;
enum class LinkType
{
@@ -81,6 +82,7 @@
std::string default_gateway;
std::string mac_address;
std::optional<uint32_t> vlan_id;
+ std::vector<std::string> nameservers;
};
// Helper function that changes bits netmask notation (i.e. /24)
@@ -160,9 +162,9 @@
{
for (const auto &objpath : dbus_data)
{
- if (objpath.first == "/xyz/openbmc_project/network/" + ethiface_id)
+ for (const auto &ifacePair : objpath.second)
{
- for (const auto &ifacePair : objpath.second)
+ if (objpath.first == "/xyz/openbmc_project/network/" + ethiface_id)
{
if (ifacePair.first == "xyz.openbmc_project.Network.MACAddress")
{
@@ -217,30 +219,45 @@
ethData.speed = *speed;
}
}
- }
- }
- else if (ifacePair.first ==
- "xyz.openbmc_project.Network.SystemConfiguration")
- {
- for (const auto &propertyPair : ifacePair.second)
- {
- if (propertyPair.first == "HostName")
+ else if (propertyPair.first == "NameServers")
{
- const std::string *hostname =
- std::get_if<std::string>(&propertyPair.second);
- if (hostname != nullptr)
+ const std::vector<std::string> *nameservers =
+ sdbusplus::message::variant_ns::get_if<
+ std::vector<std::string>>(
+ &propertyPair.second);
+ if (nameservers != nullptr)
{
- ethData.hostname = *hostname;
+ ethData.nameservers = std::move(*nameservers);
}
}
- else if (propertyPair.first == "DefaultGateway")
+ }
+ }
+ }
+ // System configuration shows up in the global namespace, so no need
+ // to check eth number
+ if (ifacePair.first ==
+ "xyz.openbmc_project.Network.SystemConfiguration")
+ {
+ for (const auto &propertyPair : ifacePair.second)
+ {
+ if (propertyPair.first == "HostName")
+ {
+ const std::string *hostname =
+ sdbusplus::message::variant_ns::get_if<std::string>(
+ &propertyPair.second);
+ if (hostname != nullptr)
{
- const std::string *defaultGateway =
- std::get_if<std::string>(&propertyPair.second);
- if (defaultGateway != nullptr)
- {
- ethData.default_gateway = *defaultGateway;
- }
+ ethData.hostname = *hostname;
+ }
+ }
+ else if (propertyPair.first == "DefaultGateway")
+ {
+ const std::string *defaultGateway =
+ sdbusplus::message::variant_ns::get_if<std::string>(
+ &propertyPair.second);
+ if (defaultGateway != nullptr)
+ {
+ ethData.default_gateway = *defaultGateway;
}
}
}
@@ -1166,7 +1183,23 @@
json_response["Id"] = iface_id;
json_response["@odata.id"] =
"/redfish/v1/Managers/bmc/EthernetInterfaces/" + iface_id;
-
+ json_response["InterfaceEnabled"] = true;
+ if (ethData.speed == 0)
+ {
+ json_response["LinkStatus"] = "NoLink";
+ json_response["Status"] = {
+ {"Health", "OK"},
+ {"State", "Disabled"},
+ };
+ }
+ else
+ {
+ json_response["LinkStatus"] = "LinkUp";
+ json_response["Status"] = {
+ {"Health", "OK"},
+ {"State", "Enabled"},
+ };
+ }
json_response["SpeedMbps"] = ethData.speed;
json_response["MACAddress"] = ethData.mac_address;
if (!ethData.hostname.empty())
@@ -1185,6 +1218,7 @@
vlanObj["VLANEnable"] = false;
vlanObj["VLANId"] = 0;
}
+ json_response["NameServers"] = ethData.nameservers;
if (ipv4Data.size() > 0)
{
@@ -1192,17 +1226,10 @@
ipv4_array = nlohmann::json::array();
for (auto &ipv4_config : ipv4Data)
{
- if (!ipv4_config.address.empty())
- {
- ipv4_array.push_back({{"AddressOrigin", ipv4_config.origin},
- {"SubnetMask", ipv4_config.netmask},
- {"Address", ipv4_config.address}});
-
- if (!ipv4_config.gateway.empty())
- {
- ipv4_array.back()["Gateway"] = ipv4_config.gateway;
- }
- }
+ ipv4_array.push_back({{"AddressOrigin", ipv4_config.origin},
+ {"SubnetMask", ipv4_config.netmask},
+ {"Address", ipv4_config.address},
+ {"Gateway", ipv4_config.gateway}});
}
}
}