Clean up api controller base classes

The parent class of APIBase is no longer wsme.types.Base. Instead
there is a new ironic.api.controllers.base.Base as the parent. This
new Base class keeps the __init__() from wsme.types.Base, but not the
__registry__ registration.

As far as I can tell[1], this type registry is used to allow the
wsproperty datatype value to be a string, but all of our uses of
wsproperty use the real type types.uuid, so this registry is just
overhead.

The other changes are for some existing classes to extend the new Base
class instead of APIBase or wsme.types.Base. APIBase is now used only
by classes which represent real database objects, which is the only
situation where having a created_at, updated_at makes sense.

DeployStepType is excluded from this change as it will require extra
work to change its parent class.

Story: 1651346
[1] https://opendev.org/x/wsme/src/branch/master/wsme/types.py#L507

Change-Id: Ie687c270ed13b99486496a84df34e5973af1b9cd
This commit is contained in:
Steve Baker 2020-01-23 10:52:56 +13:00
parent f192f2c45d
commit 0c6521804d
10 changed files with 28 additions and 20 deletions

View File

@ -17,7 +17,6 @@ import functools
from webob import exc
import wsme
from wsme import types as wtypes
from ironic.common.i18n import _
@ -43,13 +42,12 @@ class AsDictMixin(object):
and getattr(self, k) != wsme.Unset)
class APIBase(wtypes.Base, AsDictMixin):
created_at = wsme.wsattr(datetime.datetime, readonly=True)
"""The time in UTC at which the object is created"""
updated_at = wsme.wsattr(datetime.datetime, readonly=True)
"""The time in UTC at which the object is updated"""
class Base(AsDictMixin):
"""Base type for complex types"""
def __init__(self, **kw):
for key, value in kw.items():
if hasattr(self, key):
setattr(self, key, value)
def unset_fields_except(self, except_list=None):
"""Unset fields so they don't appear in the message body.
@ -65,6 +63,15 @@ class APIBase(wtypes.Base, AsDictMixin):
setattr(self, k, wsme.Unset)
class APIBase(Base):
created_at = wsme.wsattr(datetime.datetime, readonly=True)
"""The time in UTC at which the object is created"""
updated_at = wsme.wsattr(datetime.datetime, readonly=True)
"""The time in UTC at which the object is updated"""
@functools.total_ordering
class Version(object):
"""API Version object."""

View File

@ -31,7 +31,7 @@ def build_url(resource, resource_args, bookmark=False, base_url=None):
return template % {'url': base_url, 'res': resource, 'args': resource_args}
class Link(base.APIBase):
class Link(base.Base):
"""A link representation."""
href = str

View File

@ -23,7 +23,7 @@ from ironic.api.controllers import version
from ironic.api import expose
class Root(base.APIBase):
class Root(base.Base):
name = str
"""The name of the API"""

View File

@ -57,7 +57,7 @@ def max_version():
versions.min_version_string(), versions.max_version_string())
class MediaType(base.APIBase):
class MediaType(base.Base):
"""A media type representation."""
base = str
@ -68,7 +68,7 @@ class MediaType(base.APIBase):
self.type = type
class V1(base.APIBase):
class V1(base.Base):
"""The representation of the version 1 of the API."""
id = str

View File

@ -67,7 +67,7 @@ class BIOSSetting(base.APIBase):
return cls._convert_with_links(bios, node_uuid, api.request.host_url)
class BIOSSettingsCollection(wtypes.Base):
class BIOSSettingsCollection(base.Base):
"""API representation of the bios settings for a node."""
bios = [BIOSSetting]

View File

@ -20,7 +20,7 @@ from ironic.api.controllers import base
from ironic.api.controllers import link
class Collection(base.APIBase):
class Collection(base.Base):
next = str
"""A link to retrieve the next subset of the collection"""

View File

@ -84,7 +84,7 @@ def hide_fields_in_newer_versions(obj):
obj.enabled_bios_interfaces = wsme.Unset
class Driver(base.APIBase):
class Driver(base.Base):
"""API representation of a driver."""
name = str
@ -209,7 +209,7 @@ class Driver(base.APIBase):
return sample
class DriverList(base.APIBase):
class DriverList(base.Base):
"""API representation of a list of drivers."""
drivers = [Driver]

View File

@ -309,7 +309,7 @@ class NodeManagementController(rest.RestController):
"""Expose inject_nmi as a sub-element of management"""
class ConsoleInfo(base.APIBase):
class ConsoleInfo(base.Base):
"""API representation of the console information for a node."""
console_enabled = types.boolean
@ -1454,7 +1454,7 @@ class NodeMaintenanceController(rest.RestController):
# NOTE(vsaienko) We don't support pagination with VIFs, so we don't use
# collection.Collection here.
class VifCollection(wtypes.Base):
class VifCollection(base.Base):
"""API representation of a collection of VIFs. """
vifs = [types.viftype]

View File

@ -24,6 +24,7 @@ from oslo_utils import uuidutils
import wsme
from wsme import types as wtypes
from ironic.api.controllers import base
from ironic.api.controllers.v1 import utils as v1_utils
from ironic.common import exception
from ironic.common.i18n import _
@ -192,7 +193,7 @@ listtype = ListType()
jsontype = JsonType()
class JsonPatchType(wtypes.Base):
class JsonPatchType(base.Base):
"""A complex type that represents a single json-patch operation."""
path = wtypes.wsattr(wtypes.StringType(pattern='^(/[\\w-]+)+$'),

View File

@ -17,7 +17,7 @@ from ironic.api.controllers import link
ID_VERSION1 = 'v1'
class Version(base.APIBase):
class Version(base.Base):
"""An API version representation.
This class represents an API version, including the minimum and