diff options
author | Sunitha Harish <sunithaharish04@gmail.com> | 2019-04-01 03:57:25 -0500 |
---|---|---|
committer | Ed Tanous <ed.tanous@intel.com> | 2019-04-05 19:45:40 +0000 |
commit | 08244d0221ff404a2e240706138a827d97892039 (patch) | |
tree | 3d81853559a0114e412fed39b127b8604d4a0f20 /redfish-core/lib/ethernet.hpp | |
parent | e12814035e9fca6c543b3c15cc721740e3d38592 (diff) | |
download | bmcweb-08244d0221ff404a2e240706138a827d97892039.tar.gz bmcweb-08244d0221ff404a2e240706138a827d97892039.zip |
Redfish(Network): VLAN PATCH fix
This patch set fixes the issue at the Patch operation on VLAN resource.
Before this for any new value of VLANId , the patch command used to apply
value 1 as the new VLANId
Tested by :
GET https://${bmc}/redfish/v1/Managers/bmc/EthernetInterfaces/eth0/VLANs/eth0_10
PATCH https://${bmc}/redfish/v1/Managers/bmc/EthernetInterfaces/eth0/VLANs/eth0_10 -d '{ "VLANId" : 12, "VLANEnable": true}'
PATCH https://${bmc}/redfish/v1/Managers/bmc/EthernetInterfaces/eth0/VLANs/eth0_10 -d '{ "VLANId" : 20, "VLANEnable": false}'
Signed-off-by: Sunitha Harish <sunithaharish04@gmail.com>
Change-Id: Ia18e58816e6c78c8609e0daa558bc66d6914568e
Diffstat (limited to 'redfish-core/lib/ethernet.hpp')
-rw-r--r-- | redfish-core/lib/ethernet.hpp | 110 |
1 files changed, 46 insertions, 64 deletions
diff --git a/redfish-core/lib/ethernet.hpp b/redfish-core/lib/ethernet.hpp index 25dff50..8ba3f1c 100644 --- a/redfish-core/lib/ethernet.hpp +++ b/redfish-core/lib/ethernet.hpp @@ -894,52 +894,6 @@ class EthernetInterface : public Node {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; } - // TODO(kkowalsk) Find a suitable class/namespace for this - static void handleVlanPatch(const std::string &ifaceId, bool vlanEnable, - uint64_t vlanId, - const EthernetInterfaceData ðData, - const std::shared_ptr<AsyncResp> asyncResp) - { - // VLAN is configured on the interface - if (vlanEnable == true) - { - // Change VLAN Id - asyncResp->res.jsonValue["VLANId"] = vlanId; - auto callback = [asyncResp](const boost::system::error_code ec) { - if (ec) - { - messages::internalError(asyncResp->res); - } - else - { - asyncResp->res.jsonValue["VLANEnable"] = true; - } - }; - crow::connections::systemBus->async_method_call( - std::move(callback), "xyz.openbmc_project.Network", - "/xyz/openbmc_project/network/" + ifaceId, - "org.freedesktop.DBus.Properties", "Set", - "xyz.openbmc_project.Network.VLAN", "Id", - std::variant<uint32_t>(vlanId)); - } - else - { - auto callback = [asyncResp](const boost::system::error_code ec) { - if (ec) - { - messages::internalError(asyncResp->res); - return; - } - asyncResp->res.jsonValue["VLANEnable"] = false; - }; - - crow::connections::systemBus->async_method_call( - std::move(callback), "xyz.openbmc_project.Network", - "/xyz/openbmc_project/network/" + ifaceId, - "xyz.openbmc_project.Object.Delete", "Delete"); - } - } - private: void handleHostnamePatch(const std::string &hostname, const std::shared_ptr<AsyncResp> asyncResp) @@ -1522,27 +1476,55 @@ class VlanNetworkInterface : public Node // Get single eth interface data, and call the below callback for JSON // preparation - getEthernetIfaceData( - ifaceId, - [this, asyncResp, parentIfaceId, ifaceId, vlanEnable, vlanId]( - const bool &success, const EthernetInterfaceData ðData, - const boost::container::flat_set<IPv4AddressData> &ipv4Data) { - if (!success) - { - // TODO(Pawel)consider distinguish between non existing - // object, and other errors - messages::resourceNotFound( - asyncResp->res, "VLAN Network Interface", ifaceId); - - return; - } - + getEthernetIfaceData(params[1], [this, asyncResp, + parentIfaceId{std::string(params[0])}, + ifaceId{std::string(params[1])}, + &vlanEnable, &vlanId]( + const bool &success, + const EthernetInterfaceData + ðData, + const boost::container::flat_set< + IPv4AddressData> &ipv4Data) { + if (success && !ethData.vlan_id.empty()) + { parseInterfaceData(asyncResp->res.jsonValue, parentIfaceId, ifaceId, ethData, ipv4Data); + auto callback = + [asyncResp](const boost::system::error_code ec) { + if (ec) + { + messages::internalError(asyncResp->res); + } + }; - EthernetInterface::handleVlanPatch(ifaceId, vlanId, vlanEnable, - ethData, asyncResp); - }); + if (vlanEnable == true) + { + crow::connections::systemBus->async_method_call( + std::move(callback), "xyz.openbmc_project.Network", + "/xyz/openbmc_project/network/" + ifaceId, + "org.freedesktop.DBus.Properties", "Set", + "xyz.openbmc_project.Network.VLAN", "Id", + std::variant<uint32_t>(vlanId)); + } + else + { + BMCWEB_LOG_DEBUG + << "vlanEnable is false. Deleting the vlan interface"; + crow::connections::systemBus->async_method_call( + std::move(callback), "xyz.openbmc_project.Network", + std::string("/xyz/openbmc_project/network/") + ifaceId, + "xyz.openbmc_project.Object.Delete", "Delete"); + } + } + else + { + // TODO(Pawel)consider distinguish between non existing + // object, and other errors + messages::resourceNotFound(asyncResp->res, + "VLAN Network Interface", ifaceId); + return; + } + }); } void doDelete(crow::Response &res, const crow::Request &req, |