Files
nova/nova/api/openstack/compute/versions.py
T
Ken'ichi Ohmichi 1830870718 Add min/max of API microversions to version API
As nova-spec api-microversions, versions API needs to expose minimum
and maximum microversions to version API, because clients need to
know available microversions through the API. That is very important
for the interoperability.
This patch adds these versions as the nova-spec mentioned.

Note:
  As v2(not v2.1) API change manner, we have added new extensions if
  changing API. However, this patch doesn't add a new extension even
  if adding new parameters "version" and "min_version" because version
  API is independent from both v2 and v2.1 APIs.

Closes-Bug: #1443375

Change-Id: Id464a07d624d0e228fe0aa66a04c8e51f292ba0c
2015-04-14 05:53:07 +00:00

116 lines
3.2 KiB
Python

# Copyright 2011 OpenStack Foundation
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from oslo_config import cfg
from nova.api.openstack import api_version_request
from nova.api.openstack.compute.views import versions as views_versions
from nova.api.openstack import wsgi
CONF = cfg.CONF
CONF.import_opt('enabled', 'nova.api.openstack', group='osapi_v3')
LINKS = {
'v2.0': {
'html': 'http://docs.openstack.org/'
},
'v2.1': {
'html': 'http://docs.openstack.org/'
},
}
VERSIONS = {
"v2.0": {
"id": "v2.0",
"status": "SUPPORTED",
"version": "",
"min_version": "",
"updated": "2011-01-21T11:33:21Z",
"links": [
{
"rel": "describedby",
"type": "text/html",
"href": LINKS['v2.0']['html'],
},
],
"media-types": [
{
"base": "application/json",
"type": "application/vnd.openstack.compute+json;version=2",
}
],
},
"v2.1": {
"id": "v2.1",
"status": "CURRENT",
"version": api_version_request._MAX_API_VERSION,
"min_version": api_version_request._MIN_API_VERSION,
"updated": "2013-07-23T11:33:21Z",
"links": [
{
"rel": "describedby",
"type": "text/html",
"href": LINKS['v2.1']['html'],
},
],
"media-types": [
{
"base": "application/json",
"type": "application/vnd.openstack.compute+json;version=2.1",
}
],
}
}
class Versions(wsgi.Resource):
def __init__(self):
super(Versions, self).__init__(None)
if not CONF.osapi_v3.enabled:
del VERSIONS["v2.1"]
def index(self, req, body=None):
"""Return all versions."""
builder = views_versions.get_view_builder(req)
return builder.build_versions(VERSIONS)
@wsgi.response(300)
def multi(self, req, body=None):
"""Return multiple choices."""
builder = views_versions.get_view_builder(req)
return builder.build_choices(VERSIONS, req)
def get_action_args(self, request_environment):
"""Parse dictionary created by routes library."""
args = {}
if request_environment['PATH_INFO'] == '/':
args['action'] = 'index'
else:
args['action'] = 'multi'
return args
class VersionV2(object):
def show(self, req):
builder = views_versions.get_view_builder(req)
return builder.build_version(VERSIONS['v2.0'])
def create_resource():
return wsgi.Resource(VersionV2())