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:
parent
f192f2c45d
commit
0c6521804d
@ -17,7 +17,6 @@ import functools
|
|||||||
|
|
||||||
from webob import exc
|
from webob import exc
|
||||||
import wsme
|
import wsme
|
||||||
from wsme import types as wtypes
|
|
||||||
|
|
||||||
from ironic.common.i18n import _
|
from ironic.common.i18n import _
|
||||||
|
|
||||||
@ -43,13 +42,12 @@ class AsDictMixin(object):
|
|||||||
and getattr(self, k) != wsme.Unset)
|
and getattr(self, k) != wsme.Unset)
|
||||||
|
|
||||||
|
|
||||||
class APIBase(wtypes.Base, AsDictMixin):
|
class Base(AsDictMixin):
|
||||||
|
"""Base type for complex types"""
|
||||||
created_at = wsme.wsattr(datetime.datetime, readonly=True)
|
def __init__(self, **kw):
|
||||||
"""The time in UTC at which the object is created"""
|
for key, value in kw.items():
|
||||||
|
if hasattr(self, key):
|
||||||
updated_at = wsme.wsattr(datetime.datetime, readonly=True)
|
setattr(self, key, value)
|
||||||
"""The time in UTC at which the object is updated"""
|
|
||||||
|
|
||||||
def unset_fields_except(self, except_list=None):
|
def unset_fields_except(self, except_list=None):
|
||||||
"""Unset fields so they don't appear in the message body.
|
"""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)
|
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
|
@functools.total_ordering
|
||||||
class Version(object):
|
class Version(object):
|
||||||
"""API Version object."""
|
"""API Version object."""
|
||||||
|
@ -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}
|
return template % {'url': base_url, 'res': resource, 'args': resource_args}
|
||||||
|
|
||||||
|
|
||||||
class Link(base.APIBase):
|
class Link(base.Base):
|
||||||
"""A link representation."""
|
"""A link representation."""
|
||||||
|
|
||||||
href = str
|
href = str
|
||||||
|
@ -23,7 +23,7 @@ from ironic.api.controllers import version
|
|||||||
from ironic.api import expose
|
from ironic.api import expose
|
||||||
|
|
||||||
|
|
||||||
class Root(base.APIBase):
|
class Root(base.Base):
|
||||||
|
|
||||||
name = str
|
name = str
|
||||||
"""The name of the API"""
|
"""The name of the API"""
|
||||||
|
@ -57,7 +57,7 @@ def max_version():
|
|||||||
versions.min_version_string(), versions.max_version_string())
|
versions.min_version_string(), versions.max_version_string())
|
||||||
|
|
||||||
|
|
||||||
class MediaType(base.APIBase):
|
class MediaType(base.Base):
|
||||||
"""A media type representation."""
|
"""A media type representation."""
|
||||||
|
|
||||||
base = str
|
base = str
|
||||||
@ -68,7 +68,7 @@ class MediaType(base.APIBase):
|
|||||||
self.type = type
|
self.type = type
|
||||||
|
|
||||||
|
|
||||||
class V1(base.APIBase):
|
class V1(base.Base):
|
||||||
"""The representation of the version 1 of the API."""
|
"""The representation of the version 1 of the API."""
|
||||||
|
|
||||||
id = str
|
id = str
|
||||||
|
@ -67,7 +67,7 @@ class BIOSSetting(base.APIBase):
|
|||||||
return cls._convert_with_links(bios, node_uuid, api.request.host_url)
|
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."""
|
"""API representation of the bios settings for a node."""
|
||||||
|
|
||||||
bios = [BIOSSetting]
|
bios = [BIOSSetting]
|
||||||
|
@ -20,7 +20,7 @@ from ironic.api.controllers import base
|
|||||||
from ironic.api.controllers import link
|
from ironic.api.controllers import link
|
||||||
|
|
||||||
|
|
||||||
class Collection(base.APIBase):
|
class Collection(base.Base):
|
||||||
|
|
||||||
next = str
|
next = str
|
||||||
"""A link to retrieve the next subset of the collection"""
|
"""A link to retrieve the next subset of the collection"""
|
||||||
|
@ -84,7 +84,7 @@ def hide_fields_in_newer_versions(obj):
|
|||||||
obj.enabled_bios_interfaces = wsme.Unset
|
obj.enabled_bios_interfaces = wsme.Unset
|
||||||
|
|
||||||
|
|
||||||
class Driver(base.APIBase):
|
class Driver(base.Base):
|
||||||
"""API representation of a driver."""
|
"""API representation of a driver."""
|
||||||
|
|
||||||
name = str
|
name = str
|
||||||
@ -209,7 +209,7 @@ class Driver(base.APIBase):
|
|||||||
return sample
|
return sample
|
||||||
|
|
||||||
|
|
||||||
class DriverList(base.APIBase):
|
class DriverList(base.Base):
|
||||||
"""API representation of a list of drivers."""
|
"""API representation of a list of drivers."""
|
||||||
|
|
||||||
drivers = [Driver]
|
drivers = [Driver]
|
||||||
|
@ -309,7 +309,7 @@ class NodeManagementController(rest.RestController):
|
|||||||
"""Expose inject_nmi as a sub-element of management"""
|
"""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."""
|
"""API representation of the console information for a node."""
|
||||||
|
|
||||||
console_enabled = types.boolean
|
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
|
# NOTE(vsaienko) We don't support pagination with VIFs, so we don't use
|
||||||
# collection.Collection here.
|
# collection.Collection here.
|
||||||
class VifCollection(wtypes.Base):
|
class VifCollection(base.Base):
|
||||||
"""API representation of a collection of VIFs. """
|
"""API representation of a collection of VIFs. """
|
||||||
|
|
||||||
vifs = [types.viftype]
|
vifs = [types.viftype]
|
||||||
|
@ -24,6 +24,7 @@ from oslo_utils import uuidutils
|
|||||||
import wsme
|
import wsme
|
||||||
from wsme import types as wtypes
|
from wsme import types as wtypes
|
||||||
|
|
||||||
|
from ironic.api.controllers import base
|
||||||
from ironic.api.controllers.v1 import utils as v1_utils
|
from ironic.api.controllers.v1 import utils as v1_utils
|
||||||
from ironic.common import exception
|
from ironic.common import exception
|
||||||
from ironic.common.i18n import _
|
from ironic.common.i18n import _
|
||||||
@ -192,7 +193,7 @@ listtype = ListType()
|
|||||||
jsontype = JsonType()
|
jsontype = JsonType()
|
||||||
|
|
||||||
|
|
||||||
class JsonPatchType(wtypes.Base):
|
class JsonPatchType(base.Base):
|
||||||
"""A complex type that represents a single json-patch operation."""
|
"""A complex type that represents a single json-patch operation."""
|
||||||
|
|
||||||
path = wtypes.wsattr(wtypes.StringType(pattern='^(/[\\w-]+)+$'),
|
path = wtypes.wsattr(wtypes.StringType(pattern='^(/[\\w-]+)+$'),
|
||||||
|
@ -17,7 +17,7 @@ from ironic.api.controllers import link
|
|||||||
ID_VERSION1 = 'v1'
|
ID_VERSION1 = 'v1'
|
||||||
|
|
||||||
|
|
||||||
class Version(base.APIBase):
|
class Version(base.Base):
|
||||||
"""An API version representation.
|
"""An API version representation.
|
||||||
|
|
||||||
This class represents an API version, including the minimum and
|
This class represents an API version, including the minimum and
|
||||||
|
Loading…
Reference in New Issue
Block a user