virthttp  0.0
libvirt http interface
StoragePool.hpp
Go to the documentation of this file.
1 #ifndef VIRTPP_IMPL_STORAGEPOOL_HPP
2 #define VIRTPP_IMPL_STORAGEPOOL_HPP
3 
4 #include <utility>
5 #include <libvirt/libvirt.h>
6 #include "../StoragePool.hpp"
7 #include "../StorageVol.hpp"
8 
9 namespace virt {
10 
11 inline StoragePool::StoragePool(StoragePool&& oth) noexcept : underlying(oth.underlying) { oth.underlying = nullptr; }
13  std::swap(underlying, oth.underlying);
14  return *this;
15 }
16 inline StoragePool::~StoragePool() noexcept { virStoragePoolFree(underlying); }
17 
18 constexpr inline StoragePool::operator bool() const noexcept { return underlying != nullptr; }
19 
20 inline bool StoragePool::build(BuildFlag flags) noexcept { return virStoragePoolBuild(underlying, to_integral(flags)) == 0; }
21 inline bool StoragePool::create(CreateFlag flags) noexcept { return virStoragePoolCreate(underlying, to_integral(flags)) == 0; }
22 inline bool StoragePool::delete_(DeleteFlag flags) noexcept { return virStoragePoolDelete(underlying, to_integral(flags)) == 0; }
23 inline bool StoragePool::destroy() noexcept { return virStoragePoolDestroy(underlying) == 0; }
24 
25 [[nodiscard]] inline TFE StoragePool::getAutostart() const noexcept {
26  int val = 0;
27  const auto res = virStoragePoolGetAutostart(underlying, &val);
28  return TFE{res + val};
29 }
30 
31 [[nodiscard]] inline Connection StoragePool::getConnect() const noexcept {
32  const auto ret = virStoragePoolGetConnect(underlying);
33  if (ret)
34  virConnectRef(ret);
35  return Connection{ret};
36 }
37 
38 [[nodiscard]] inline auto StoragePool::getInfo() const noexcept -> std::optional<Info> {
39  std::optional<Info> ret;
40  return virStoragePoolGetInfo(underlying, &ret.emplace()) == 0 ? ret : std::nullopt;
41 }
42 
43 [[nodiscard]] inline gsl::czstring<> StoragePool::getName() const noexcept { return virStoragePoolGetName(underlying); }
44 
45 [[nodiscard]] inline auto StoragePool::getUUID() const -> std::optional<std::array<unsigned char, VIR_UUID_BUFLEN>> {
46  std::optional<std::array<unsigned char, VIR_UUID_BUFLEN>> ret{};
47  return virStoragePoolGetUUID(underlying, ret.emplace().data()) == 0 ? ret : std::nullopt;
48 }
49 
50 [[nodiscard]] inline auto StoragePool::getUUIDString() const noexcept -> std::optional<std::array<char, VIR_UUID_STRING_BUFLEN>> {
51  std::optional<std::array<char, VIR_UUID_STRING_BUFLEN>> ret{};
52  return virStoragePoolGetUUIDString(underlying, ret.emplace().data()) == 0 ? ret : std::nullopt;
53 }
54 
55 [[nodiscard]] inline passive<gsl::czstring<>> StoragePool::getXMLDesc() const noexcept { return virStoragePoolGetXMLDesc(underlying, 0); }
56 
57 [[nodiscard]] inline TFE StoragePool::isActive() const noexcept { return TFE{virStoragePoolIsActive(underlying)}; }
58 [[nodiscard]] inline TFE StoragePool::isPersistent() const noexcept { return TFE{virStoragePoolIsPersistent(underlying)}; }
59 [[nodiscard]] inline auto StoragePool::listAllVolumes() const noexcept {
60  return meta::light::wrap_opram_owning_set_destroyable_arr<StorageVol>(underlying, virStoragePoolListAllVolumes, 0u);
61 }
62 [[nodiscard]] inline auto StoragePool::extractAllVolumes() const {
63  return meta::heavy::wrap_opram_owning_set_destroyable_arr<StorageVol>(underlying, virStoragePoolListAllVolumes, 0u);
64 }
65 [[nodiscard]] inline auto StoragePool::listVolumesNames() const noexcept {
66  return meta::light::wrap_oparm_owning_fill_freeable_arr(underlying, virStoragePoolNumOfVolumes, virStoragePoolListVolumes);
67 }
68 [[nodiscard]] inline int StoragePool::numOfVolumes() const noexcept { return virStoragePoolNumOfVolumes(underlying); }
69 inline bool StoragePool::refresh() noexcept { return virStoragePoolRefresh(underlying, 0) == 0; }
70 inline bool StoragePool::setAutostart(bool autostart) noexcept { return virStoragePoolSetAutostart(underlying, +autostart) == 0; }
71 inline bool StoragePool::undefine() noexcept { return virStoragePoolUndefine(underlying) == 0; }
72 
73 inline StoragePool StoragePool::createXML(Connection& conn, gsl::czstring<> xml, CreateFlag flags) {
74  return StoragePool{virStoragePoolCreateXML(conn.underlying, xml, to_integral(flags))};
75 }
76 inline StoragePool StoragePool::defineXML(Connection& conn, gsl::czstring<> xml) {
77  return StoragePool{virStoragePoolDefineXML(conn.underlying, xml, 0)};
78 }
79 
80 inline StorageVol StoragePool::volLookupByName(gsl::czstring<> name) const noexcept {
81  return StorageVol{virStorageVolLookupByName(underlying, name)};
82 }
83 
84 } // namespace virt
85 
86 #endif
auto listVolumesNames() const noexcept
Definition: StoragePool.hpp:65
bool setAutostart(bool autostart) noexcept
Definition: StoragePool.hpp:70
passive< gsl::czstring<> > getName() const noexcept
Definition: StoragePool.hpp:43
int numOfVolumes() const noexcept
Definition: StoragePool.hpp:68
static StoragePool createXML(Connection &conn, gsl::czstring<> xml, CreateFlag flags)
Definition: StoragePool.hpp:73
bool create(CreateFlag flags) noexcept
Definition: StoragePool.hpp:21
auto getInfo() const noexcept-> std::optional< Info >
Definition: StoragePool.hpp:38
static StoragePool defineXML(Connection &conn, gsl::czstring<> xml)
Definition: StoragePool.hpp:76
constexpr auto to_integral(E e) noexcept
Definition: Base.hpp:32
Definition: PoolBuildFlag.hpp:10
Connection getConnect() const noexcept
Definition: StoragePool.hpp:31
STL namespace.
Definition: Connection.hpp:47
T passive
Definition: utility.hpp:48
Definition: PoolDeleteFlag.hpp:10
auto wrap_oparm_owning_fill_freeable_arr(U underlying, CF count_fcn, DF data_fcn)
Definition: utility.hpp:276
Definition: PoolCreateFlag.hpp:10
Definition: StoragePool.hpp:67
TFE getAutostart() const noexcept
Definition: StoragePool.hpp:25
bool undefine() noexcept
Definition: StoragePool.hpp:71
~StoragePool() noexcept
Definition: StoragePool.hpp:16
bool build(BuildFlag flags) noexcept
Definition: StoragePool.hpp:20
Definition: AdminConnection.hpp:11
auto listAllVolumes() const noexcept
Definition: StoragePool.hpp:59
bool refresh() noexcept
Definition: StoragePool.hpp:69
TFE isActive() const noexcept
Definition: StoragePool.hpp:57
Definition: StoragePool.hpp:11
Definition: StorageVol.hpp:10
StorageVol volLookupByName(gsl::czstring<> name) const noexcept
Definition: StoragePool.hpp:80
auto getUUID() const -> std::optional< std::array< unsigned char, VIR_UUID_BUFLEN >>
Definition: StoragePool.hpp:45
auto getUUIDString() const noexcept-> std::optional< std::array< char, VIR_UUID_STRING_BUFLEN >>
Definition: StoragePool.hpp:50
bool delete_(DeleteFlag flags) noexcept
Definition: StoragePool.hpp:22
TFE isPersistent() const noexcept
Definition: StoragePool.hpp:58
bool destroy() noexcept
Definition: StoragePool.hpp:23
constexpr StoragePool & operator=(const StoragePool &) noexcept=delete
passive< gsl::czstring<> > getXMLDesc() const noexcept
Definition: StoragePool.hpp:55
Definition: tfe.hpp:4
constexpr StoragePool() noexcept=default
auto extractAllVolumes() const
Definition: StoragePool.hpp:62