diff --git a/api-ref/source/v2/amphora.inc b/api-ref/source/v2/amphora.inc index 5ef38387f6..afdf5ac825 100644 --- a/api-ref/source/v2/amphora.inc +++ b/api-ref/source/v2/amphora.inc @@ -67,6 +67,8 @@ Response Parameters - vrrp_id: vrrp-id - vrrp_priority: vrrp-priority - cached_zone: cached-zone + - created_at: created_at + - updated_at: updated_at Response Example ---------------- @@ -138,6 +140,8 @@ Response Parameters - vrrp_id: vrrp-id - vrrp_priority: vrrp-priority - cached_zone: cached-zone + - created_at: created_at + - updated_at: updated_at Response Example ---------------- diff --git a/api-ref/source/v2/examples/amphora-list-response.json b/api-ref/source/v2/examples/amphora-list-response.json index 9c8c66efef..2fa4b959bd 100644 --- a/api-ref/source/v2/examples/amphora-list-response.json +++ b/api-ref/source/v2/examples/amphora-list-response.json @@ -16,7 +16,9 @@ "vrrp_interface": "eth1", "vrrp_id": 1, "vrrp_priority": 100, - "cached_zone": "zone1" + "cached_zone": "zone1", + "created_at": "2017-05-10T18:14:44", + "updated_at": "2017-05-10T23:08:12" }, { "id": "89c186a3-cb16-497b-b099-c4bd40316642", @@ -34,7 +36,9 @@ "vrrp_interface": "eth1", "vrrp_id": 1, "vrrp_priority": 200, - "cached_zone": "zone2" + "cached_zone": "zone2", + "created_at": "2017-06-11T19:15:45", + "updated_at": "2017-06-11T24:09:13" } ] } diff --git a/api-ref/source/v2/examples/amphora-show-response.json b/api-ref/source/v2/examples/amphora-show-response.json index 86f7c8949b..aeb29a8d69 100644 --- a/api-ref/source/v2/examples/amphora-show-response.json +++ b/api-ref/source/v2/examples/amphora-show-response.json @@ -15,6 +15,8 @@ "vrrp_interface": "eth1", "vrrp_id": 1, "vrrp_priority": 100, - "cached_zone": "zone1" + "cached_zone": "zone1", + "created_at": "2017-05-10T18:14:44", + "updated_at": "2017-05-10T23:08:12" } } diff --git a/octavia/api/v2/types/amphora.py b/octavia/api/v2/types/amphora.py index e63ac1809c..90715e0e6f 100644 --- a/octavia/api/v2/types/amphora.py +++ b/octavia/api/v2/types/amphora.py @@ -40,6 +40,8 @@ class AmphoraResponse(BaseAmphoraType): vrrp_id = wtypes.wsattr(wtypes.IntegerType()) vrrp_priority = wtypes.wsattr(wtypes.IntegerType()) cached_zone = wtypes.wsattr(wtypes.StringType()) + created_at = wtypes.wsattr(wtypes.datetime.datetime) + updated_at = wtypes.wsattr(wtypes.datetime.datetime) @classmethod def from_data_model(cls, data_model, children=False): diff --git a/octavia/common/data_models.py b/octavia/common/data_models.py index af6eca72af..aafc5a2382 100644 --- a/octavia/common/data_models.py +++ b/octavia/common/data_models.py @@ -500,7 +500,8 @@ class Amphora(BaseDataModel): ha_ip=None, vrrp_port_id=None, ha_port_id=None, load_balancer=None, role=None, cert_expiration=None, cert_busy=False, vrrp_interface=None, vrrp_id=None, - vrrp_priority=None, cached_zone=None): + vrrp_priority=None, cached_zone=None, created_at=None, + updated_at=None): self.id = id self.load_balancer_id = load_balancer_id self.compute_id = compute_id @@ -518,6 +519,8 @@ class Amphora(BaseDataModel): self.cert_expiration = cert_expiration self.cert_busy = cert_busy self.cached_zone = cached_zone + self.created_at = created_at + self.updated_at = updated_at def delete(self): for amphora in self.load_balancer.amphorae: diff --git a/octavia/db/migration/alembic_migrations/versions/10d38216ad34_add_timestamps_to_amphora.py b/octavia/db/migration/alembic_migrations/versions/10d38216ad34_add_timestamps_to_amphora.py new file mode 100644 index 0000000000..8ca76b8d25 --- /dev/null +++ b/octavia/db/migration/alembic_migrations/versions/10d38216ad34_add_timestamps_to_amphora.py @@ -0,0 +1,39 @@ +# Copyright 2018 GoDaddy +# +# 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. + +"""add timestamps to amphora + +Revision ID: 10d38216ad34 +Revises: 0aee2b450512 +Create Date: 2018-02-26 10:04:59.133772 + +""" + +from alembic import op +import sqlalchemy as sa + +# revision identifiers, used by Alembic. +revision = '10d38216ad34' +down_revision = '0aee2b450512' + + +def upgrade(): + op.add_column( + u'amphora', + sa.Column(u'created_at', sa.DateTime(), nullable=True) + ) + op.add_column( + u'amphora', + sa.Column(u'updated_at', sa.DateTime(), nullable=True) + ) diff --git a/octavia/db/models.py b/octavia/db/models.py index df97140fec..1f7d105390 100644 --- a/octavia/db/models.py +++ b/octavia/db/models.py @@ -484,7 +484,7 @@ class SNI(base_models.BASE): cascade="delete")) -class Amphora(base_models.BASE, base_models.IdMixin): +class Amphora(base_models.BASE, base_models.IdMixin, models.TimestampMixin): __data_model__ = data_models.Amphora diff --git a/octavia/tests/functional/api/v2/test_amphora.py b/octavia/tests/functional/api/v2/test_amphora.py index 353bec2e25..1ab9711d5a 100644 --- a/octavia/tests/functional/api/v2/test_amphora.py +++ b/octavia/tests/functional/api/v2/test_amphora.py @@ -52,7 +52,9 @@ class TestAmphora(base.BaseAPITest): 'vrrp_interface': 'eth1', 'vrrp_id': 1, 'vrrp_priority': 100, - 'cached_zone': None + 'cached_zone': None, + 'created_at': datetime.datetime.now(), + 'updated_at': datetime.datetime.now(), } self.amp = self.amphora_repo.create(self.session, **self.amp_args) self.amp_id = self.amp.id @@ -82,6 +84,10 @@ class TestAmphora(base.BaseAPITest): response.pop('loadbalancer_id')) self.assertEqual(source.pop('cert_expiration').isoformat(), response.pop('cert_expiration')) + self.assertEqual(source.pop('created_at').isoformat(), + response.pop('created_at')) + self.assertEqual(source.pop('updated_at').isoformat(), + response.pop('updated_at')) self.assertEqual(source, response) def test_get(self):