Container Infrastructure Management Service for OpenStack
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

api.py 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # Copyright 2013 - Red Hat, Inc.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. """Starter script for the Magnum API service."""
  15. import os
  16. import sys
  17. from oslo_concurrency import processutils
  18. from oslo_log import log as logging
  19. from oslo_reports import guru_meditation_report as gmr
  20. from werkzeug import serving
  21. from magnum.api import app as api_app
  22. from magnum.common import profiler
  23. from magnum.common import service
  24. import magnum.conf
  25. from magnum.i18n import _
  26. from magnum.i18n import _LI
  27. from magnum.objects import base
  28. from magnum import version
  29. CONF = magnum.conf.CONF
  30. LOG = logging.getLogger(__name__)
  31. def _get_ssl_configs(use_ssl):
  32. if use_ssl:
  33. cert_file = CONF.api.ssl_cert_file
  34. key_file = CONF.api.ssl_key_file
  35. if cert_file and not os.path.exists(cert_file):
  36. raise RuntimeError(
  37. _("Unable to find cert_file : %s") % cert_file)
  38. if key_file and not os.path.exists(key_file):
  39. raise RuntimeError(
  40. _("Unable to find key_file : %s") % key_file)
  41. return cert_file, key_file
  42. else:
  43. return None
  44. def main():
  45. service.prepare_service(sys.argv)
  46. gmr.TextGuruMeditation.setup_autorun(version)
  47. # Enable object backporting via the conductor
  48. base.MagnumObject.indirection_api = base.MagnumObjectIndirectionAPI()
  49. app = api_app.load_app()
  50. # Setup OSprofiler for WSGI service
  51. profiler.setup('magnum-api', CONF.host)
  52. # SSL configuration
  53. use_ssl = CONF.api.enabled_ssl
  54. # Create the WSGI server and start it
  55. host, port = CONF.api.host, CONF.api.port
  56. LOG.info(_LI('Starting server in PID %s'), os.getpid())
  57. LOG.debug("Configuration:")
  58. CONF.log_opt_values(LOG, logging.DEBUG)
  59. LOG.info(_LI('Serving on %(proto)s://%(host)s:%(port)s'),
  60. dict(proto="https" if use_ssl else "http", host=host, port=port))
  61. workers = CONF.api.workers
  62. if not workers:
  63. workers = processutils.get_worker_count()
  64. LOG.info(_LI('Server will handle each request in a new process up to'
  65. ' %s concurrent processes'), workers)
  66. serving.run_simple(host, port, app, processes=workers,
  67. ssl_context=_get_ssl_configs(use_ssl))