Commit a3d519a2 authored by Thibault VINCENT's avatar Thibault VINCENT
Browse files

fixed lack or code reuse

parent 856c8ef2
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -180,7 +180,7 @@ class HVStorage(object):

    def get_storage_pools(self):
        '''
        Returns a list of storage pools bound to the host
        Returns a dict of storage pools bound to the host
        '''
        pass

@@ -239,12 +239,12 @@ class HVStorage(object):

    def find_space(self, new_space):
        '''
        Tries to find a suitable chunk of space to store new_space.
        Tries to find a suitable chunk of space for volume allocation.

        :param new_space: a space size in gigabytes
        :type new_space: :class:`str`
        :return: a :class:`tuple` of possible locations or :class:`False` if no
            space is suitable
        :return: a :class:`tuple` of best location or :class:`False` if no
            pool is suitable
        '''

    def get_pool_info(self, pool):
+9 −15
Original line number Diff line number Diff line
@@ -330,11 +330,11 @@ class LibvirtHVStorage(HVStorage):
        pools = []
        pools.extend(self.hv_handle._con_handle.listDefinedStoragePools())
        pools.extend(self.hv_handle._con_handle.listStoragePools())
        self._pools = []
        self._pools.extend(pool_obj(self.hv_handle._con_handle, pool) for pool in pools)
        self._pools = dict([(p, pool_obj(self.hv_handle._con_handle, p)) \
            for p in pools])

    def get_storage_pools(self):
        return [pool.name() for pool in self._pools]
        return self._pools

    def get_pool_info(self, pool):
        pool_info = {}
@@ -408,23 +408,17 @@ class LibvirtHVStorage(HVStorage):

    def find_space(self, new_space):
        '''
        Tries to find a suitable chunk of space to store new_space.
        Tries to find a suitable chunk of space for volume allocation.

        :param new_space: a space size in gigabytes
        :type new_space: :class:`str`
        :return: a :class:`tuple` of possible locations or :class:`False` if no
            space is suitable
        :return: a :class:`tuple` of best location or :class:`False` if no
            pool is suitable
        '''
        pool_names = self.hv_handle._con_handle.listStoragePools()
        for pool_name in pool_names:
        for pool in self._pools.iteritems():
            try:
                pool = self.hv_handle._con_handle \
                    .storagePoolLookupByName(pool_name)
            except libvirt.libvirtError as e:
                raise StorageError("Failed to fetch pool data (%s)" % e)
            try:
                if new_space * GIGABYTE_DIV < pool.info()[3]:
                    return (pool_name)
                if new_space * GIGABYTE_DIV < pool[1].info()[3]:
                    return (pool)
            except libvirt.libvirtError as e:
                raise StorageError("Can't query pool informations (%s)" % e)
        return False