Merge "Move db access out into a seperate file."
This commit is contained in:
commit
5a21eee3c6
@ -19,6 +19,7 @@
|
|||||||
from nova import manager
|
from nova import manager
|
||||||
|
|
||||||
from ceilometer import extension_manager
|
from ceilometer import extension_manager
|
||||||
|
from ceilometer.compute import resources
|
||||||
from ceilometer.openstack.common import cfg
|
from ceilometer.openstack.common import cfg
|
||||||
from ceilometer.openstack.common import log
|
from ceilometer.openstack.common import log
|
||||||
from ceilometer import publish
|
from ceilometer import publish
|
||||||
@ -38,6 +39,9 @@ PLUGIN_NAMESPACE = 'ceilometer.poll.central'
|
|||||||
|
|
||||||
|
|
||||||
class AgentManager(manager.Manager):
|
class AgentManager(manager.Manager):
|
||||||
|
def __init__(self, host=None):
|
||||||
|
super(AgentManager, self).__init__(host=host)
|
||||||
|
self.resources = resources.Resources()
|
||||||
|
|
||||||
def init_host(self):
|
def init_host(self):
|
||||||
self.ext_manager = extension_manager.ActivatedExtensionManager(
|
self.ext_manager = extension_manager.ActivatedExtensionManager(
|
||||||
|
@ -21,6 +21,7 @@ from nova import manager
|
|||||||
from ceilometer import extension_manager
|
from ceilometer import extension_manager
|
||||||
from ceilometer.openstack.common import cfg
|
from ceilometer.openstack.common import cfg
|
||||||
from ceilometer.openstack.common import log
|
from ceilometer.openstack.common import log
|
||||||
|
from ceilometer.compute import resources
|
||||||
from ceilometer import publish
|
from ceilometer import publish
|
||||||
|
|
||||||
OPTS = [
|
OPTS = [
|
||||||
@ -40,6 +41,10 @@ PLUGIN_NAMESPACE = 'ceilometer.poll.compute'
|
|||||||
|
|
||||||
class AgentManager(manager.Manager):
|
class AgentManager(manager.Manager):
|
||||||
|
|
||||||
|
def __init__(self, host=None):
|
||||||
|
super(AgentManager, self).__init__(host=host)
|
||||||
|
self.resources = resources.Resources()
|
||||||
|
|
||||||
def init_host(self):
|
def init_host(self):
|
||||||
self.ext_manager = extension_manager.ActivatedExtensionManager(
|
self.ext_manager = extension_manager.ActivatedExtensionManager(
|
||||||
namespace=PLUGIN_NAMESPACE,
|
namespace=PLUGIN_NAMESPACE,
|
||||||
@ -75,8 +80,6 @@ class AgentManager(manager.Manager):
|
|||||||
|
|
||||||
def periodic_tasks(self, context, raise_on_error=False):
|
def periodic_tasks(self, context, raise_on_error=False):
|
||||||
"""Tasks to be run at a periodic interval."""
|
"""Tasks to be run at a periodic interval."""
|
||||||
# FIXME(dhellmann): How do we get a list of instances without
|
for instance in self.resources.instance_get_all_by_host(context):
|
||||||
# talking directly to the database?
|
|
||||||
for instance in self.db.instance_get_all_by_host(context, self.host):
|
|
||||||
if instance['vm_state'] != 'error':
|
if instance['vm_state'] != 'error':
|
||||||
self.poll_instance(context, instance)
|
self.poll_instance(context, instance)
|
||||||
|
37
ceilometer/compute/resources.py
Normal file
37
ceilometer/compute/resources.py
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
# a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
# License for the specific language governing permissions and limitations
|
||||||
|
# under the License.
|
||||||
|
|
||||||
|
from ceilometer.openstack.common import cfg
|
||||||
|
from nova.openstack.common import importutils
|
||||||
|
|
||||||
|
|
||||||
|
db_driver_opt = cfg.StrOpt('db_driver',
|
||||||
|
default='nova.db',
|
||||||
|
help='driver to use for database access')
|
||||||
|
|
||||||
|
|
||||||
|
cfg.CONF.register_opt(db_driver_opt)
|
||||||
|
|
||||||
|
|
||||||
|
# FIXME(dhellmann): How do we get a list of instances without
|
||||||
|
# talking directly to the database?
|
||||||
|
class Resources(object):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.db = importutils.import_module(cfg.CONF.db_driver)
|
||||||
|
|
||||||
|
def instance_get_all_by_host(self, context):
|
||||||
|
return self.db.instance_get_all_by_host(context, cfg.CONF.host)
|
||||||
|
|
||||||
|
def floating_ip_get_all(self, context):
|
||||||
|
return self.db.floating_ip_get_all(context)
|
@ -31,7 +31,7 @@ class FloatingIPPollster(plugin.CentralPollster):
|
|||||||
|
|
||||||
def get_counters(self, manager, context):
|
def get_counters(self, manager, context):
|
||||||
try:
|
try:
|
||||||
ips = manager.db.floating_ip_get_all(context)
|
ips = manager.resources.floating_ip_get_all(context)
|
||||||
except exception.FloatingIpNotFoundForHost:
|
except exception.FloatingIpNotFoundForHost:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
|
@ -84,10 +84,10 @@ class TestRunTasks(base.TestCase):
|
|||||||
stillborn_instance = mock.MagicMock()
|
stillborn_instance = mock.MagicMock()
|
||||||
stillborn_instance.name = 'stillborn'
|
stillborn_instance.name = 'stillborn'
|
||||||
stillborn_instance.vm_state = 'error'
|
stillborn_instance.vm_state = 'error'
|
||||||
self.mox.StubOutWithMock(self.mgr.db, 'instance_get_all_by_host')
|
self.mox.StubOutWithMock(self.mgr.resources,
|
||||||
self.mgr.db.instance_get_all_by_host(
|
'instance_get_all_by_host')
|
||||||
None,
|
self.mgr.resources.instance_get_all_by_host(
|
||||||
self.mgr.host,
|
None
|
||||||
).AndReturn([self.instance, stillborn_instance])
|
).AndReturn([self.instance, stillborn_instance])
|
||||||
|
|
||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user