From 5c7800d2d56d137df82f76c15800ff2c10bf4f57 Mon Sep 17 00:00:00 2001 From: Mohammed Naser Date: Fri, 19 Jan 2018 19:32:00 -0800 Subject: [PATCH] Switch to providing created_at field for servers All of the current models return the creation date in created_at with the exception of servers which are currently returned with a created field instead. This patch addresses this and gives the ability to get access to both. Change-Id: Ifbd59834080eea62dead19d18a9a11a851a4ce2e --- doc/source/user/model.rst | 1 + .../notes/switch-nova-to-created_at-45b7b50af6a2d59e.yaml | 5 +++++ shade/_normalize.py | 5 +++++ shade/tests/unit/test_normalize.py | 2 ++ 4 files changed, 13 insertions(+) create mode 100644 releasenotes/notes/switch-nova-to-created_at-45b7b50af6a2d59e.yaml diff --git a/doc/source/user/model.rst b/doc/source/user/model.rst index ebfc3af97..ce857d315 100644 --- a/doc/source/user/model.rst +++ b/doc/source/user/model.rst @@ -208,6 +208,7 @@ A Server from Nova accessIPv6=str(), addresses=dict(), # string, list(Address) created=str(), + created_at=str(), key_name=str(), metadata=dict(), # string, string private_v4=str(), diff --git a/releasenotes/notes/switch-nova-to-created_at-45b7b50af6a2d59e.yaml b/releasenotes/notes/switch-nova-to-created_at-45b7b50af6a2d59e.yaml new file mode 100644 index 000000000..68cf0a5e3 --- /dev/null +++ b/releasenotes/notes/switch-nova-to-created_at-45b7b50af6a2d59e.yaml @@ -0,0 +1,5 @@ +--- +features: + - The `created` field which was returned by the Nova API is now returned as + `created_at` as well when not using strict mode for consistency with other + models. diff --git a/shade/_normalize.py b/shade/_normalize.py index 83783c776..72f91ae2e 100644 --- a/shade/_normalize.py +++ b/shade/_normalize.py @@ -499,6 +499,11 @@ class Normalizer(object): # Protect against security_groups being None ret['security_groups'] = server.pop('security_groups', None) or [] + # NOTE(mnaser): The Nova API returns the creation date in `created` + # however the Shade contract returns `created_at` for + # all resources. + ret['created_at'] = server.get('created') + for field in _SERVER_FIELDS: ret[field] = server.pop(field, None) if not ret['networks']: diff --git a/shade/tests/unit/test_normalize.py b/shade/tests/unit/test_normalize.py index 0be594022..44ee5175b 100644 --- a/shade/tests/unit/test_normalize.py +++ b/shade/tests/unit/test_normalize.py @@ -566,6 +566,7 @@ class TestUtils(base.TestCase): u'version': 4}]}, 'adminPass': None, 'created': u'2015-08-01T19:52:16Z', + 'created_at': u'2015-08-01T19:52:16Z', 'disk_config': u'MANUAL', 'flavor': {u'id': u'bbcb7eb5-5c8d-498f-9d7e-307c575d3566'}, 'has_config_drive': True, @@ -635,6 +636,7 @@ class TestUtils(base.TestCase): 'cloud': '_test_cloud_', 'config_drive': u'True', 'created': u'2015-08-01T19:52:16Z', + 'created_at': u'2015-08-01T19:52:16Z', 'disk_config': u'MANUAL', 'flavor': {u'id': u'bbcb7eb5-5c8d-498f-9d7e-307c575d3566'}, 'has_config_drive': True,