Merge "Refactoring/cleanup of compute and db apis"
This commit is contained in:
commit
27f317e30a
@ -132,15 +132,6 @@ def service_get_all(context, disabled=None):
|
||||
return IMPL.service_get_all(context, disabled)
|
||||
|
||||
|
||||
def service_does_host_exist(context, host_name, include_disabled=False):
|
||||
"""Returns True if 'host_name' is found in the services table, False
|
||||
otherwise
|
||||
:param: host_name - the name of the host we want to check if it exists
|
||||
:param: include_disabled - Set to True to include hosts from disabled
|
||||
services"""
|
||||
return IMPL.service_does_host_exist(context, host_name, include_disabled)
|
||||
|
||||
|
||||
def service_get_all_by_topic(context, topic):
|
||||
"""Get all services for a given topic."""
|
||||
return IMPL.service_get_all_by_topic(context, topic)
|
||||
@ -159,15 +150,6 @@ def service_get_by_compute_host(context, host):
|
||||
return IMPL.service_get_by_compute_host(context, host)
|
||||
|
||||
|
||||
def service_get_all_compute_sorted(context):
|
||||
"""Get all compute services sorted by instance count.
|
||||
|
||||
:returns: a list of (Service, instance_count) tuples.
|
||||
|
||||
"""
|
||||
return IMPL.service_get_all_compute_sorted(context)
|
||||
|
||||
|
||||
def service_get_by_args(context, host, binary):
|
||||
"""Get the state of a service by node name and binary."""
|
||||
return IMPL.service_get_by_args(context, host, binary)
|
||||
|
@ -396,45 +396,6 @@ def service_get_by_compute_host(context, host):
|
||||
return result
|
||||
|
||||
|
||||
@require_admin_context
|
||||
def _service_get_all_topic_subquery(context, session, topic, subq, label):
|
||||
sort_value = getattr(subq.c, label)
|
||||
return model_query(context, models.Service,
|
||||
func.coalesce(sort_value, 0),
|
||||
session=session, read_deleted="no").\
|
||||
filter_by(topic=topic).\
|
||||
filter_by(disabled=False).\
|
||||
outerjoin((subq, models.Service.host == subq.c.host)).\
|
||||
order_by(sort_value).\
|
||||
all()
|
||||
|
||||
|
||||
@require_admin_context
|
||||
def service_get_all_compute_sorted(context):
|
||||
session = get_session()
|
||||
with session.begin():
|
||||
# NOTE(vish): The intended query is below
|
||||
# SELECT services.*, COALESCE(inst_cores.instance_cores,
|
||||
# 0)
|
||||
# FROM services LEFT OUTER JOIN
|
||||
# (SELECT host, SUM(instances.vcpus) AS instance_cores
|
||||
# FROM instances GROUP BY host) AS inst_cores
|
||||
# ON services.host = inst_cores.host
|
||||
topic = CONF.compute_topic
|
||||
label = 'instance_cores'
|
||||
subq = model_query(context, models.Instance.host,
|
||||
func.sum(models.Instance.vcpus).label(label),
|
||||
base_model=models.Instance, session=session,
|
||||
read_deleted="no").\
|
||||
group_by(models.Instance.host).\
|
||||
subquery()
|
||||
return _service_get_all_topic_subquery(context,
|
||||
session,
|
||||
topic,
|
||||
subq,
|
||||
label)
|
||||
|
||||
|
||||
@require_admin_context
|
||||
def service_get_by_args(context, host, binary):
|
||||
result = model_query(context, models.Service).\
|
||||
|
Loading…
x
Reference in New Issue
Block a user