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 *
21
from nova import log as logging
31
instance_types = Table('instance_types', meta,
32
Column('created_at', DateTime(timezone=False)),
33
Column('updated_at', DateTime(timezone=False)),
34
Column('deleted_at', DateTime(timezone=False)),
35
Column('deleted', Boolean(create_constraint=True, name=None)),
37
String(length=255, convert_unicode=False, assert_unicode=None,
38
unicode_error=None, _warn_on_bytestring=False),
40
Column('id', Integer(), primary_key=True, nullable=False),
41
Column('memory_mb', Integer(), nullable=False),
42
Column('vcpus', Integer(), nullable=False),
43
Column('local_gb', Integer(), nullable=False),
44
Column('flavorid', Integer(), nullable=False, unique=True),
45
Column('swap', Integer(), nullable=False, default=0),
46
Column('rxtx_quota', Integer(), nullable=False, default=0),
47
Column('rxtx_cap', Integer(), nullable=False, default=0))
50
def upgrade(migrate_engine):
51
# Upgrade operations go here
52
# Don't create your own engine; bind migrate_engine
54
meta.bind = migrate_engine
56
instance_types.create()
58
logging.info(repr(table))
59
logging.exception('Exception while creating instance_types table')
62
# Here are the old static instance types
64
'm1.tiny': dict(memory_mb=512, vcpus=1, local_gb=0, flavorid=1),
65
'm1.small': dict(memory_mb=2048, vcpus=1, local_gb=20, flavorid=2),
66
'm1.medium': dict(memory_mb=4096, vcpus=2, local_gb=40, flavorid=3),
67
'm1.large': dict(memory_mb=8192, vcpus=4, local_gb=80, flavorid=4),
68
'm1.xlarge': dict(memory_mb=16384, vcpus=8, local_gb=160, flavorid=5)}
70
i = instance_types.insert()
71
for name, values in INSTANCE_TYPES.iteritems():
72
# FIXME(kpepple) should we be seeding created_at / updated_at ?
73
# now = datetime.datatime.utcnow()
74
i.execute({'name': name, 'memory_mb': values["memory_mb"],
75
'vcpus': values["vcpus"], 'deleted': 0,
76
'local_gb': values["local_gb"],
77
'flavorid': values["flavorid"]})
79
logging.info(repr(table))
80
logging.exception('Exception while seeding instance_types table')
84
def downgrade(migrate_engine):
85
# Operations to reverse the above upgrade go here.
86
for table in (instance_types):