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

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@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): -- 1.9.3

Reviewed-by: ShaoHe Feng <shaohef@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@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@linux.vnet.ibm.com> IBM Linux Technology Center

Reviewed-by: Crístian Viana <vianac@linux.vnet.ibm.com> On 28-05-2014 06:52, 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@linux.vnet.ibm.com>
participants (4)
-
Aline Manera
-
Crístian Viana
-
Sheldon
-
Zhou Zheng Sheng