From d4e13d7c5836e9914b94b74d3f5daaf0f00b1c25 Mon Sep 17 00:00:00 2001 From: "Kevin L. Mitchell" Date: Wed, 27 Jun 2012 18:44:35 -0500 Subject: [PATCH] Add hypervisor information extension. Adds a new extension to get information about hypervisors (as opposed to compute hosts), including a list of hypervisors matching a regular expression (database regular expression, i.e., %'s) and a list of hypervisors with the list of instances living on those hypervisors. Change-Id: I2e44e82e123e5e727b49622fe5e966131658f9f6 --- nova/db/api.py | 10 ++++++++++ nova/db/sqlalchemy/api.py | 13 +++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/nova/db/api.py b/nova/db/api.py index dc859f748..989864a2b 100644 --- a/nova/db/api.py +++ b/nova/db/api.py @@ -188,11 +188,21 @@ def service_update(context, service_id, values): ################### +def compute_node_get(context, compute_id): + """Get a computeNode.""" + return IMPL.compute_node_get(context, compute_id) + + def compute_node_get_all(context): """Get all computeNodes.""" return IMPL.compute_node_get_all(context) +def compute_node_search_by_hypervisor(context, hypervisor_match): + """Get computeNodes given a hypervisor hostname match string.""" + return IMPL.compute_node_search_by_hypervisor(context, hypervisor_match) + + def compute_node_create(context, values): """Create a computeNode from the values dictionary.""" return IMPL.compute_node_create(context, values) diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index 55effd645..d573690cc 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -473,7 +473,7 @@ def service_update(context, service_id, values): ################### -def _compute_node_get(context, compute_id, session=None): +def compute_node_get(context, compute_id, session=None): result = model_query(context, models.ComputeNode, session=session).\ filter_by(id=compute_id).\ first() @@ -491,6 +491,15 @@ def compute_node_get_all(context, session=None): all() +@require_admin_context +def compute_node_search_by_hypervisor(context, hypervisor_match): + field = models.ComputeNode.hypervisor_hostname + return model_query(context, models.ComputeNode).\ + options(joinedload('service')).\ + filter(field.like('%%%s%%' % hypervisor_match)).\ + all() + + def _get_host_utilization(context, host, ram_mb, disk_gb): """Compute the current utilization of a given host.""" instances = instance_get_all_by_host(context, host) @@ -542,7 +551,7 @@ def compute_node_update(context, compute_id, values, auto_adjust): if auto_adjust: _adjust_compute_node_values_for_utilization(context, values, session) with session.begin(subtransactions=True): - compute_ref = _compute_node_get(context, compute_id, session=session) + compute_ref = compute_node_get(context, compute_id, session=session) compute_ref.update(values) compute_ref.save(session=session)