~rackspace-titan/nova/openstack-api-password-gen

« back to all changes in this revision

Viewing changes to nova/db/sqlalchemy/migrate_repo/versions/008_add_instance_types.py

  • Committer: Tarmac
  • Author(s): Ken Pepple, Josh Kearney
  • Date: 2011-03-03 02:04:51 UTC
  • mfrom: (624.2.75 instancetypes)
  • Revision ID: tarmac-20110303020451-tjwc91h2mcas663t
merges dynamic instance types blueprint (http://wiki.openstack.org/ConfigureInstanceTypesDynamically) and bundles blueprint (https://blueprints.launchpad.net/nova/+spec/flavors)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 
2
 
 
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
 
7
#
 
8
#         http://www.apache.org/licenses/LICENSE-2.0
 
9
#
 
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
 
14
#    under the License.
 
15
 
 
16
from sqlalchemy import *
 
17
from migrate import *
 
18
 
 
19
from nova import api
 
20
from nova import db
 
21
from nova import log as logging
 
22
 
 
23
import datetime
 
24
 
 
25
meta = MetaData()
 
26
 
 
27
 
 
28
#
 
29
# New Tables
 
30
#
 
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)),
 
36
        Column('name',
 
37
               String(length=255, convert_unicode=False, assert_unicode=None,
 
38
                      unicode_error=None, _warn_on_bytestring=False),
 
39
                      unique=True),
 
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))
 
48
 
 
49
 
 
50
def upgrade(migrate_engine):
 
51
    # Upgrade operations go here
 
52
    # Don't create your own engine; bind migrate_engine
 
53
    # to your metadata
 
54
    meta.bind = migrate_engine
 
55
    try:
 
56
        instance_types.create()
 
57
    except Exception:
 
58
        logging.info(repr(table))
 
59
        logging.exception('Exception while creating instance_types table')
 
60
        raise
 
61
 
 
62
    # Here are the old static instance types
 
63
    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)}
 
69
    try:
 
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"]})
 
78
    except Exception:
 
79
        logging.info(repr(table))
 
80
        logging.exception('Exception while seeding instance_types table')
 
81
        raise
 
82
 
 
83
 
 
84
def downgrade(migrate_engine):
 
85
    # Operations to reverse the above upgrade go here.
 
86
    for table in (instance_types):
 
87
        table.drop()