diff options
author | termie <github@anarkystic.com> | 2011-02-23 15:14:16 -0800 |
---|---|---|
committer | termie <github@anarkystic.com> | 2011-02-23 15:14:16 -0800 |
commit | 24090232272e0db163060e0ca32dbf97c05120c9 (patch) | |
tree | c4b605caf028637d3c1d8d8d203bb6bbd5e40f1c /nova/service.py | |
parent | cd301d67506bcb6d67d921492435e9d7d56aafb1 (diff) | |
download | nova-24090232272e0db163060e0ca32dbf97c05120c9.tar.gz nova-24090232272e0db163060e0ca32dbf97c05120c9.tar.xz nova-24090232272e0db163060e0ca32dbf97c05120c9.zip |
updates to nova.flags to get help working better
Fixes some old bugs that were brought up on the mailing list.
First step towards moving flags into the places where they belong.
Also moves manager import into service's init so that we can get all the
dynamically loaded flags shortly after loading.
Diffstat (limited to 'nova/service.py')
-rw-r--r-- | nova/service.py | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/nova/service.py b/nova/service.py index cc88ac233..f47358089 100644 --- a/nova/service.py +++ b/nova/service.py @@ -45,15 +45,10 @@ FLAGS = flags.FLAGS flags.DEFINE_integer('report_interval', 10, 'seconds between nodes reporting state to datastore', lower_bound=1) - flags.DEFINE_integer('periodic_interval', 60, 'seconds between running periodic tasks', lower_bound=1) -flags.DEFINE_flag(flags.HelpFlag()) -flags.DEFINE_flag(flags.HelpshortFlag()) -flags.DEFINE_flag(flags.HelpXMLFlag()) - class Service(object): """Base class for workers that run on hosts.""" @@ -64,6 +59,8 @@ class Service(object): self.binary = binary self.topic = topic self.manager_class_name = manager + manager_class = utils.import_class(self.manager_class_name) + self.manager = manager_class(host=self.host, *args, **kwargs) self.report_interval = report_interval self.periodic_interval = periodic_interval super(Service, self).__init__(*args, **kwargs) @@ -71,9 +68,9 @@ class Service(object): self.timers = [] def start(self): - manager_class = utils.import_class(self.manager_class_name) - self.manager = manager_class(host=self.host, *self.saved_args, - **self.saved_kwargs) + vcs_string = version.version_string_with_vcs() + logging.audit(_("Starting %(topic)s node (version %(vcs_string)s)"), + {'topic': self.topic, 'vcs_string': vcs_string}) self.manager.init_host() self.model_disconnected = False ctxt = context.get_admin_context() @@ -153,9 +150,6 @@ class Service(object): report_interval = FLAGS.report_interval if not periodic_interval: periodic_interval = FLAGS.periodic_interval - vcs_string = version.version_string_with_vcs() - logging.audit(_("Starting %(topic)s node (version %(vcs_string)s)") - % locals()) service_obj = cls(host, binary, topic, manager, report_interval, periodic_interval) @@ -217,8 +211,19 @@ class Service(object): def serve(*services): - if not services: - services = [Service.create()] + try: + if not services: + services = [Service.create()] + except Exception: + logging.exception('in Service.create()') + raise + finally: + # After we've loaded up all our dynamic bits, check + # whether we should print help + flags.DEFINE_flag(flags.HelpFlag()) + flags.DEFINE_flag(flags.HelpshortFlag()) + flags.DEFINE_flag(flags.HelpXMLFlag()) + FLAGS.ParseNewFlags() name = '_'.join(x.binary for x in services) logging.debug(_("Serving %s"), name) |