diff options
| author | Jenkins <jenkins@review.openstack.org> | 2012-05-30 21:19:02 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2012-05-30 21:19:02 +0000 |
| commit | 04d511b2973f61cd1181f329f168fc502fb19357 (patch) | |
| tree | 113c2fc6a203af96a8fcdbc8452ace1f3fe55eb7 | |
| parent | b04cd354f9c28403536593169b3fcfd828dba389 (diff) | |
| parent | 0414446063101bf2931f1c9cf568bf3c46488363 (diff) | |
Merge "Add attach_time for EC2 Volumes"
| -rw-r--r-- | nova/db/sqlalchemy/api.py | 1 | ||||
| -rw-r--r-- | nova/db/sqlalchemy/migrate_repo/versions/098_update_volume_attach_time.py | 72 | ||||
| -rw-r--r-- | nova/db/sqlalchemy/models.py | 2 |
3 files changed, 74 insertions, 1 deletions
diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index 39b26a759..22eb7a8fd 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -2810,6 +2810,7 @@ def volume_attached(context, volume_id, instance_uuid, mountpoint): volume_ref['mountpoint'] = mountpoint volume_ref['attach_status'] = 'attached' volume_ref['instance_uuid'] = instance_uuid + volume_ref['attach_time'] = utils.utcnow() volume_ref.save(session=session) diff --git a/nova/db/sqlalchemy/migrate_repo/versions/098_update_volume_attach_time.py b/nova/db/sqlalchemy/migrate_repo/versions/098_update_volume_attach_time.py new file mode 100644 index 000000000..46f681100 --- /dev/null +++ b/nova/db/sqlalchemy/migrate_repo/versions/098_update_volume_attach_time.py @@ -0,0 +1,72 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 +# +# Copyright (c) 2012 Canonical Ltd. +# All Rights Reserved. +# +# 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 sqlalchemy import select, Column, Table, MetaData, String, DateTime + + +def upgrade(migrate_engine): + meta = MetaData() + meta.bind = migrate_engine + + volumes = Table('volumes', meta, autoload=True) + attach_datetime = Column('attachtime_datetime', DateTime(timezone=False)) + attach_datetime.create(volumes) + + old_attachtime = volumes.c.attach_time + + try: + volumes_list = list(volumes.select().execute()) + for v in volumes_list: + attach_time = select([volumes.c.attach_time], + volumes.c.id == v['id']) + volumes.update().\ + where(volumes.c.id == v['id']).\ + values(attach_datetime=attach_time).execute() + except Exception: + attach_datetime.drop() + raise + + old_attachtime.alter(name='attach_time_old') + attach_datetime.alter(name='attach_time') + old_attachtime.drop() + + +def downgrade(migrate_engine): + meta = MetaData() + meta.bind = migrate_engine + + volumes = Table('volumes', meta, autoload=True) + attach_string = Column('attachtime_string', String(255)) + attach_string.create(volumes) + + old_attachtime = volumes.c.attach_time + + try: + volumes_list = list(volumes.select().execute()) + for v in volumes_list: + attach_time = select([volumes.c.attach_time], + volumes.c.id == v['id']) + volumes.update().\ + where(volumes.c.id == v['id']).\ + values(attach_string=attach_time).execute() + except Exception: + attach_datetime.drop() + raise + + old_attachtime.alter(name='attach_time_old') + attach_string.alter(name='attach_time') + old_attachtime.drop() diff --git a/nova/db/sqlalchemy/models.py b/nova/db/sqlalchemy/models.py index ada6afe10..452816bb7 100644 --- a/nova/db/sqlalchemy/models.py +++ b/nova/db/sqlalchemy/models.py @@ -342,7 +342,7 @@ class Volume(BASE, NovaBase): availability_zone = Column(String(255)) # TODO(vish): foreign key? instance_uuid = Column(String(36)) mountpoint = Column(String(255)) - attach_time = Column(String(255)) # TODO(vish): datetime + attach_time = Column(DateTime) status = Column(String(255)) # TODO(vish): enum? attach_status = Column(String(255)) # TODO(vish): enum |
