Merge "Add attach_time for EC2 Volumes"

This commit is contained in:
Jenkins
2012-05-30 21:19:02 +00:00
committed by Gerrit Code Review
3 changed files with 74 additions and 1 deletions

View File

@@ -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)

View File

@@ -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()

View File

@@ -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