From 7e29a8bf626a01630c40bfd56bee2df336540ad2 Mon Sep 17 00:00:00 2001 From: Erik Skultety Date: Wed, 24 May 2023 09:37:23 +0200 Subject: libvirt_wrapper: Add helpers to lookup a libvirt volume by path One of the helpers is just an error handling wrapper over the plain libvirt API while the other wraps the libvirt object with our class. Signed-off-by: Erik Skultety --- lcitool/libvirt_wrapper.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lcitool/libvirt_wrapper.py b/lcitool/libvirt_wrapper.py index 237c972..7f1eda7 100644 --- a/lcitool/libvirt_wrapper.py +++ b/lcitool/libvirt_wrapper.py @@ -147,6 +147,18 @@ class LibvirtStoragePoolObject(LibvirtAbstractObject): self._path = path_node.text return Path(self._path) + @staticmethod + def _lookup_volume_by_path(conn, path): + try: + return conn.storageVolLookupByPath(path) + except libvirt.libvirtError: + return None + + def _volume_by_path(self, path): + volobj = self._lookup_volume_by_path(self._conn, path) + if volobj: + return LibvirtStorageVolObject(self, volobj) + def create_volume(self, name, capacity, allocation=None, _format="qcow2", units='bytes', owner=None, group=None, mode=None,): -- cgit v1.1