Browse Source

Merge "Convert root controller to plain controller"

master
Zuul 3 days ago
committed by Gerrit Code Review
parent
commit
2f02358dec
1 changed files with 21 additions and 9 deletions
  1. +21
    -9
      ironic/api/controllers/root.py

+ 21
- 9
ironic/api/controllers/root.py View File

@@ -15,13 +15,15 @@
# under the License.

import pecan
from pecan import rest

from ironic.api.controllers import v1
from ironic.api.controllers import version
from ironic.api import method


V1 = v1.Controller()


def root():
return {
'name': "OpenStack Ironic API",
@@ -32,22 +34,32 @@ def root():
}


class RootController(rest.RestController):

v1 = v1.Controller()
class RootController(object):

@method.expose()
def get(self):
def index(self, *args):
if args:
pecan.abort(404)
return root()

@pecan.expose()
def _route(self, args, request=None):
def _lookup(self, primary_key, *remainder):
"""Overrides the default routing behavior.

It redirects the request to the default version of the ironic API
if the version number is not specified in the url.
"""

if args[0] and args[0] != version.ID_VERSION1:
args = [version.ID_VERSION1] + args
return super(RootController, self)._route(args, request)
# support paths which are missing the first version element
if primary_key and primary_key != version.ID_VERSION1:
remainder = [primary_key] + list(remainder)

# remove any trailing /
if remainder and not remainder[-1]:
remainder = remainder[:-1]

# but ensure /v1 goes to /v1/
if not remainder:
remainder = ['']

return V1, remainder

Loading…
Cancel
Save