aodh/ceilometer/compute/nova_notifier/folsom.py
Doug Hellmann 7d8bd50d08 Decouple the nova notifier from ceilometer code
The move to oslo.config introduced a conflict in the nova notifier
because both nova and ceilometer have copies of the
openstack.common.rpc library and define an option for the AMQP
exchange name for the project. This changeset decouples the notifier
plugin in ceilometer from most of the ceilometer code, to remove that
conflict.

The nova notifier is rewritten to emit a new notification message with
event type `compute.instance.delete.samples` instead of making the old
RPC calls directly to the ceilometer collector, and a notification
listener plugin is provided to convert those messages to sample data.

The notifier implementations are split between the one that worked
in folsom and the one that works in grizzly to maintain backwards
compatibility.

get_hypervisor_inspector() is moved to a location where it can be
imported both by the compute agent manager and the notifier
plugin. The definition of `disabled_compute_pollsters` option is also
moved for the same reason.

The tox configuration is changed to run the nova notifier tests
separately from the other tests, since nose cannot import nova and
ceilometer code in the same process.

bug 1130952

Change-Id: I39ba4564c9c14f09dbdd768d7a83f6940e3942ad
Signed-off-by: Doug Hellmann <doug.hellmann@dreamhost.com>
2013-02-26 14:22:27 -05:00

68 lines
2.2 KiB
Python

# -*- encoding: utf-8 -*-
#
# Copyright © 2012 New Dream Network, LLC (DreamHost)
#
# Author: Julien Danjou <julien@danjou.info>
#
# 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.
__all__ = [
'notify',
'initialize_manager',
]
from oslo.config import cfg
from ceilometer.openstack.common import log as logging
from ceilometer.compute.manager import AgentManager
from nova import db as instance_info_source
# This module runs inside the nova compute
# agent, which only configures the "nova" logger.
# We use a fake logger name in that namespace
# so that messages from this module appear
# in the log file.
LOG = logging.getLogger('nova.ceilometer.notifier')
_agent_manager = None
def initialize_manager(agent_manager=None):
global _agent_manager
if not agent_manager:
cfg.CONF(args=[], project='ceilometer', prog='ceilometer-agent')
# Instantiate a manager
_agent_manager = AgentManager()
else:
_agent_manager = agent_manager
_agent_manager.setup_notifier_task()
def notify(context, message):
global _agent_manager
# Initialize the global config object as though it was in the
# compute agent process so that the ceilometer copy of the rpc
# modules will know how to communicate.
if _agent_manager is None:
initialize_manager()
if message['event_type'] == 'compute.instance.delete.start':
instance_id = message['payload']['instance_id']
LOG.debug('polling final stats for %r', instance_id)
_agent_manager.poll_instance(context,
instance_info_source.instance_get_by_uuid(
context,
instance_id))