Created Bootstrapper to handle Nova bootstrapping logic.
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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()))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user