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.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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_log import log as logging
  18. from oslo_reports import guru_meditation_report as gmr
  19. from werkzeug import serving
  20. from magnum.api import app as api_app
  21. from magnum.common import profiler
  22. from magnum.common import service
  23. import magnum.conf
  24. from magnum.i18n import _
  25. from magnum.i18n import _LI
  26. from magnum.objects import base
  27. from magnum import version
  28. CONF = magnum.conf.CONF
  29. LOG = logging.getLogger(__name__)
  30. def _get_ssl_configs(use_ssl):
  31. if use_ssl:
  32. cert_file = CONF.api.ssl_cert_file
  33. key_file = CONF.api.ssl_key_file
  34. if cert_file and not os.path.exists(cert_file):
  35. raise RuntimeError(
  36. _("Unable to find cert_file : %s") % cert_file)
  37. if key_file and not os.path.exists(key_file):
  38. raise RuntimeError(
  39. _("Unable to find key_file : %s") % key_file)
  40. return cert_file, key_file
  41. else:
  42. return None
  43. def main():
  44. service.prepare_service(sys.argv)
  45. gmr.TextGuruMeditation.setup_autorun(version)
  46. # Enable object backporting via the conductor
  47. base.MagnumObject.indirection_api = base.MagnumObjectIndirectionAPI()
  48. app = api_app.load_app()
  49. # Setup OSprofiler for WSGI service
  50. profiler.setup('magnum-api', CONF.host)
  51. # SSL configuration
  52. use_ssl = CONF.api.enabled_ssl
  53. # Create the WSGI server and start it
  54. host, port = CONF.api.host, CONF.api.port
  55. LOG.info(_LI('Starting server in PID %s'), os.getpid())
  56. LOG.debug("Configuration:")
  57. CONF.log_opt_values(LOG, logging.DEBUG)
  58. LOG.info(_LI('Serving on %(proto)s://%(host)s:%(port)s'),
  59. dict(proto="https" if use_ssl else "http", host=host, port=port))
  60. serving.run_simple(host, port, app,
  61. ssl_context=_get_ssl_configs(use_ssl))