1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
3
# Copyright 2011 Ken Pepple
4
# Licensed under the Apache License, Version 2.0 (the "License"); you may
5
# not use this file except in compliance with the License. You may obtain
6
# a copy of the License at
8
# http://www.apache.org/licenses/LICENSE-2.0
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
# License for the specific language governing permissions and limitations
16
from sqlalchemy import Boolean, Column, DateTime, Integer
17
from sqlalchemy import MetaData, String, Table
18
from nova import log as logging
20
LOG = logging.getLogger(__name__)
23
def upgrade(migrate_engine):
24
# Upgrade operations go here
25
# Don't create your own engine; bind migrate_engine
28
meta.bind = migrate_engine
32
instance_types = Table('instance_types', meta,
33
Column('created_at', DateTime(timezone=False)),
34
Column('updated_at', DateTime(timezone=False)),
35
Column('deleted_at', DateTime(timezone=False)),
36
Column('deleted', Boolean(create_constraint=True, name=None)),
38
String(length=255, convert_unicode=False,
40
unicode_error=None, _warn_on_bytestring=False),
42
Column('id', Integer(), primary_key=True, nullable=False),
43
Column('memory_mb', Integer(), nullable=False),
44
Column('vcpus', Integer(), nullable=False),
45
Column('local_gb', Integer(), nullable=False),
46
Column('flavorid', Integer(), nullable=False, unique=True),
47
Column('swap', Integer(), nullable=False, default=0),
48
Column('rxtx_quota', Integer(), nullable=False, default=0),
49
Column('rxtx_cap', Integer(), nullable=False, default=0))
51
instance_types.create()
53
LOG.info(repr(instance_types))
54
LOG.exception('Exception while creating instance_types table')
57
# Here are the old static instance types
59
'm1.tiny': dict(memory_mb=512, vcpus=1, local_gb=0, flavorid=1),
60
'm1.small': dict(memory_mb=2048, vcpus=1, local_gb=20, flavorid=2),
61
'm1.medium': dict(memory_mb=4096, vcpus=2, local_gb=40, flavorid=3),
62
'm1.large': dict(memory_mb=8192, vcpus=4, local_gb=80, flavorid=4),
63
'm1.xlarge': dict(memory_mb=16384, vcpus=8, local_gb=160, flavorid=5)}
65
i = instance_types.insert()
66
for name, values in INSTANCE_TYPES.iteritems():
67
# FIXME(kpepple) should we be seeding created_at / updated_at ?
68
# now = datetime.datatime.utcnow()
69
i.execute({'name': name, 'memory_mb': values["memory_mb"],
70
'vcpus': values["vcpus"], 'deleted': False,
71
'local_gb': values["local_gb"],
72
'flavorid': values["flavorid"]})
74
LOG.info(repr(instance_types))
75
LOG.exception('Exception while seeding instance_types table')
79
def downgrade(migrate_engine):
80
# Operations to reverse the above upgrade go here.
82
meta.bind = migrate_engine
83
instance_types = Table('instance_types', meta, autoload=True)
84
for table in (instance_types, ):