diff --git a/ironic/api/controllers/base.py b/ironic/api/controllers/base.py index 41ddf31e59..73d7f9a086 100644 --- a/ironic/api/controllers/base.py +++ b/ironic/api/controllers/base.py @@ -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.""" diff --git a/ironic/api/controllers/link.py b/ironic/api/controllers/link.py index a19e3b2ade..6f5f072b92 100644 --- a/ironic/api/controllers/link.py +++ b/ironic/api/controllers/link.py @@ -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 diff --git a/ironic/api/controllers/root.py b/ironic/api/controllers/root.py index ece2b6dc45..42308fd826 100644 --- a/ironic/api/controllers/root.py +++ b/ironic/api/controllers/root.py @@ -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""" diff --git a/ironic/api/controllers/v1/__init__.py b/ironic/api/controllers/v1/__init__.py index ee26308fe7..cd568881f5 100644 --- a/ironic/api/controllers/v1/__init__.py +++ b/ironic/api/controllers/v1/__init__.py @@ -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 diff --git a/ironic/api/controllers/v1/bios.py b/ironic/api/controllers/v1/bios.py index 11ef23cb27..7be088c722 100644 --- a/ironic/api/controllers/v1/bios.py +++ b/ironic/api/controllers/v1/bios.py @@ -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] diff --git a/ironic/api/controllers/v1/collection.py b/ironic/api/controllers/v1/collection.py index 873621b125..cb65b9793d 100644 --- a/ironic/api/controllers/v1/collection.py +++ b/ironic/api/controllers/v1/collection.py @@ -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""" diff --git a/ironic/api/controllers/v1/driver.py b/ironic/api/controllers/v1/driver.py index c6a3f66752..efe6d31d6d 100644 --- a/ironic/api/controllers/v1/driver.py +++ b/ironic/api/controllers/v1/driver.py @@ -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] diff --git a/ironic/api/controllers/v1/node.py b/ironic/api/controllers/v1/node.py index d2454bab10..c322d3e20e 100644 --- a/ironic/api/controllers/v1/node.py +++ b/ironic/api/controllers/v1/node.py @@ -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] diff --git a/ironic/api/controllers/v1/types.py b/ironic/api/controllers/v1/types.py index 6df548a469..b0be55bd86 100644 --- a/ironic/api/controllers/v1/types.py +++ b/ironic/api/controllers/v1/types.py @@ -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-]+)+$'), diff --git a/ironic/api/controllers/version.py b/ironic/api/controllers/version.py index f83243da5d..a24ab32c65 100644 --- a/ironic/api/controllers/version.py +++ b/ironic/api/controllers/version.py @@ -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