summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Lamar <brian.lamar@rackspace.com>2011-06-23 21:31:00 -0400
committerBrian Lamar <brian.lamar@rackspace.com>2011-06-23 21:31:00 -0400
commit655a783d5a0ef2ddadcf119793cd34513a45fe27 (patch)
tree0c48676a13c628c802028d2e3c6402de10cd6051
parent2690e31bbd8c515771ca69a0a73e9ff5761a9079 (diff)
downloadnova-655a783d5a0ef2ddadcf119793cd34513a45fe27.tar.gz
nova-655a783d5a0ef2ddadcf119793cd34513a45fe27.tar.xz
nova-655a783d5a0ef2ddadcf119793cd34513a45fe27.zip
Created Bootstrapper to handle Nova bootstrapping logic.
-rwxr-xr-xbin/nova-api5
-rw-r--r--nova/service.py36
-rw-r--r--nova/utils.py37
3 files changed, 41 insertions, 37 deletions
diff --git a/bin/nova-api b/bin/nova-api
index 121f6f9a0..ea99a1b48 100755
--- a/bin/nova-api
+++ b/bin/nova-api
@@ -25,17 +25,18 @@ Starts both the EC2 and OpenStack APIs in separate processes.
import sys
-import nova.log
import nova.service
+import nova.utils
def main():
"""Launch EC2 and OSAPI services."""
- launcher = nova.service.Launcher(sys.argv)
+ nova.utils.Bootstrapper.bootstrap_binary(sys.argv)
ec2 = nova.service.WSGIService("ec2")
osapi = nova.service.WSGIService("osapi")
+ launcher = nova.service.Launcher()
launcher.launch_service(ec2)
launcher.launch_service(osapi)
diff --git a/nova/service.py b/nova/service.py
index 41c6551e0..00e4f61e5 100644
--- a/nova/service.py
+++ b/nova/service.py
@@ -60,47 +60,13 @@ flags.DEFINE_string('api_paste_config', "api-paste.ini",
class Launcher(object):
"""Launch one or more services and wait for them to complete."""
- def __init__(self, flags=None):
+ def __init__(self):
"""Initialize the service launcher.
- :param flags: Flags to use for the services we're going to load.
:returns: None
"""
self._services = []
- self._version = version.version_string_with_vcs()
- self._flags = flags
- self._setup_flags()
- self._setup_logging()
- self._log_flags()
-
- def _setup_logging(self):
- """Logic to ensure logging is going to work correctly for services.
-
- :returns: None
-
- """
- logging.setup()
- logging.audit(_("Nova Version (%(_version)s)") % self.__dict__)
-
- def _setup_flags(self):
- """Logic to ensure flags/configuration are correctly set.
-
- :returns: None
-
- """
- utils.default_flagfile(args=self._flags)
- FLAGS(self._flags or [])
- flags.DEFINE_flag(flags.HelpFlag())
- flags.DEFINE_flag(flags.HelpshortFlag())
- flags.DEFINE_flag(flags.HelpXMLFlag())
- FLAGS.ParseNewFlags()
-
- def _log_flags(self):
- LOG.debug(_("Full set of FLAGS:"))
- for flag in FLAGS:
- flag_get = FLAGS.get(flag, None)
- LOG.debug("%(flag)s : %(flag_get)s" % locals())
@staticmethod
def run_service(service):
diff --git a/nova/utils.py b/nova/utils.py
index a9b0f3128..a6b8d4cbe 100644
--- a/nova/utils.py
+++ b/nova/utils.py
@@ -743,3 +743,40 @@ def is_uuid_like(val):
if not isinstance(val, basestring):
return False
return (len(val) == 36) and (val.count('-') == 4)
+
+
+class Bootstrapper(object):
+ """Provides environment bootstrapping capabilities for entry points."""
+
+ @staticmethod
+ def bootstrap_binary(argv):
+ """Initialize the Nova environment using command line arguments."""
+ Bootstrapper.setup_flags(argv)
+ Bootstrapper.setup_logging()
+ Bootstrapper.log_flags()
+
+ @staticmethod
+ def setup_logging():
+ """Initialize logging and log a message indicating the Nova version."""
+ logging.setup()
+ logging.audit(_("Nova Version (%s)") %
+ version.version_string_with_vcs())
+
+ @staticmethod
+ def setup_flags(input_flags):
+ """Initialize flags, load flag file, and print help if needed."""
+ default_flagfile(args=input_flags)
+ FLAGS(input_flags or [])
+ flags.DEFINE_flag(flags.HelpFlag())
+ flags.DEFINE_flag(flags.HelpshortFlag())
+ flags.DEFINE_flag(flags.HelpXMLFlag())
+ FLAGS.ParseNewFlags()
+
+ @staticmethod
+ def log_flags():
+ """Log the list of all active flags being used."""
+ logging.audit(_("Currently active flags:"))
+ for key in FLAGS:
+ value = FLAGS.get(key, None)
+ logging.audit(_("%(key)s : %(value)s" % locals()))
+