6 #include <libvirt/libvirt.h> 7 #include "../Connection.hpp" 8 #include "../Network.hpp" 9 #include "../utility.hpp" 17 underlying = net.underlying;
18 net.underlying =
nullptr;
24 virNetworkFree(underlying);
30 const auto res = virNetworkGetConnect(underlying);
41 std::array<unsigned char, VIR_UUID_BUFLEN> ret{};
42 return virNetworkGetUUID(underlying, ret.data()) == 0 ? std::optional(ret) : std::nullopt;
46 std::array<char, VIR_UUID_STRING_BUFLEN> ret{};
47 return virNetworkGetUUIDString(underlying, ret.data()) == 0 ? std::optional(ret) : std::nullopt;
52 ret.resize(VIR_UUID_STRING_BUFLEN);
53 if (virNetworkGetUUIDString(underlying, ret.data()) != 0)
55 ret.resize(std::strlen(ret.data()));
65 const auto res = virNetworkGetXMLDesc(underlying,
to_integral(flags));
66 const auto ret = std::string{res};
76 using RetType = std::optional<std::unique_ptr<virNetworkDHCPLeasePtr[], void (*)(virNetworkDHCPLeasePtr*)>>;
77 virNetworkDHCPLeasePtr* lease_arr;
78 auto res = virNetworkGetDHCPLeases(underlying, mac, &lease_arr, 0);
80 return RetType{std::nullopt};
81 return std::optional{std::unique_ptr<virNetworkDHCPLeasePtr[], void (*)(virNetworkDHCPLeasePtr*)>(lease_arr, [](
auto arr) {
84 virNetworkDHCPLeaseFree(*it);
90 virNetworkDHCPLeasePtr* lease_arr;
91 auto res = virNetworkGetDHCPLeases(underlying, mac, &lease_arr, 0);
94 std::vector<virNetworkDHCPLease> ret{};
96 std::for_each(lease_arr, lease_arr + res, [&](virNetworkDHCPLeasePtr v) {
98 virNetworkDHCPLeaseFree(v);
107 inline bool Network::setAutostart(
bool autostart) noexcept {
return virNetworkSetAutostart(underlying, autostart) == 0; }
111 const auto res = virNetworkGetAutostart(underlying, &v);
112 return TFE{res == 0 ? v : -1};
bool create() noexcept
Definition: Network.hpp:115
auto extractDHCPLeases(gsl::czstring<> mac) const -> std::optional< std::vector< virNetworkDHCPLease >>
Definition: Network.hpp:89
std::string extractName() const noexcept
Definition: Network.hpp:38
void freeany(T ptr)
Definition: utility.hpp:50
bool setAutostart(bool autostart) noexcept
Definition: Network.hpp:107
constexpr auto to_integral(E e) noexcept
Definition: Base.hpp:32
TFE getAutostart() const noexcept
Definition: Network.hpp:109
Definition: Connection.hpp:47
T passive
Definition: utility.hpp:48
bool destroy() noexcept
Definition: Network.hpp:117
auto getDHCPLeases(gsl::czstring<> mac) const noexcept
Definition: Network.hpp:75
Connection getConnect() const noexcept
Definition: Network.hpp:29
passive< const char * > getName() const noexcept
Definition: Network.hpp:36
TFE isPersistent() const noexcept
Definition: Network.hpp:73
Definition: utility.hpp:122
~Network() noexcept
Definition: Network.hpp:22
static Network defineXML(Connection &conn, gsl::czstring<> xml)
Definition: Network.hpp:122
Definition: AdminConnection.hpp:11
Definition: Network.hpp:14
TFE isActive() const noexcept
Definition: Network.hpp:71
Network & operator=(const Network &)=delete
UniqueZstring getBridgeName() const noexcept
Definition: Network.hpp:27
constexpr Network() noexcept=default
std::string extractXMLDesc(enums::network::XMLFlags flags=enums::network::XMLFlags::DEFAULT) const noexcept
Definition: Network.hpp:64
auto getUUID() const noexcept
Definition: Network.hpp:40
UniqueZstring getXMLDesc(enums::network::XMLFlags flags=enums::network::XMLFlags::DEFAULT) const noexcept
Definition: Network.hpp:60
static Network createXML(Connection &conn, gsl::czstring<> xml)
Definition: Network.hpp:121
auto extractUUIDString() const -> std::string
Definition: Network.hpp:50
bool undefine() noexcept
Definition: Network.hpp:119
Definition: XMLFlags.hpp:8
auto getUUIDString() const noexcept-> std::optional< std::array< char, VIR_UUID_STRING_BUFLEN >>
Definition: Network.hpp:45