diff --git a/bin/ceilometer-agent-compute b/bin/ceilometer-agent-compute index 785172b7..d03a34cb 100755 --- a/bin/ceilometer-agent-compute +++ b/bin/ceilometer-agent-compute @@ -27,17 +27,9 @@ from ceilometer.service import prepare_service from ceilometer.openstack.common import cfg from ceilometer.openstack.common import service -from nova import flags -from nova.compute import manager as compute_manager - if __name__ == '__main__': - # Register the compute options from nova with our config object so - # our pollsters can figure out which compute driver the hypervisor - # is using. - cfg.CONF.register_opts(compute_manager.compute_opts) - prepare_service(sys.argv) mgr = manager.AgentManager() topic = 'ceilometer.agent.compute' diff --git a/ceilometer/compute/libvirt.py b/ceilometer/compute/libvirt.py index c389c994..948fe80f 100644 --- a/ceilometer/compute/libvirt.py +++ b/ceilometer/compute/libvirt.py @@ -22,7 +22,15 @@ import datetime from lxml import etree from nova import flags - +try: + from nova import config as nova_config +except ImportError: + # NOTE(dhellmann): We want to try to maintain compatibility + # with folsom for the time being, so set the name nova_config + # to a sentinal we can use to trigger different behavior + # when we try to set up the configuration object. + from nova import flags + nova_config = False from ceilometer import counter from ceilometer.compute import plugin from ceilometer.compute import instance as compute_instance @@ -30,14 +38,23 @@ from ceilometer.openstack.common import importutils from ceilometer.openstack.common import log from ceilometer.openstack.common import timeutils -FLAGS = flags.FLAGS - def _instance_name(instance): """Shortcut to get instance name""" return getattr(instance, 'OS-EXT-SRV-ATTR:instance_name', None) +def get_compute_driver(): + # FIXME(jd) This function is made to be destroyed by an abstraction + # layer in Nova providing an hypervisor agnostic API. + # XXX(jd) Folsom compat + if not nova_config: + flags.parse_args([]) + return flags.FLAGS.compute_driver + nova_config.parse_args([]) + return nova_config.CONF.compute_driver + + def get_libvirt_connection(): """Return an open connection for talking to libvirt.""" # The direct-import implementation only works with Folsom because @@ -45,11 +62,11 @@ def get_libvirt_connection(): try: try: return importutils.import_object_ns('nova.virt', - FLAGS.compute_driver, + get_compute_driver(), None) except TypeError: return importutils.import_object_ns('nova.virt', - FLAGS.compute_driver) + get_compute_driver()) except ImportError: # Fall back to the way it was done in Essex. import nova.virt.connection @@ -73,7 +90,7 @@ class LibVirtPollster(plugin.ComputePollster): def is_enabled(self): # Use a fairly liberal substring check. - return 'libvirt' in FLAGS.compute_driver.lower() + return 'libvirt' in get_compute_driver().lower() class InstancePollster(LibVirtPollster): diff --git a/ceilometer/service.py b/ceilometer/service.py index 0fb2b01f..fd8f4bff 100644 --- a/ceilometer/service.py +++ b/ceilometer/service.py @@ -18,16 +18,7 @@ # under the License. import os - -from nova import flags -try: - from nova import config as nova_config -except ImportError: - # NOTE(dhellmann): We want to try to maintain compatibility - # with folsom for the time being, so set the name nova_config - # to a sentinal we can use to trigger different behavior - # when we try to set up the configuration object. - nova_config = False +import socket from ceilometer.openstack.common import cfg from ceilometer.openstack.common import context @@ -38,7 +29,14 @@ from ceilometer.openstack.common.rpc import service as rpc_service cfg.CONF.register_opts([ cfg.IntOpt('periodic_interval', default=600, - help='seconds between running periodic tasks') + help='seconds between running periodic tasks'), + cfg.StrOpt('host', + default=socket.getfqdn(), + help='Name of this node. This can be an opaque identifier. ' + 'It is not necessarily a hostname, FQDN, or IP address. ' + 'However, the node name must be valid within ' + 'an AMQP key, and if using ZeroMQ, a valid ' + 'hostname, FQDN, or IP address'), ]) CLI_OPTIONS = [ @@ -60,8 +58,6 @@ CLI_OPTIONS = [ help='Auth URL to use for openstack service access'), ] cfg.CONF.register_cli_opts(CLI_OPTIONS) -cfg.CONF.register_cli_opts(flags.core_opts) -cfg.CONF.register_cli_opts(flags.global_opts) class PeriodicService(rpc_service.Service): @@ -80,22 +76,6 @@ def _sanitize_cmd_line(argv): return [a for a in argv if a in cli_opt_names] -def _init_nova_config(argv): - # NOTE(dhellmann): We want to try to maintain compatibility - # with folsom for the time being, so this function is - # just here to isolate the rest of the module from having - # to know how to configure different versions of nova. - if nova_config: - nova_config.parse_args(argv) - else: - flags.parse_args(argv) - - def prepare_service(argv=[]): cfg.CONF(argv[1:], project='ceilometer') - # FIXME(dhellmann): We must set up the nova.flags module in order - # to have the RPC and DB access work correctly because we are - # still using the Service object out of nova directly. We need to - # move that into openstack.common. - _init_nova_config(_sanitize_cmd_line(argv)) log.setup('ceilometer') diff --git a/ceilometer/tests/skip.py b/ceilometer/tests/skip.py index 643a7906..da58b6c5 100644 --- a/ceilometer/tests/skip.py +++ b/ceilometer/tests/skip.py @@ -73,14 +73,3 @@ class skip_unless(object): raise nose.SkipTest(self.message) func(*args, **kw) return _skipper - - -def skip_if_fake(func): - """Decorator that skips a test if running in fake mode.""" - def _skipper(*args, **kw): - """Wrapped skipper function.""" - if FLAGS.fake_tests: - raise unittest.SkipTest('Test cannot be run in fake mode') - else: - return func(*args, **kw) - return _skipper diff --git a/tools/notificationclient.py b/tools/notificationclient.py index b922e507..7a2d1d81 100755 --- a/tools/notificationclient.py +++ b/tools/notificationclient.py @@ -26,13 +26,11 @@ import logging import cPickle as pickle import sys -from nova import flags from nova import utils from ceilometer.openstack.common import cfg from ceilometer.openstack.common import rpc -FLAGS = flags.FLAGS LOG = logging.getLogger(__name__) @@ -91,8 +89,8 @@ def send_messages(connection, topic, input): def main(): - rpc.register_opts(FLAGS) - FLAGS.register_opts([ + rpc.register_opts(cfg.CONF) + cfg.CONF.register_opts([ cfg.StrOpt('datafile', default=None, help='Data file to read or write', @@ -105,7 +103,7 @@ def main(): ), ]) - remaining_args = FLAGS(sys.argv) + remaining_args = cfg.CONF(sys.argv) utils.monkey_patch() parser = argparse.ArgumentParser(