3 #include <rapidjson/rapidjson.h> 40 template <
class... Args>
auto error(Args... args)
const noexcept {
return json_res.
error(args...); };
53 -> std::optional<virt::enums::connection::list::networks::Flag> {
55 auto flags = Flag::DEFAULT;
57 flags |= *activity ? Flag::ACTIVE : Flag::INACTIVE;
58 if (
auto persistence =
target.
getBool(
"persistent"); persistence)
59 flags |= *persistence ? Flag::PERSISTENT : Flag::TRANSIENT;
61 flags |= *autostart ? Flag::AUTOSTART : Flag::NO_AUTOSTART;
71 template <
class... Args>
auto error(Args... args)
const noexcept {
return json_res.
error(args...); };
81 const auto create_nw = [&](std::string_view xml) {
85 rapidjson::Value res_val;
87 res_val.AddMember(
"created",
true,
json_res.GetAllocator());
93 return create_nw(obj.GetString());
95 for (
const auto & item : obj.GetArray()) {
107 rapidjson::Value res_val;
108 auto& jalloc =
json_res.GetAllocator();
110 if (path_parts.size() < 5) {
111 rapidjson::Value json_active;
115 logger.
error(
"Error occurred while getting network status");
120 rapidjson::Value json_AS;
124 logger.
error(
"Error occurred while getting network autostart policy");
129 rapidjson::Value json_is_persistent;
133 logger.
error(
"Error occurred while getting network persistence");
136 json_is_persistent =
to_json(tfe);
140 res_val.AddMember(
"name", rapidjson::Value(nw.
getName(), jalloc), jalloc);
142 res_val.AddMember(
"active", json_active, jalloc);
143 res_val.AddMember(
"autostart", json_AS, jalloc);
144 res_val.AddMember(
"persistent", json_is_persistent, jalloc);
145 if (path_parts.size() == 4)
154 4,
target, res_val,
json_res.GetAllocator(), [&](
auto... args) {
return error(args...); });
162 const auto& action_obj = *action.MemberBegin();
163 const auto& [action_name, action_val] = action_obj;
164 const auto hdl =
network_actions_table[std::string_view{action_name.GetString(), action_name.GetStringLength()}];
169 auto& jalloc =
json_res.GetAllocator();
170 const auto success = [&] {
171 rapidjson::Value res_val;
173 res_val.AddMember(
"deleted",
true, jalloc);
177 const auto failure = [&] {
178 rapidjson::Value msg_val;
184 return nw.
undefine() ? success() : failure();
auto extractDHCPLeases(gsl::czstring<> mac) const -> std::optional< std::vector< virNetworkDHCPLease >>
Definition: Network.hpp:89
DependsOutcome
Definition: depends.hpp:11
NetworkUnawareHandlers(HandlerContext &ctx)
Definition: network.hpp:43
auto to_json(const virt::TypedParams &tp, JAllocator &&jalloc) noexcept-> rapidjson::Value
Definition: virt2json.hpp:6
Definition: network.hpp:34
constexpr auto gen_jdispatchers(const std::tuple< JDVs... > &tup) noexcept-> std::array< JDispatch, sizeof...(JDVs)>
Definition: dispatch.hpp:115
void error(int code)
Definition: json_utils.hpp:57
TFE getAutostart() const noexcept
Definition: Network.hpp:109
auto create(const rapidjson::Value &obj) -> DependsOutcome override
Definition: network.hpp:80
std::tuple< JDispatchVals< JAll >, JDispatchVals< JAll >, JDispatchVals< JAll >, JDispatchVals< JAll >> NetworkJDispatcherVals
Definition: network.hpp:18
Logger logger
Definition: logger.hpp:58
const TargetParser & target
the incoming request's URI target
Definition: hdl_ctx.hpp:14
static constexpr auto search_all_flags(const TargetParser &target) noexcept-> std::optional< virt::enums::connection::list::networks::Flag >
Definition: network.hpp:52
void error(Ts...msg)
Definition: logger.hpp:25
NetworkActionsTable network_actions_table
Definition: dispatch.hpp:20
constexpr auto subquery
Perfect-forwarding lifted subq_impl::subquery.
Definition: flagwork.hpp:242
constexpr auto network_jdispatchers
Definition: network.hpp:28
virt::Connection & conn
the connection to perform libvirt operations through (plans to change to a vector) ...
Definition: hdl_ctx.hpp:12
passive< const char * > getName() const noexcept
Definition: Network.hpp:36
auto vacuum(const rapidjson::Value &action) -> DependsOutcome override
Definition: network.hpp:168
Definition: hdl_ctx.hpp:11
TFE isPersistent() const noexcept
Definition: Network.hpp:73
Definition: Network.hpp:14
TFE isActive() const noexcept
Definition: Network.hpp:71
JsonRes & json_res
the result of running the handlers to be sent to the client
Definition: hdl_ctx.hpp:13
UniqueZstring getBridgeName() const noexcept
Definition: Network.hpp:27
const auto fwd_as_if_err(int code)
Definition: hdl_ctx.hpp:32
void result(T &&val)
Definition: json_utils.hpp:45
Definition: network.hpp:70
constexpr bool err() const noexcept
Definition: tfe.hpp:11
constexpr auto parameterized_depends_scope(Fcns &&...depends) noexcept((std::is_nothrow_move_constructible_v< Fcns > &&...))
Definition: flagwork.hpp:60
auto alter(const rapidjson::Value &action) -> DependsOutcome override
Definition: network.hpp:161
constexpr const std::vector< std::string_view > & getPathParts() const noexcept
Definition: urlparser.hpp:83
NetworkHandlers(HandlerContext &ctx, virt::Network &nw)
Definition: network.hpp:78
UniqueZstring getXMLDesc(enums::network::XMLFlags flags=enums::network::XMLFlags::DEFAULT) const noexcept
Definition: Network.hpp:60
void message(T &&val)
Definition: json_utils.hpp:50
static Network createXML(Connection &conn, gsl::czstring<> xml)
Definition: Network.hpp:121
#define SUBQ_LIFT(mem_fn)
Definition: flagwork.hpp:15
auto extractLastError() -> Error
Definition: Error.hpp:44
Definition: urlparser.hpp:36
auto extractUUIDString() const -> std::string
Definition: Network.hpp:50
auto query(const rapidjson::Value &action) -> DependsOutcome override
Definition: network.hpp:106
bool undefine() noexcept
Definition: Network.hpp:119
constexpr std::optional< bool > getBool(std::string_view key) const noexcept
Definition: urlparser.hpp:91
constexpr NetworkJDispatcherVals network_jdispatcher_vals
Definition: network.hpp:23