Merge "Refactoring/cleanup of compute and db apis"
This commit is contained in:
commit
bdb3b3c092
@ -91,7 +91,6 @@ compute_opts = [
|
||||
CONF = cfg.CONF
|
||||
CONF.register_opts(compute_opts)
|
||||
CONF.import_opt('compute_topic', 'nova.compute.rpcapi')
|
||||
CONF.import_opt('consoleauth_topic', 'nova.consoleauth')
|
||||
CONF.import_opt('enable', 'nova.cells.opts', group='cells')
|
||||
|
||||
MAX_USERDATA_SIZE = 65535
|
||||
@ -902,9 +901,9 @@ class API(base.Base):
|
||||
def trigger_provider_fw_rules_refresh(self, context):
|
||||
"""Called when a rule is added/removed from a provider firewall."""
|
||||
|
||||
host_names = [x['host'] for (x, idx)
|
||||
in self.db.service_get_all_compute_sorted(context)]
|
||||
for host_name in host_names:
|
||||
for service in self.db.service_get_all_by_topic(context,
|
||||
CONF.compute_topic):
|
||||
host_name = service['host']
|
||||
self.compute_rpcapi.refresh_provider_fw_rules(context, host_name)
|
||||
|
||||
def update_state(self, context, instance, new_state):
|
||||
|
@ -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).\
|
||||
|
@ -298,8 +298,6 @@ class NetworkManager(manager.SchedulerDependentManager):
|
||||
self.network_api = network_api.API()
|
||||
self.network_rpcapi = network_rpcapi.NetworkAPI()
|
||||
self.security_group_api = compute_api.SecurityGroupAPI()
|
||||
self.compute_api = compute_api.API(
|
||||
security_group_api=self.security_group_api)
|
||||
self.servicegroup_api = servicegroup.API()
|
||||
|
||||
# NOTE(tr3buchet: unless manager subclassing NetworkManager has
|
||||
|
Loading…
Reference in New Issue
Block a user