OpenStack Image Management (Glance)
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.

versions.py 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. # Copyright 2012 OpenStack Foundation.
  2. # All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  5. # not use this file except in compliance with the License. You may obtain
  6. # a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. # License for the specific language governing permissions and limitations
  14. # under the License.
  15. from oslo_config import cfg
  16. from oslo_log import log as logging
  17. from oslo_serialization import jsonutils
  18. from six.moves import http_client
  19. import webob.dec
  20. from glance.common import wsgi
  21. from glance.i18n import _, _LW
  22. versions_opts = [
  23. cfg.StrOpt('public_endpoint',
  24. help=_("""
  25. Public url endpoint to use for Glance versions response.
  26. This is the public url endpoint that will appear in the Glance
  27. "versions" response. If no value is specified, the endpoint that is
  28. displayed in the version's response is that of the host running the
  29. API service. Change the endpoint to represent the proxy URL if the
  30. API service is running behind a proxy. If the service is running
  31. behind a load balancer, add the load balancer's URL for this value.
  32. Possible values:
  33. * None
  34. * Proxy URL
  35. * Load balancer URL
  36. Related options:
  37. * None
  38. """)),
  39. ]
  40. CONF = cfg.CONF
  41. CONF.register_opts(versions_opts)
  42. LOG = logging.getLogger(__name__)
  43. class Controller(object):
  44. """A wsgi controller that reports which API versions are supported."""
  45. def index(self, req, explicit=False):
  46. """Respond to a request for all OpenStack API versions."""
  47. def build_version_object(version, path, status):
  48. url = CONF.public_endpoint or req.host_url
  49. return {
  50. 'id': 'v%s' % version,
  51. 'status': status,
  52. 'links': [
  53. {
  54. 'rel': 'self',
  55. 'href': '%s/%s/' % (url, path),
  56. },
  57. ],
  58. }
  59. version_objs = []
  60. if CONF.enable_v2_api:
  61. version_objs.extend([
  62. build_version_object(2.6, 'v2', 'CURRENT'),
  63. build_version_object(2.5, 'v2', 'SUPPORTED'),
  64. build_version_object(2.4, 'v2', 'SUPPORTED'),
  65. build_version_object(2.3, 'v2', 'SUPPORTED'),
  66. build_version_object(2.2, 'v2', 'SUPPORTED'),
  67. build_version_object(2.1, 'v2', 'SUPPORTED'),
  68. build_version_object(2.0, 'v2', 'SUPPORTED'),
  69. ])
  70. if CONF.enable_v1_api:
  71. LOG.warn(_LW('The Images (Glance) v1 API is deprecated and will '
  72. 'be removed on or after the Pike release, following '
  73. 'the standard OpenStack deprecation policy. '
  74. 'Currently, the solution is to set '
  75. 'enable_v1_api=False and enable_v2_api=True in your '
  76. 'glance-api.conf file. Once those options are '
  77. 'removed from the code, Images (Glance) v2 API will '
  78. 'be switched on by default and will be the only '
  79. 'option to deploy and use.'))
  80. version_objs.extend([
  81. build_version_object(1.1, 'v1', 'DEPRECATED'),
  82. build_version_object(1.0, 'v1', 'DEPRECATED'),
  83. ])
  84. status = explicit and http_client.OK or http_client.MULTIPLE_CHOICES
  85. response = webob.Response(request=req,
  86. status=status,
  87. content_type='application/json')
  88. response.body = jsonutils.dump_as_bytes(dict(versions=version_objs))
  89. return response
  90. @webob.dec.wsgify(RequestClass=wsgi.Request)
  91. def __call__(self, req):
  92. return self.index(req)
  93. def create_resource(conf):
  94. return wsgi.Resource(Controller())