diff options
author | Erik Skultety <eskultet@redhat.com> | 2023-05-24 09:37:23 +0200 |
---|---|---|
committer | Erik Skultety <eskultet@redhat.com> | 2023-06-22 12:05:04 +0000 |
commit | 7e29a8bf626a01630c40bfd56bee2df336540ad2 (patch) | |
tree | 5f4a1e94c6587b24bbbe8f3b25e82ec6ce4dda32 | |
parent | 76b82a29a9a5e56e222f3c94e4480987220b4181 (diff) | |
download | libvirt-ci-7e29a8bf626a01630c40bfd56bee2df336540ad2.zip libvirt-ci-7e29a8bf626a01630c40bfd56bee2df336540ad2.tar.gz libvirt-ci-7e29a8bf626a01630c40bfd56bee2df336540ad2.tar.bz2 |
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 <eskultet@redhat.com>
-rw-r--r-- | lcitool/libvirt_wrapper.py | 12 |
1 files changed, 12 insertions, 0 deletions
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,): |