From ca2c68a492743e002ab7f4788aec2fd965702b6d Mon Sep 17 00:00:00 2001 From: Dan Smith <dansmith@redhat.com> Date: Wed, 1 Feb 2017 12:21:23 -0800 Subject: [PATCH] Add ability to query for ComputeNodes by their mapped value Related to blueprint discover-hosts-faster Change-Id: Ic0068e12cd19824789872e2aa3acaf64c96ccd6b --- nova/db/api.py | 13 +++++++++++++ nova/db/sqlalchemy/api.py | 8 ++++++++ 2 files changed, 21 insertions(+) diff --git a/nova/db/api.py b/nova/db/api.py index fd285e53d..377178404 100644 --- a/nova/db/api.py +++ b/nova/db/api.py @@ -254,6 +254,19 @@ def compute_node_get_all(context): return IMPL.compute_node_get_all(context) +def compute_node_get_all_mapped_less_than(context, mapped_less_than): + """Get all ComputeNode objects with specific mapped values. + + :param context: The security context + :param mapped_less_than: Get compute nodes with mapped less than this + value + + :returns: List of dictionaries each containing compute node properties + """ + return IMPL.compute_node_get_all_mapped_less_than(context, + mapped_less_than) + + def compute_node_get_all_by_pagination(context, limit=None, marker=None): """Get compute nodes by pagination. :param context: The security context diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index 80dad6dc5..498091737 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -625,6 +625,8 @@ def _compute_node_select(context, filters=None, limit=None, marker=None): if "hypervisor_hostname" in filters: hyp_hostname = filters["hypervisor_hostname"] select = select.where(cn_tbl.c.hypervisor_hostname == hyp_hostname) + if "mapped" in filters: + select = select.where(cn_tbl.c.mapped < filters['mapped']) if marker is not None: try: compute_node_get(context, marker) @@ -702,6 +704,12 @@ def compute_node_get_all(context): return _compute_node_fetchall(context) +@pick_context_manager_reader +def compute_node_get_all_mapped_less_than(context, mapped_less_than): + return _compute_node_fetchall(context, + {'mapped': mapped_less_than}) + + @pick_context_manager_reader def compute_node_get_all_by_pagination(context, limit=None, marker=None): return _compute_node_fetchall(context, limit=limit, marker=marker)