[Kimchi-devel] [PATCH] model.host: avoid redundant libvirt lookupByName API invocation

Sheldon shaohef at linux.vnet.ibm.com
Wed May 28 09:56:40 UTC 2014


Reviewed-by: ShaoHe Feng <shaohef at linux.vnet.ibm.com>

On 05/28/2014 05:52 PM, Zhou Zheng Sheng wrote:
> In HostModel._get_vms_list_by_state(), it gets a list of domain objects
> and extracts the names, then it traverses the names and calls
> lookupByName(name) to get domain objects. This is redundant because it
> has a list of domain object already.
>
> This patch fixes the problem.
>
> Signed-off-by: Zhou Zheng Sheng <zhshzhou at linux.vnet.ibm.com>
> ---
>   src/kimchi/model/host.py | 12 +++---------
>   1 file changed, 3 insertions(+), 9 deletions(-)
>
> diff --git a/src/kimchi/model/host.py b/src/kimchi/model/host.py
> index e9ac487..5844f4b 100644
> --- a/src/kimchi/model/host.py
> +++ b/src/kimchi/model/host.py
> @@ -104,15 +104,9 @@ class HostModel(object):
>
>       def _get_vms_list_by_state(self, state):
>           conn = self.conn.get()
> -        names = [dom.name().decode('utf-8') for dom in conn.listAllDomains(0)]
> -
> -        ret_list = []
> -        for name in names:
> -            dom = conn.lookupByName(name.encode("utf-8"))
> -            info = dom.info()
> -            if (DOM_STATE_MAP[info[0]]) == state:
> -                ret_list.append(name)
> -        return ret_list
> +        return [dom.name().decode('utf-8')
> +                for dom in conn.listAllDomains(0)
> +                if (DOM_STATE_MAP[dom.info()[0]]) == state]
>
>
>   class HostStatsModel(object):


-- 
Thanks and best regards!

Sheldon Feng(冯少合)<shaohef at linux.vnet.ibm.com>
IBM Linux Technology Center




More information about the Kimchi-devel mailing list