1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
#include "utils/dbus_utils.hpp"
#include "async_resp.hpp"
#include <boost/system/error_code.hpp>
#include <nlohmann/json.hpp>
#include <sdbusplus/message.hpp>
#include <memory>
#include <string>
#include <string_view>
namespace redfish
{
namespace details
{
void afterSetProperty(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
const std::string& redfishPropertyName,
const nlohmann::json& propertyValue,
const boost::system::error_code& ec,
const sdbusplus::message_t& msg)
{
if (ec)
{
if (ec.value() == boost::system::errc::permission_denied)
{
messages::insufficientPrivilege(asyncResp->res);
}
const sd_bus_error* dbusError = msg.get_error();
if (dbusError != nullptr)
{
std::string_view errorName(dbusError->name);
if (errorName == "xyz.openbmc_project.Common.Error.InvalidArgument")
{
BMCWEB_LOG_WARNING("DBUS response error: {}", ec);
messages::propertyValueIncorrect(
asyncResp->res, redfishPropertyName, propertyValue);
return;
}
if (errorName ==
"xyz.openbmc_project.State.Chassis.Error.BMCNotReady")
{
BMCWEB_LOG_WARNING(
"BMC not ready, operation not allowed right now");
messages::serviceTemporarilyUnavailable(asyncResp->res, "10");
return;
}
if (errorName == "xyz.openbmc_project.State.Host.Error.BMCNotReady")
{
BMCWEB_LOG_WARNING(
"BMC not ready, operation not allowed right now");
messages::serviceTemporarilyUnavailable(asyncResp->res, "10");
return;
}
if (errorName == "xyz.openbmc_project.Common.Error.NotAllowed")
{
messages::propertyNotWritable(asyncResp->res,
redfishPropertyName);
return;
}
}
BMCWEB_LOG_ERROR("D-Bus error setting Redfish Property {} ec={}",
redfishPropertyName, ec);
messages::internalError(asyncResp->res);
return;
}
// Only set 204 if another error hasn't already happened.
if (asyncResp->res.result() == boost::beast::http::status::ok)
{
asyncResp->res.result(boost::beast::http::status::no_content);
}
};
void afterSetPropertyAction(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
const std::string& redfishActionName,
const std::string& redfishActionParameterName,
const boost::system::error_code& ec,
const sdbusplus::message_t& /*msg*/)
{
if (ec)
{
if (ec.value() == boost::asio::error::invalid_argument)
{
BMCWEB_LOG_WARNING(
"Resource {} is patched with invalid argument during action {}",
redfishActionParameterName, redfishActionName);
if (redfishActionParameterName.empty())
{
messages::operationFailed(asyncResp->res);
}
else
{
messages::actionParameterValueError(asyncResp->res,
redfishActionParameterName,
redfishActionName);
}
return;
}
if (ec.value() == boost::asio::error::host_unreachable)
{
BMCWEB_LOG_WARNING(
"Resource {} is not found while performing action {}",
redfishActionParameterName, redfishActionName);
messages::resourceNotFound(asyncResp->res, "Actions",
redfishActionName);
return;
}
BMCWEB_LOG_ERROR("D-Bus error setting Redfish Property {} ec={}",
redfishActionParameterName, ec);
messages::internalError(asyncResp->res);
return;
}
// Only set 204 if another error hasn't already happened.
if (asyncResp->res.result() == boost::beast::http::status::ok)
{
asyncResp->res.result(boost::beast::http::status::no_content);
}
};
} // namespace details
} // namespace redfish
|