pike版的nova/cmd/api.py代码如下
import sys
from oslo_log import log as logging
from oslo_reports import guru_meditation_report as gmr
import nova.conf
from nova import config
from nova import exception
from nova import objects
from nova import service
from nova import utils
from nova import version
CONF = nova.conf.CONF
def main():
config.parse_args(sys.argv)
logging.setup(CONF, "nova")
utils.monkey_patch()
objects.register_all()
if 'osapi_compute' in CONF.enabled_apis:
# NOTE(mriedem): This is needed for caching the nova-compute service
# version.
objects.Service.enable_min_version_cache()
log = logging.getLogger(__name__)
gmr.TextGuruMeditation.setup_autorun(version)
launcher = service.process_launcher()
started = 0
for api in CONF.enabled_apis:
should_use_ssl = api in CONF.enabled_ssl_apis
try:
server = service.WSGIService(api, use_ssl=should_use_ssl)
launcher.launch_service(server, workers=server.workers or 1)
started += 1
except exception.PasteAppNotFound as ex:
log.warning("%s. ``enabled_apis`` includes bad values. "
"Fix to remove this warning.", ex)
if started == 0:
log.error('No APIs were started. '
'Check the enabled_apis config option.')
sys.exit(1)
launcher.wait()
变量CONF在文件nova/conf/__init__.py中定义,其中有一行service.register_opts(CONF),在文件nova/conf/service.py中有以下代码
cfg.ListOpt('enabled_apis',
item_type=cfg.types.String(choices=['osapi_compute',
'metadata']),
default=['osapi_compute', 'metadata'],
help="List of APIs to be enabled by default."),
cfg.ListOpt('enabled_ssl_apis',
default=[],
help="""
List of APIs with enabled SSL.
Nova provides SSL support for the API servers. enabled_ssl_apis option
allows configuring the SSL support.
"""),
定义了enabled_apis数组中的一项为osapi_compute,nova/cmd/api.py中的核心代码为
server = service.WSGIService(api, use_ssl=should_use_ssl)
launcher.launch_service(server, workers=server.workers or 1)
WSGIService的定义在nova/service.py文件中,代码如下
class WSGIService(service.Service):
"""Provides ability to launch API from a 'paste' configuration