diff --git a/ccnode/interface.py b/ccnode/interface.py index 7e37d68506227e16bf3292acfd0aaebf431baf13..f783e0f89a1c53650c0f6be1c021cf211b854fb4 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 18c438e51b03ff20515e70b46d3aee3dd1e6601d..49a330ecb3af30f2e2dfc75ccbbae9f5dd1a3246 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