Skip to content
Snippets Groups Projects
Commit cf264fe7 authored by Thibault VINCENT's avatar Thibault VINCENT
Browse files

storage api cleanup, added storage usage methods

parent b581e5fb
No related branches found
No related tags found
No related merge requests found
......@@ -172,25 +172,13 @@ class HVStorage(object):
:param hypervisor: in instance of :class:`Hypervisor`
'''
def get_backend_type(self):
'''
Returns the type of backend used for storage
'''
pass
def get_storage_pools(self):
def get_pools(self):
'''
Returns a dict of storage pools bound to the host
'''
pass
def get_space_statistics(self):
'''
Returns informations about space available in the storage object
'''
pass
def get_storage_volumes(self, pool=None):
def get_volumes(self, pool=None):
'''
Returns volumes stored in pool or all pools
'''
......@@ -218,7 +206,7 @@ class HVStorage(object):
Adds a volume to the specified pool
:param pool: the pool in which to create the volume
:type pool: :class:`str`
:type pool: :class:`virStoragePool`
:param name: name of the new volume
:type name: :class:`str`
:param space: size of the new volume in gigabytes
......@@ -231,7 +219,7 @@ class HVStorage(object):
Deletes a volume in the specified pool
:param pool: the pool in which delete the volume
:type pool: :class:`str`
:type pool: :class:`virStoragePool`
:param name: the name of the volume
:type name: :class:`str`
'''
......@@ -247,22 +235,37 @@ class HVStorage(object):
pool is suitable
'''
def get_pool_info(self, pool):
def get_pool_state(self, pool):
'''
Returns informations about the pool
Returns the running state of the pool
:param pool: the storage pool name
:type pool: libvirt.`virStoragePool`
'''
pass
def get_vol_info(self, vol):
def get_pool_total_space(self, pool):
'''
Returns informations about the volume
Returns the storage capacity of this pool in gigabytes
:param pool: the pool to get information from
:type pool: :class:`virStoragePool`
:return: :class:`int` of capacity in gigabytes
'''
def get_pool_available_space(self, pool):
'''
Returns available space of this storage pool in gigabytes
:param pool: the pool to get information from
:type pool: :class:`virStoragePool`
:return: :class:`int` of available free space in gigabytes
'''
def get_pool_used_space(self, pool):
'''
Returns current storage pool usage in gigabytes
:param pool: the pool to get information from
:type pool: :class:`virStoragePool`
:return: :class:`int` of used space in gigabytes
'''
......@@ -333,35 +333,23 @@ class LibvirtHVStorage(HVStorage):
self._pools = dict([(p, pool_obj(self.hv_handle._con_handle, p)) \
for p in pools])
def get_storage_pools(self):
return self._pools
def get_pool_info(self, pool):
pool_info = {}
pool_info[POOL_NAME] = pool.name()
pool_info[POOL_STATUS] = self.get_pool_state(pool)
pool_info[POOL_TOTAL_SIZE] = self.get_pool_size(pool) / GIGABYTE_DIV
return pool_info
def get_pool_size(self, pool):
def get_pools(self):
'''
Returns total logical size of the pool
:param pool: the storage pool
:type pool: :class:`libvirt.virStoragePool`
Returns a dict of storage pools bound to the host
'''
return pool.info()[1]
return self._pools
def get_pool_state(self, pool):
def get_volumes(self, pool=None):
'''
Returns the running state of the pool
:param pool: the storage pool name
:type pool: libvirt.`virStoragePool`
Returns volumes stored in pool or all pools
'''
return POOL_STATE[pool.info()[0]]
volumes = []
if pool is None:
for pool in self._pools.iteritems():
volumes.extend(pool[1].listVolumes())
else:
volumes = pool.listVolumes()
return volumes
def add_volume(self, pool, name, space):
'''
......@@ -423,6 +411,45 @@ class LibvirtHVStorage(HVStorage):
raise StorageError("Can't query pool informations (%s)" % e)
return False
def get_pool_state(self, pool):
'''
Returns the running state of the pool
:param pool: the storage pool name
:type pool: libvirt.`virStoragePool`
'''
return POOL_STATE[pool.info()[0]]
def get_pool_total_space(self, pool):
'''
Returns the storage capacity of this pool in gigabytes
:param pool: the pool to get information from
:type pool: :class:`virStoragePool`
:return: :class:`int` of capacity in gigabytes
'''
return pool.info()[1];
def get_pool_available_space(self, pool):
'''
Returns available space of this storage pool in gigabytes
:param pool: the pool to get information from
:type pool: :class:`virStoragePool`
:return: :class:`int` of available free space in gigabytes
'''
return pool.info()[2];
def get_pool_used_space(self, pool):
'''
Returns current storage pool usage in gigabytes
:param pool: the pool to get information from
:type pool: :class:`virStoragePool`
:return: :class:`int` of used space in gigabytes
'''
return pool.info()[3];
#### Helper functions
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment