~ubuntu-branches/ubuntu/saucy/nova/saucy-proposed

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-05-24 13:12:53 UTC
  • mfrom: (1.1.55)
  • Revision ID: package-import@ubuntu.com-20120524131253-ommql08fg1en06ut
Tags: 2012.2~f1-0ubuntu1
* New upstream release.
* Prepare for quantal:
  - Dropped debian/patches/upstream/0006-Use-project_id-in-ec2.cloud._format_image.patch
  - Dropped debian/patches/upstream/0005-Populate-image-properties-with-project_id-again.patch
  - Dropped debian/patches/upstream/0004-Fixed-bug-962840-added-a-test-case.patch
  - Dropped debian/patches/upstream/0003-Allow-unprivileged-RADOS-users-to-access-rbd-volumes.patch
  - Dropped debian/patches/upstream/0002-Stop-libvirt-test-from-deleting-instances-dir.patch
  - Dropped debian/patches/upstream/0001-fix-bug-where-nova-ignores-glance-host-in-imageref.patch 
  - Dropped debian/patches/0001-fix-useexisting-deprecation-warnings.patch
* debian/control: Add python-keystone as a dependency. (LP: #907197)
* debian/patches/kombu_tests_timeout.patch: Refreshed.
* debian/nova.conf, debian/nova-common.postinst: Convert to new ini
  file configuration
* debian/patches/nova-manage_flagfile_location.patch: Refreshed

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 Boolean, Column, DateTime, Integer
17
 
from sqlalchemy import MetaData, String, Table
18
 
from nova import log as logging
19
 
 
20
 
LOG = logging.getLogger(__name__)
21
 
 
22
 
 
23
 
def upgrade(migrate_engine):
24
 
    # Upgrade operations go here
25
 
    # Don't create your own engine; bind migrate_engine
26
 
    # to your metadata
27
 
    meta = MetaData()
28
 
    meta.bind = migrate_engine
29
 
    #
30
 
    # New Tables
31
 
    #
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)),
37
 
            Column('name',
38
 
                   String(length=255, convert_unicode=False,
39
 
                          assert_unicode=None,
40
 
                          unicode_error=None, _warn_on_bytestring=False),
41
 
                          unique=True),
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))
50
 
    try:
51
 
        instance_types.create()
52
 
    except Exception:
53
 
        LOG.info(repr(instance_types))
54
 
        LOG.exception('Exception while creating instance_types table')
55
 
        raise
56
 
 
57
 
    # Here are the old static instance types
58
 
    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)}
64
 
    try:
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"]})
73
 
    except Exception:
74
 
        LOG.info(repr(instance_types))
75
 
        LOG.exception('Exception while seeding instance_types table')
76
 
        raise
77
 
 
78
 
 
79
 
def downgrade(migrate_engine):
80
 
    # Operations to reverse the above upgrade go here.
81
 
    meta = MetaData()
82
 
    meta.bind = migrate_engine
83
 
    instance_types = Table('instance_types', meta, autoload=True)
84
 
    for table in (instance_types, ):
85
 
        table.drop()