neutron/neutron/extensions/timestamp.py
Kevin Benton 8133f6e385 Include timezone in timestamp fields
The Neutron 'created_at'/'updated_at' fields on API resources
were inconsistent with other OpenStack projects because we did
not include timezone information. This patch addressed that
problem by adding the zulu time indicator onto the end of the
fields.

Because this could break clients expecting no timezone, this patch
also eliminates the 'timestamp_core' and 'timestamp_ext' extensions
and consolidates them into a new 'timestamp' extension. This makes
the change discoverable via the API.

This is assuming the current API development paradigm where
extensions can come and go depending on the deployment and the client
is expected to handle this by checking the loaded extensions.
Once we decide extensions are permanent, this type of change will
no longer be possible.

Even though this is being proposed late in the cycle, it is better
to get this change in before the release where we expose even more
resources with incorrectly formatted timestamps.

(cherry picked from commit 424a633fd9)

APIImpact
Closes-Bug: #1561200
Change-Id: I2ee2ed4c713d88345adc55b022feb95653eec663
2016-09-16 11:19:12 -07:00

61 lines
1.9 KiB
Python

# Copyright 2015 HuaWei Technologies.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from neutron.api import extensions
from neutron.db import standard_attr
# Attribute Map
CREATED = 'created_at'
UPDATED = 'updated_at'
TIMESTAMP_BODY = {
CREATED: {'allow_post': False, 'allow_put': False,
'is_visible': True, 'default': None
},
UPDATED: {'allow_post': False, 'allow_put': False,
'is_visible': True, 'default': None
},
}
class Timestamp(extensions.ExtensionDescriptor):
"""Extension class supporting timestamp.
This class is used by neutron's extension framework for adding timestamp
to neutron core resources.
"""
@classmethod
def get_name(cls):
return "Resource timestamps"
@classmethod
def get_alias(cls):
return "standard-attr-timestamp"
@classmethod
def get_description(cls):
return ("Adds created_at and updated_at fields to all Neutron "
"resources that have Neutron standard attributes.")
@classmethod
def get_updated(cls):
return "2016-09-12T10:00:00-00:00"
def get_extended_resources(self, version):
if version != "2.0":
return {}
rs_map = standard_attr.get_standard_attr_resource_model_map()
return {resource: TIMESTAMP_BODY for resource in rs_map}