[Kimchi-devel] [PATCHv9 05/10] storage server: Update model and mockmodel

Aline Manera alinefm at linux.vnet.ibm.com
Thu Jan 23 13:02:41 UTC 2014


Reviewed-by: Aline Manera <alinefm at linux.vnet.ibm.com>

On 01/22/2014 02:13 PM, lvroyce at linux.vnet.ibm.com wrote:
> From: Royce Lv <lvroyce at linux.vnet.ibm.com>
>
> Query all storage pool to retrieve storage server we used.
> If no query param is given, all supported type will be listed.
> With param given, only specified type of server is listed.
>
> Signed-off-by: Royce Lv <lvroyce at linux.vnet.ibm.com>
> ---
>   src/kimchi/mockmodel.py | 30 ++++++++++++++++++++++++++++++
>   src/kimchi/model.py     | 30 ++++++++++++++++++++++++++++++
>   2 files changed, 60 insertions(+)
>
> diff --git a/src/kimchi/mockmodel.py b/src/kimchi/mockmodel.py
> index 4ef3fa6..9e7dcfd 100644
> --- a/src/kimchi/mockmodel.py
> +++ b/src/kimchi/mockmodel.py
> @@ -408,6 +408,36 @@ class MockModel(object):
>                       iso_volumes.append(res)
>           return iso_volumes
>
> +    def storageservers_get_list(self, _target_type=None):
> +        # FIXME: When added new storage server support, this needs to be updated
> +        target_type = kimchi.model.STORAGE_SOURCES.keys() \
> +            if not _target_type else [_target_type]
> +        pools = self.storagepools_get_list()
> +        server_list = []
> +        for pool in pools:
> +            try:
> +                pool_info = self.storagepool_lookup(pool)
> +                if (pool_info['type'] in target_type and
> +                        pool_info['source']['addr'] not in server_list):
> +                    server_list.append(pool_info['source']['addr'])
> +            except NotFoundError:
> +                pass
> +
> +        return server_list
> +
> +    def storageserver_lookup(self, server):
> +        pools = self.storagepools_get_list()
> +        for pool in pools:
> +            try:
> +                pool_info = self.storagepool_lookup(pool)
> +                if pool_info['source'] and pool_info['source']['addr'] == server:
> +                    return dict(host=server)
> +            except NotFoundError:
> +            # Avoid inconsistent pool result because of lease between list and lookup
> +                pass
> +
> +        raise NotFoundError("storage server %s not used by kimchi" % server)
> +
>       def dummy_interfaces(self):
>           interfaces = {}
>           ifaces = {"eth1": "nic", "bond0": "bonding",
> diff --git a/src/kimchi/model.py b/src/kimchi/model.py
> index ea528c6..67546b8 100644
> --- a/src/kimchi/model.py
> +++ b/src/kimchi/model.py
> @@ -1303,6 +1303,36 @@ class Model(object):
>               else:
>                   raise
>
> +    def storageservers_get_list(self, _target_type=None):
> +        target_type = STORAGE_SOURCES.keys() if not _target_type else [_target_type]
> +        pools = self.storagepools_get_list()
> +        server_list = []
> +        for pool in pools:
> +            try:
> +                pool_info = self.storagepool_lookup(pool)
> +                if (pool_info['type'] in target_type and
> +                        pool_info['source']['addr'] not in server_list):
> +                    # Avoid to add same server for multiple times
> +                    # if it hosts more than one storage type
> +                    server_list.append(pool_info['source']['addr'])
> +            except NotFoundError:
> +                pass
> +
> +        return server_list
> +
> +    def storageserver_lookup(self, server):
> +        pools = self.storagepools_get_list()
> +        for pool in pools:
> +            try:
> +                pool_info = self.storagepool_lookup(pool)
> +                if pool_info['source'] and pool_info['source']['addr'] == server:
> +                    return dict(host=server)
> +            except NotFoundError:
> +            # Avoid inconsistent pool result because of lease between list and lookup
> +                pass
> +
> +        raise NotFoundError('server %s does not used by kimchi' % server)
> +
>       def _get_screenshot(self, vm_uuid):
>           with self.objstore as session:
>               try:




More information about the Kimchi-devel mailing list