From cc439720392c77c2fa4001be0f5c31bacf7315f5 Mon Sep 17 00:00:00 2001 From: Thibault VINCENT Date: Wed, 22 Dec 2010 11:07:35 +0100 Subject: [PATCH] storage: add wrappers for volume allocation and capacity --- ccnode/interface.py | 22 ++++++++++++++++++++++ ccnode/libvirtwrapper.py | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/ccnode/interface.py b/ccnode/interface.py index 7e37d68..f783e0f 100644 --- a/ccnode/interface.py +++ b/ccnode/interface.py @@ -289,3 +289,25 @@ class HVStorage(object): :type volume_name: :class:`str` :return: :class:`str` path to the volume file ''' + + def get_volume_allocation(self, pool, vol_name): + ''' + Returns the pool space used by this volume in bytes + + :param pool: the pool containing this volume from + :type pool: :class:`virStoragePool` + :param vol_name: name of the volume to query + :type vol_name: :class:`str` + :return: :class:`int` of allocation in bytes + ''' + + def get_volume_capacity(self, pool, vol_name): + ''' + Returns the capacity (usable space) of this volume in bytes + + :param pool: the pool containing this volume from + :type pool: :class:`virStoragePool` + :param vol_name: name of the volume to query + :type vol_name: :class:`str` + :return: :class:`int` of capacity in bytes + ''' diff --git a/ccnode/libvirtwrapper.py b/ccnode/libvirtwrapper.py index 18c438e..49a330e 100644 --- a/ccnode/libvirtwrapper.py +++ b/ccnode/libvirtwrapper.py @@ -504,6 +504,43 @@ class LibvirtHVStorage(HVStorage): except libvirt.libvirtError as e: raise StorageError("Volume has no path information (%s)" % e) + def get_volume_allocation(self, pool, vol_name): + ''' + Returns the pool space used by this volume in bytes + + :param pool: the pool containing this volume from + :type pool: :class:`virStoragePool` + :param vol_name: name of the volume to query + :type vol_name: :class:`str` + :return: :class:`int` of allocation in bytes + ''' + try: + vol = pool.storageVolLookupByName(vol_name) + except libvirt.libvirtError as e: + raise StorageError("Volume not found (%s)" % e) + try: + return vol.info()[2] + except libvirt.libvirtError as e: + raise StorageError("Volume has no allocation information (%s)" % e) + + def get_volume_capacity(self, pool, vol_name): + ''' + Returns the capacity (usable space) of this volume in bytes + + :param pool: the pool containing this volume from + :type pool: :class:`virStoragePool` + :param vol_name: name of the volume to query + :type vol_name: :class:`str` + :return: :class:`int` of capacity in bytes + ''' + try: + vol = pool.storageVolLookupByName(vol_name) + except libvirt.libvirtError as e: + raise StorageError("Volume not found (%s)" % e) + try: + return vol.info()[1] + except libvirt.libvirtError as e: + raise StorageError("Volume has no capacity information (%s)" % e) #### Helper functions -- GitLab