Merge lp:~termie/nova/db_migration into lp:~hudson-openstack/nova/trunk

Proposed by termie
Status: Merged
Approved by: Vish Ishaya
Approved revision: 565
Merged at revision: 581
Proposed branch: lp:~termie/nova/db_migration
Merge into: lp:~hudson-openstack/nova/trunk
Diff against target: 1141 lines (+920/-88)
15 files modified
MANIFEST.in (+1/-0)
bin/nova-manage (+18/-1)
nova/db/migration.py (+38/-0)
nova/db/sqlalchemy/__init__.py (+0/-28)
nova/db/sqlalchemy/migrate_repo/README (+4/-0)
nova/db/sqlalchemy/migrate_repo/manage.py (+4/-0)
nova/db/sqlalchemy/migrate_repo/migrate.cfg (+20/-0)
nova/db/sqlalchemy/migrate_repo/versions/001_austin.py (+547/-0)
nova/db/sqlalchemy/migrate_repo/versions/002_bexar.py (+209/-0)
nova/db/sqlalchemy/migration.py (+72/-0)
nova/db/sqlalchemy/models.py (+0/-45)
nova/service.py (+0/-13)
nova/tests/__init__.py (+5/-0)
run_tests.py (+1/-1)
tools/pip-requires (+1/-0)
To merge this branch: bzr merge lp:~termie/nova/db_migration
Reviewer Review Type Date Requested Status
termie (community) Approve
Jay Pipes (community) Approve
Thierry Carrez (community) ffe Approve
Todd Willey (community) Approve
Devin Carlen (community) Approve
Review via email: mp+46073@code.launchpad.net

Description of the change

Allows moving from the Austin-style db to the Bexar-style.

Prevents the db from being created automatically when services run.

Adds nova-manage db sync and nova manage db version to bring the db up-to-date and to check the current version. Must be run with the same privileges as the services who will access the database (or you need to chmod the db afterwards if sqlite)

To post a comment you must log in.
Revision history for this message
Devin Carlen (devcamcar) wrote :

approve, nice work

review: Approve
Revision history for this message
Todd Willey (xtoddx) wrote :

Awesome.

It would be great to have more sphinx docs about this, from the standpoint of developer needing to modify the schema, as well as a service provider needing to use nova-manage to keep their schema up to date.

review: Approve
Revision history for this message
OpenStack Infra (hudson-openstack) wrote :

The attempt to merge lp:~termie/nova/db_migration into lp:nova failed. Below is the output from the failed tests.

Revision history for this message
Soren Hansen (soren) wrote :

/me looks into this.

2011/1/13 OpenStack Hudson <email address hidden>:
> The attempt to merge lp:~termie/nova/db_migration into lp:nova failed. Below is the output from the failed tests.
>
>
>
> --
> https://code.launchpad.net/~termie/nova/db_migration/+merge/46073
> You are subscribed to branch lp:nova.
>

--
Soren Hansen <email address hidden>
Systems Architect, The Rackspace Cloud
Ubuntu Developer

Revision history for this message
Soren Hansen (soren) wrote :

python-migrate and python-tempita installed on Hudson box. Retrying.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote :
Download full text (122.8 KiB)

The attempt to merge lp:~termie/nova/db_migration into lp:nova failed. Below is the output from the failed tests.

TrialTestCase
    runTest ok
AdminAPITest
    test_admin_disabled ok
    test_admin_enabled ok
APITest
    test_exceptions_are_converted_to_faults ok
Test
    test_authorize_token ok
    test_authorize_user ok
    test_bad_token ok
    test_bad_user ok
    test_no_user ok
    test_token_expiry ok
TestLimiter
    test_authorize_token ok
TestFaults
    test_fault_parts ok
    test_raise ok
    test_retry_header ok
FlavorsTest
    test_get_flavor_by_id ok
    test_get_flavor_list ok
GlanceImageServiceTest
    test_create ok
    test_create_and_show_non_existing_image ok
    test_delete ok
    test_update ok
ImageControllerWithGlanceServiceTest
    test_get_image_details ok
    test_get_image_index ok
LocalImageServiceTest
    test_create ok
    test_create_and_show_non_existing_image ok
    test_delete ok
    test_update ok
LimiterTest
    test_minute ok
    test_one_per_period ok
    test_second ok
    test_users_get_separate_buckets ok
    test_we_can_go_indefinitely_if_we_spread_out_requests ok
WSGIAppProxyTest
    test_200 ok
    test_403 ok
    test_failure ok
WSGIAppTest
    test_escaping ok
    test_good_urls ok
    test_invalid_methods ok
    test_invalid_urls ok
    test_response_to_delays ok
ServersTest
    test_create_backup_schedules ok
    test_create_instance ok
    test_delete_backup_schedules ok
    test_delete_server_instance ...

Revision history for this message
termie (termie) wrote :

looks like something new was added in trunk that found an error in the migration :) (i was dumb and didn't run the tests in the merge branch) anyway, looking into it

Revision history for this message
termie (termie) wrote :

the column creation isn't working as documented as far as i can tell, rawwwrrrr

Revision history for this message
termie (termie) wrote :

alright, column creation is working fine, there have just been changes to the models in trunk whilst i was not looking, wee.

should work fine now.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote :

Attempt to merge into lp:nova failed due to conflicts:

text conflict in tools/pip-requires

Revision history for this message
Thierry Carrez (ttx) wrote :

This just needs a few more hours to get in. FFe approved for landing before Monday.

review: Approve (ffe)
Revision history for this message
termie (termie) wrote :

pushed new version, however there are currently pep8 violations in trunk so i expect there will be more conflicts, i have already fixed the violations in a different branch and i expect somebody else will fix them too... so.... dumb.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote :
Download full text (588.5 KiB)

The attempt to merge lp:~termie/nova/db_migration into lp:nova failed. Below is the output from the failed tests.

AdminAPITest
    test_admin_disabled ok
    test_admin_enabled ok
APITest
    test_exceptions_are_converted_to_faults ok
Test
    test_authorize_token ok
    test_authorize_user ok
    test_bad_token ok
    test_bad_user ok
    test_no_user ok
    test_token_expiry ok
TestLimiter
    test_authorize_token ok
TestFaults
    test_fault_parts ok
    test_raise ok
    test_retry_header ok
FlavorsTest
    test_get_flavor_by_id ok
    test_get_flavor_list ok
GlanceImageServiceTest
    test_create ok
    test_create_and_show_non_existing_image ok
    test_delete ok
    test_update ok
ImageControllerWithGlanceServiceTest
    test_get_image_details ok
    test_get_image_index ok
LocalImageServiceTest
    test_create ok
    test_create_and_show_non_existing_image ok
    test_delete ok
    test_update ok
LimiterTest
    test_minute ok
    test_one_per_period ok
    test_second ok
    test_users_get_separate_buckets ok
    test_we_can_go_indefinitely_if_we_spread_out_requests ok
WSGIAppProxyTest
    test_200 ok
    test_403 ok
    test_failure ok
WSGIAppTest
    test_escaping ok
    test_good_urls ok
    test_invalid_methods ok
    test_invalid_urls ok
    test_response_to_delays ok
ServersTest
    test_create_backup_schedules ok
    test_create_instance ok
    test_delete_backup_schedules ok
    test_delete_server_instance ok
    test_get_all_server_details ok
    test...

Revision history for this message
termie (termie) wrote :

i'm going to wait a day or so for things to settle before I try to commit this again, tracking other people's schema changes commit-to-commit isn't really on my list of fun things.

Revision history for this message
Thierry Carrez (ttx) wrote :

@termie: due to featurefreeze you should have the necessary stability for merging this now.
I see only one branch in queue still modifying the schema (https://code.launchpad.net/~nttdata/nova/live-migration/+merge/44940)

Revision history for this message
Jay Pipes (jaypipes) wrote :

Heyo.

Mostly good (and necessary!) stuff, Andy. Nice job.

Here's a couple things to address, though (outside of the merge stuff you're currently looking at):

1) Please add sqlalchemy-migrations to tools/pip-requires otherwise tests will bomb in a virtualenv

2) Copy/paste docstring fail here :)

22 + def sync(self, version=None):
23 + """adds role to user
24 + if project is specified, adds project specific role
25 + arguments: user, role [project]"""
26 + return migration.db_sync(version)

3) Nova != Django :)

135 === added file 'nova/db/sqlalchemy/migrate_repo/__init__.py'
136 === added file 'nova/db/sqlalchemy/migrate_repo/manage.py'
137 --- nova/db/sqlalchemy/migrate_repo/manage.py 1970-01-01 00:00:00 +0000
138 +++ nova/db/sqlalchemy/migrate_repo/manage.py 2011-01-15 02:00:45 +0000
139 @@ -0,0 +1,4 @@
140 +#!/usr/bin/env python
141 +from migrate.versioning.shell import main
142 +if __name__ == '__main__':
143 + main(debug='False', repository='.')

Not sure if the above is necessary considering the nova-manage db sync. Was this just to achieve parity with Django? I didn't see this script being used anywhere.

4) This code:

951 +def db_sync(version=None):
952 + db_version()
953 + repo_path = _find_migrate_repo()
954 + return versioning_api.upgrade(FLAGS.sql_connection, repo_path, version)

Looks like there is something missing... db_version() returns the numeric version of the database, if it is versioned (returning 0 if not versioned). May I suggest changing the above code to the following:

def db_sync(version=1):
  cur_version = db_version()
  repo_path = _find_migrate_repo()
  if version > cur_version:
    return versioning_api.upgrade(FLAGS.sql_connection, repo_path, version)
  return True

Cheers!

jay

review: Needs Fixing
Revision history for this message
termie (termie) wrote :

> Heyo.
>
> Mostly good (and necessary!) stuff, Andy. Nice job.
>
> Here's a couple things to address, though (outside of the merge stuff you're
> currently looking at):
>
> 1) Please add sqlalchemy-migrations to tools/pip-requires otherwise tests will
> bomb in a virtualenv
>

sqlalchemy-migrate is already in there.

> 2) Copy/paste docstring fail here :)
>
> 22 + def sync(self, version=None):
> 23 + """adds role to user
> 24 + if project is specified, adds project specific role
> 25 + arguments: user, role [project]"""
> 26 + return migration.db_sync(version)

Nice catch.

>
> 3) Nova != Django :)
>
> 135 === added file 'nova/db/sqlalchemy/migrate_repo/__init__.py'
> 136 === added file 'nova/db/sqlalchemy/migrate_repo/manage.py'
> 137 --- nova/db/sqlalchemy/migrate_repo/manage.py 1970-01-01 00:00:00
> +0000
> 138 +++ nova/db/sqlalchemy/migrate_repo/manage.py 2011-01-15 02:00:45
> +0000
> 139 @@ -0,0 +1,4 @@
> 140 +#!/usr/bin/env python
> 141 +from migrate.versioning.shell import main
> 142 +if __name__ == '__main__':
> 143 + main(debug='False', repository='.')
>
> Not sure if the above is necessary considering the nova-manage db sync. Was
> this just to achieve parity with Django? I didn't see this script being used
> anywhere.
>

This has nothing to do with django, this is the default repository format for sqlalchemy-migrate. There is, however an indentation error.

> 4) This code:
>
> 951 +def db_sync(version=None):
> 952 + db_version()
> 953 + repo_path = _find_migrate_repo()
> 954 + return versioning_api.upgrade(FLAGS.sql_connection, repo_path,
> version)
>
> Looks like there is something missing... db_version() returns the numeric
> version of the database, if it is versioned (returning 0 if not versioned).

db_versions ensures that the db version is set correctly (1 if they already had the austin db, 0 if the db is empty).

> May I suggest changing the above code to the following:
>
> def db_sync(version=1):
> cur_version = db_version()
> repo_path = _find_migrate_repo()
> if version > cur_version:
> return versioning_api.upgrade(FLAGS.sql_connection, repo_path, version)
> return True
>
> Cheers!

Sync already knows about updates and won't update if the version is correct.

I'll fix the nova-manage documentation, however this branch is now waiting on discussion about the live_migration branch.

>
> jay

Revision history for this message
Jay Pipes (jaypipes) wrote :

> sqlalchemy-migrate is already in there.

Doh. Sorry, missed that :)

> This has nothing to do with django, this is the default repository format for
> sqlalchemy-migrate. There is, however an indentation error.

Ah, OK, sorry. Looked like it was Django-related; thx for the explanation.

> Sync already knows about updates and won't update if the version is correct.

Ah, OK, that wasn't clear...thx for the explanation.

> I'll fix the nova-manage documentation, however this branch is now waiting on
> discussion about the live_migration branch

My vote is to revert the live-migrations patch and proceed with this patch. The live-migration patch needs more baking IMHO.

review: Approve
Revision history for this message
termie (termie) wrote :

Just to make sure launchpad doesn't try to merge this again and generate an epic error log marking this as needs fixing

review: Needs Fixing
Revision history for this message
termie (termie) wrote :

aight, ready for another looksee, i added string lengths to satisfy MySQL and added the new columns

Revision history for this message
termie (termie) wrote :

approving myself, not sure whether that will make it try to merge...

review: Approve
Revision history for this message
OpenStack Infra (hudson-openstack) wrote :
Download full text (132.2 KiB)

The attempt to merge lp:~termie/nova/db_migration into lp:nova failed. Below is the output from the failed tests.

AdminAPITest
    test_admin_disabled ok
    test_admin_enabled ok
APITest
    test_exceptions_are_converted_to_faults ok
Test
    test_authorize_token ok
    test_authorize_user ok
    test_bad_token ok
    test_bad_user ok
    test_no_user ok
    test_token_expiry ok
TestLimiter
    test_authorize_token ok
TestFaults
    test_fault_parts ok
    test_raise ok
    test_retry_header ok
FlavorsTest
    test_get_flavor_by_id ok
    test_get_flavor_list ok
GlanceImageServiceTest
    test_create ok
    test_create_and_show_non_existing_image ok
    test_delete ok
    test_update ok
ImageControllerWithGlanceServiceTest
    test_get_image_details ok
    test_get_image_index ok
LocalImageServiceTest
    test_create ok
    test_create_and_show_non_existing_image ok
    test_delete ok
    test_update ok
LimiterTest
    test_minute ok
    test_one_per_period ok
    test_second ok
    test_users_get_separate_buckets ok
    test_we_can_go_indefinitely_if_we_spread_out_requests ok
WSGIAppProxyTest
    test_200 ok
    test_403 ok
    test_failure ok
WSGIAppTest
    test_escaping ok
    test_good_urls ok
    test_invalid_methods ok
    test_invalid_urls ok
    test_response_to_delays ok
ServersTest
    test_create_backup_schedules ok
    test_create_instance ok
    test_delete_backup_schedules ok
    test_delete_server_instance ok
    test_get_all_server_details ok
    test...

Revision history for this message
termie (termie) wrote :

grr, this is all passing locally with run_tests.sh

Revision history for this message
termie (termie) wrote :

it looks like hudson is running tests twice, one of which without run_tests.sh (looks like it is running nose)

lp:~termie/nova/db_migration updated
565. By termie

move db sync into nosetests package-level fixtures so that the existing nosetests attempt in hudson will pass

Revision history for this message
termie (termie) wrote :

moved db sync into a nose package-level fixture, approving again

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'MANIFEST.in'
--- MANIFEST.in 2010-12-22 20:59:53 +0000
+++ MANIFEST.in 2011-01-19 01:35:10 +0000
@@ -12,6 +12,7 @@
12include nova/cloudpipe/client.ovpn.template12include nova/cloudpipe/client.ovpn.template
13include nova/compute/fakevirtinstance.xml13include nova/compute/fakevirtinstance.xml
14include nova/compute/interfaces.template14include nova/compute/interfaces.template
15include nova/db/sqlalchemy/migrate_repo/migrate.cfg
15include nova/virt/interfaces.template16include nova/virt/interfaces.template
16include nova/virt/libvirt*.xml.template17include nova/virt/libvirt*.xml.template
17include nova/tests/CA/18include nova/tests/CA/
1819
=== modified file 'bin/nova-manage'
--- bin/nova-manage 2011-01-18 19:01:16 +0000
+++ bin/nova-manage 2011-01-19 01:35:10 +0000
@@ -82,6 +82,7 @@
82from nova import utils82from nova import utils
83from nova.auth import manager83from nova.auth import manager
84from nova.cloudpipe import pipelib84from nova.cloudpipe import pipelib
85from nova.db import migration
8586
8687
87logging.basicConfig()88logging.basicConfig()
@@ -519,6 +520,21 @@
519 print re.sub('#012', "\n", "\n".join(lines))520 print re.sub('#012', "\n", "\n".join(lines))
520521
521522
523class DbCommands(object):
524 """Class for managing the database."""
525
526 def __init__(self):
527 pass
528
529 def sync(self, version=None):
530 """Sync the database up to the most recent version."""
531 return migration.db_sync(version)
532
533 def version(self):
534 """Print the current database version."""
535 print migration.db_version()
536
537
522CATEGORIES = [538CATEGORIES = [
523 ('user', UserCommands),539 ('user', UserCommands),
524 ('project', ProjectCommands),540 ('project', ProjectCommands),
@@ -528,7 +544,8 @@
528 ('floating', FloatingIpCommands),544 ('floating', FloatingIpCommands),
529 ('network', NetworkCommands),545 ('network', NetworkCommands),
530 ('service', ServiceCommands),546 ('service', ServiceCommands),
531 ('log', LogCommands)]547 ('log', LogCommands),
548 ('db', DbCommands)]
532549
533550
534def lazy_match(name, key_value_tuples):551def lazy_match(name, key_value_tuples):
535552
=== added file 'nova/db/migration.py'
--- nova/db/migration.py 1970-01-01 00:00:00 +0000
+++ nova/db/migration.py 2011-01-19 01:35:10 +0000
@@ -0,0 +1,38 @@
1# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3# Copyright 2010 United States Government as represented by the
4# Administrator of the National Aeronautics and Space Administration.
5# All Rights Reserved.
6#
7# Licensed under the Apache License, Version 2.0 (the "License"); you may
8# not use this file except in compliance with the License. You may obtain
9# a copy of the License at
10#
11# http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16# License for the specific language governing permissions and limitations
17# under the License.
18"""Database setup and migration commands."""
19
20from nova import flags
21from nova import utils
22
23FLAGS = flags.FLAGS
24flags.DECLARE('db_backend', 'nova.db.api')
25
26
27IMPL = utils.LazyPluggable(FLAGS['db_backend'],
28 sqlalchemy='nova.db.sqlalchemy.migration')
29
30
31def db_sync(version=None):
32 """Migrate the database to `version` or the most recent version."""
33 return IMPL.db_sync(version=version)
34
35
36def db_version():
37 """Display the current database version."""
38 return IMPL.db_version()
039
=== modified file 'nova/db/sqlalchemy/__init__.py'
--- nova/db/sqlalchemy/__init__.py 2011-01-07 19:49:07 +0000
+++ nova/db/sqlalchemy/__init__.py 2011-01-19 01:35:10 +0000
@@ -15,31 +15,3 @@
15# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the15# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16# License for the specific language governing permissions and limitations16# License for the specific language governing permissions and limitations
17# under the License.17# under the License.
18
19"""
20SQLAlchemy database backend
21"""
22import time
23
24from sqlalchemy.exc import OperationalError
25
26from nova import flags
27from nova import log as logging
28from nova.db.sqlalchemy import models
29
30
31FLAGS = flags.FLAGS
32LOG = logging.getLogger('nova.db.sqlalchemy')
33
34
35for i in xrange(FLAGS.sql_max_retries):
36 if i > 0:
37 time.sleep(FLAGS.sql_retry_interval)
38
39 try:
40 models.register_models()
41 break
42 except OperationalError:
43 LOG.exception(_("Data store %s is unreachable."
44 " Trying again in %d seconds."),
45 FLAGS.sql_connection, FLAGS.sql_retry_interval)
4618
=== added directory 'nova/db/sqlalchemy/migrate_repo'
=== added file 'nova/db/sqlalchemy/migrate_repo/README'
--- nova/db/sqlalchemy/migrate_repo/README 1970-01-01 00:00:00 +0000
+++ nova/db/sqlalchemy/migrate_repo/README 2011-01-19 01:35:10 +0000
@@ -0,0 +1,4 @@
1This is a database migration repository.
2
3More information at
4http://code.google.com/p/sqlalchemy-migrate/
05
=== added file 'nova/db/sqlalchemy/migrate_repo/__init__.py'
=== added file 'nova/db/sqlalchemy/migrate_repo/manage.py'
--- nova/db/sqlalchemy/migrate_repo/manage.py 1970-01-01 00:00:00 +0000
+++ nova/db/sqlalchemy/migrate_repo/manage.py 2011-01-19 01:35:10 +0000
@@ -0,0 +1,4 @@
1#!/usr/bin/env python
2from migrate.versioning.shell import main
3if __name__ == '__main__':
4 main(debug='False', repository='.')
05
=== added file 'nova/db/sqlalchemy/migrate_repo/migrate.cfg'
--- nova/db/sqlalchemy/migrate_repo/migrate.cfg 1970-01-01 00:00:00 +0000
+++ nova/db/sqlalchemy/migrate_repo/migrate.cfg 2011-01-19 01:35:10 +0000
@@ -0,0 +1,20 @@
1[db_settings]
2# Used to identify which repository this database is versioned under.
3# You can use the name of your project.
4repository_id=nova
5
6# The name of the database table used to track the schema version.
7# This name shouldn't already be used by your project.
8# If this is changed once a database is under version control, you'll need to
9# change the table name in each database too.
10version_table=migrate_version
11
12# When committing a change script, Migrate will attempt to generate the
13# sql for all supported databases; normally, if one of them fails - probably
14# because you don't have that database installed - it is ignored and the
15# commit continues, perhaps ending successfully.
16# Databases in this list MUST compile successfully during a commit, or the
17# entire commit will fail. List the databases your application will actually
18# be using to ensure your updates to that database work properly.
19# This must be a list; example: ['postgres','sqlite']
20required_dbs=[]
021
=== added directory 'nova/db/sqlalchemy/migrate_repo/versions'
=== added file 'nova/db/sqlalchemy/migrate_repo/versions/001_austin.py'
--- nova/db/sqlalchemy/migrate_repo/versions/001_austin.py 1970-01-01 00:00:00 +0000
+++ nova/db/sqlalchemy/migrate_repo/versions/001_austin.py 2011-01-19 01:35:10 +0000
@@ -0,0 +1,547 @@
1# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3# Copyright 2010 United States Government as represented by the
4# Administrator of the National Aeronautics and Space Administration.
5# All Rights Reserved.
6#
7# Licensed under the Apache License, Version 2.0 (the "License"); you may
8# not use this file except in compliance with the License. You may obtain
9# a copy of the License at
10#
11# http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16# License for the specific language governing permissions and limitations
17# under the License.
18
19## Table code mostly autogenerated by genmodel.py
20from sqlalchemy import *
21from migrate import *
22
23from nova import log as logging
24
25
26meta = MetaData()
27
28
29auth_tokens = Table('auth_tokens', meta,
30 Column('created_at', DateTime(timezone=False)),
31 Column('updated_at', DateTime(timezone=False)),
32 Column('deleted_at', DateTime(timezone=False)),
33 Column('deleted', Boolean(create_constraint=True, name=None)),
34 Column('token_hash',
35 String(length=255, convert_unicode=False, assert_unicode=None,
36 unicode_error=None, _warn_on_bytestring=False),
37 primary_key=True,
38 nullable=False),
39 Column('user_id', Integer()),
40 Column('server_manageent_url',
41 String(length=255, convert_unicode=False, assert_unicode=None,
42 unicode_error=None, _warn_on_bytestring=False)),
43 Column('storage_url',
44 String(length=255, convert_unicode=False, assert_unicode=None,
45 unicode_error=None, _warn_on_bytestring=False)),
46 Column('cdn_management_url',
47 String(length=255, convert_unicode=False, assert_unicode=None,
48 unicode_error=None, _warn_on_bytestring=False)),
49 )
50
51
52export_devices = Table('export_devices', meta,
53 Column('created_at', DateTime(timezone=False)),
54 Column('updated_at', DateTime(timezone=False)),
55 Column('deleted_at', DateTime(timezone=False)),
56 Column('deleted', Boolean(create_constraint=True, name=None)),
57 Column('id', Integer(), primary_key=True, nullable=False),
58 Column('shelf_id', Integer()),
59 Column('blade_id', Integer()),
60 Column('volume_id',
61 Integer(),
62 ForeignKey('volumes.id'),
63 nullable=True),
64 )
65
66
67fixed_ips = Table('fixed_ips', meta,
68 Column('created_at', DateTime(timezone=False)),
69 Column('updated_at', DateTime(timezone=False)),
70 Column('deleted_at', DateTime(timezone=False)),
71 Column('deleted', Boolean(create_constraint=True, name=None)),
72 Column('id', Integer(), primary_key=True, nullable=False),
73 Column('address',
74 String(length=255, convert_unicode=False, assert_unicode=None,
75 unicode_error=None, _warn_on_bytestring=False)),
76 Column('network_id',
77 Integer(),
78 ForeignKey('networks.id'),
79 nullable=True),
80 Column('instance_id',
81 Integer(),
82 ForeignKey('instances.id'),
83 nullable=True),
84 Column('allocated', Boolean(create_constraint=True, name=None)),
85 Column('leased', Boolean(create_constraint=True, name=None)),
86 Column('reserved', Boolean(create_constraint=True, name=None)),
87 )
88
89
90floating_ips = Table('floating_ips', meta,
91 Column('created_at', DateTime(timezone=False)),
92 Column('updated_at', DateTime(timezone=False)),
93 Column('deleted_at', DateTime(timezone=False)),
94 Column('deleted', Boolean(create_constraint=True, name=None)),
95 Column('id', Integer(), primary_key=True, nullable=False),
96 Column('address',
97 String(length=255, convert_unicode=False, assert_unicode=None,
98 unicode_error=None, _warn_on_bytestring=False)),
99 Column('fixed_ip_id',
100 Integer(),
101 ForeignKey('fixed_ips.id'),
102 nullable=True),
103 Column('project_id',
104 String(length=255, convert_unicode=False, assert_unicode=None,
105 unicode_error=None, _warn_on_bytestring=False)),
106 Column('host',
107 String(length=255, convert_unicode=False, assert_unicode=None,
108 unicode_error=None, _warn_on_bytestring=False)),
109 )
110
111
112instances = Table('instances', meta,
113 Column('created_at', DateTime(timezone=False)),
114 Column('updated_at', DateTime(timezone=False)),
115 Column('deleted_at', DateTime(timezone=False)),
116 Column('deleted', Boolean(create_constraint=True, name=None)),
117 Column('id', Integer(), primary_key=True, nullable=False),
118 Column('internal_id', Integer()),
119 Column('admin_pass',
120 String(length=255, convert_unicode=False, assert_unicode=None,
121 unicode_error=None, _warn_on_bytestring=False)),
122 Column('user_id',
123 String(length=255, convert_unicode=False, assert_unicode=None,
124 unicode_error=None, _warn_on_bytestring=False)),
125 Column('project_id',
126 String(length=255, convert_unicode=False, assert_unicode=None,
127 unicode_error=None, _warn_on_bytestring=False)),
128 Column('image_id',
129 String(length=255, convert_unicode=False, assert_unicode=None,
130 unicode_error=None, _warn_on_bytestring=False)),
131 Column('kernel_id',
132 String(length=255, convert_unicode=False, assert_unicode=None,
133 unicode_error=None, _warn_on_bytestring=False)),
134 Column('ramdisk_id',
135 String(length=255, convert_unicode=False, assert_unicode=None,
136 unicode_error=None, _warn_on_bytestring=False)),
137 Column('launch_index', Integer()),
138 Column('key_name',
139 String(length=255, convert_unicode=False, assert_unicode=None,
140 unicode_error=None, _warn_on_bytestring=False)),
141 Column('key_data',
142 Text(length=None, convert_unicode=False, assert_unicode=None,
143 unicode_error=None, _warn_on_bytestring=False)),
144 Column('state', Integer()),
145 Column('state_description',
146 String(length=255, convert_unicode=False, assert_unicode=None,
147 unicode_error=None, _warn_on_bytestring=False)),
148 Column('memory_mb', Integer()),
149 Column('vcpus', Integer()),
150 Column('local_gb', Integer()),
151 Column('hostname',
152 String(length=255, convert_unicode=False, assert_unicode=None,
153 unicode_error=None, _warn_on_bytestring=False)),
154 Column('host',
155 String(length=255, convert_unicode=False, assert_unicode=None,
156 unicode_error=None, _warn_on_bytestring=False)),
157 Column('instance_type',
158 String(length=255, convert_unicode=False, assert_unicode=None,
159 unicode_error=None, _warn_on_bytestring=False)),
160 Column('user_data',
161 Text(length=None, convert_unicode=False, assert_unicode=None,
162 unicode_error=None, _warn_on_bytestring=False)),
163 Column('reservation_id',
164 String(length=255, convert_unicode=False, assert_unicode=None,
165 unicode_error=None, _warn_on_bytestring=False)),
166 Column('mac_address',
167 String(length=255, convert_unicode=False, assert_unicode=None,
168 unicode_error=None, _warn_on_bytestring=False)),
169 Column('scheduled_at', DateTime(timezone=False)),
170 Column('launched_at', DateTime(timezone=False)),
171 Column('terminated_at', DateTime(timezone=False)),
172 Column('display_name',
173 String(length=255, convert_unicode=False, assert_unicode=None,
174 unicode_error=None, _warn_on_bytestring=False)),
175 Column('display_description',
176 String(length=255, convert_unicode=False, assert_unicode=None,
177 unicode_error=None, _warn_on_bytestring=False)),
178 )
179
180
181iscsi_targets = Table('iscsi_targets', meta,
182 Column('created_at', DateTime(timezone=False)),
183 Column('updated_at', DateTime(timezone=False)),
184 Column('deleted_at', DateTime(timezone=False)),
185 Column('deleted', Boolean(create_constraint=True, name=None)),
186 Column('id', Integer(), primary_key=True, nullable=False),
187 Column('target_num', Integer()),
188 Column('host',
189 String(length=255, convert_unicode=False, assert_unicode=None,
190 unicode_error=None, _warn_on_bytestring=False)),
191 Column('volume_id',
192 Integer(),
193 ForeignKey('volumes.id'),
194 nullable=True),
195 )
196
197
198key_pairs = Table('key_pairs', meta,
199 Column('created_at', DateTime(timezone=False)),
200 Column('updated_at', DateTime(timezone=False)),
201 Column('deleted_at', DateTime(timezone=False)),
202 Column('deleted', Boolean(create_constraint=True, name=None)),
203 Column('id', Integer(), primary_key=True, nullable=False),
204 Column('name',
205 String(length=255, convert_unicode=False, assert_unicode=None,
206 unicode_error=None, _warn_on_bytestring=False)),
207 Column('user_id',
208 String(length=255, convert_unicode=False, assert_unicode=None,
209 unicode_error=None, _warn_on_bytestring=False)),
210 Column('fingerprint',
211 String(length=255, convert_unicode=False, assert_unicode=None,
212 unicode_error=None, _warn_on_bytestring=False)),
213 Column('public_key',
214 Text(length=None, convert_unicode=False, assert_unicode=None,
215 unicode_error=None, _warn_on_bytestring=False)),
216 )
217
218
219networks = Table('networks', meta,
220 Column('created_at', DateTime(timezone=False)),
221 Column('updated_at', DateTime(timezone=False)),
222 Column('deleted_at', DateTime(timezone=False)),
223 Column('deleted', Boolean(create_constraint=True, name=None)),
224 Column('id', Integer(), primary_key=True, nullable=False),
225 Column('injected', Boolean(create_constraint=True, name=None)),
226 Column('cidr',
227 String(length=255, convert_unicode=False, assert_unicode=None,
228 unicode_error=None, _warn_on_bytestring=False)),
229 Column('netmask',
230 String(length=255, convert_unicode=False, assert_unicode=None,
231 unicode_error=None, _warn_on_bytestring=False)),
232 Column('bridge',
233 String(length=255, convert_unicode=False, assert_unicode=None,
234 unicode_error=None, _warn_on_bytestring=False)),
235 Column('gateway',
236 String(length=255, convert_unicode=False, assert_unicode=None,
237 unicode_error=None, _warn_on_bytestring=False)),
238 Column('broadcast',
239 String(length=255, convert_unicode=False, assert_unicode=None,
240 unicode_error=None, _warn_on_bytestring=False)),
241 Column('dns',
242 String(length=255, convert_unicode=False, assert_unicode=None,
243 unicode_error=None, _warn_on_bytestring=False)),
244 Column('vlan', Integer()),
245 Column('vpn_public_address',
246 String(length=255, convert_unicode=False, assert_unicode=None,
247 unicode_error=None, _warn_on_bytestring=False)),
248 Column('vpn_public_port', Integer()),
249 Column('vpn_private_address',
250 String(length=255, convert_unicode=False, assert_unicode=None,
251 unicode_error=None, _warn_on_bytestring=False)),
252 Column('dhcp_start',
253 String(length=255, convert_unicode=False, assert_unicode=None,
254 unicode_error=None, _warn_on_bytestring=False)),
255 Column('project_id',
256 String(length=255, convert_unicode=False, assert_unicode=None,
257 unicode_error=None, _warn_on_bytestring=False)),
258 Column('host',
259 String(length=255, convert_unicode=False, assert_unicode=None,
260 unicode_error=None, _warn_on_bytestring=False)),
261 )
262
263
264projects = Table('projects', meta,
265 Column('created_at', DateTime(timezone=False)),
266 Column('updated_at', DateTime(timezone=False)),
267 Column('deleted_at', DateTime(timezone=False)),
268 Column('deleted', Boolean(create_constraint=True, name=None)),
269 Column('id',
270 String(length=255, convert_unicode=False, assert_unicode=None,
271 unicode_error=None, _warn_on_bytestring=False),
272 primary_key=True,
273 nullable=False),
274 Column('name',
275 String(length=255, convert_unicode=False, assert_unicode=None,
276 unicode_error=None, _warn_on_bytestring=False)),
277 Column('description',
278 String(length=255, convert_unicode=False, assert_unicode=None,
279 unicode_error=None, _warn_on_bytestring=False)),
280 Column('project_manager',
281 String(length=255, convert_unicode=False, assert_unicode=None,
282 unicode_error=None, _warn_on_bytestring=False),
283 ForeignKey('users.id')),
284 )
285
286
287quotas = Table('quotas', meta,
288 Column('created_at', DateTime(timezone=False)),
289 Column('updated_at', DateTime(timezone=False)),
290 Column('deleted_at', DateTime(timezone=False)),
291 Column('deleted', Boolean(create_constraint=True, name=None)),
292 Column('id', Integer(), primary_key=True, nullable=False),
293 Column('project_id',
294 String(length=255, convert_unicode=False, assert_unicode=None,
295 unicode_error=None, _warn_on_bytestring=False)),
296 Column('instances', Integer()),
297 Column('cores', Integer()),
298 Column('volumes', Integer()),
299 Column('gigabytes', Integer()),
300 Column('floating_ips', Integer()),
301 )
302
303
304security_groups = Table('security_groups', meta,
305 Column('created_at', DateTime(timezone=False)),
306 Column('updated_at', DateTime(timezone=False)),
307 Column('deleted_at', DateTime(timezone=False)),
308 Column('deleted', Boolean(create_constraint=True, name=None)),
309 Column('id', Integer(), primary_key=True, nullable=False),
310 Column('name',
311 String(length=255, convert_unicode=False, assert_unicode=None,
312 unicode_error=None, _warn_on_bytestring=False)),
313 Column('description',
314 String(length=255, convert_unicode=False, assert_unicode=None,
315 unicode_error=None, _warn_on_bytestring=False)),
316 Column('user_id',
317 String(length=255, convert_unicode=False, assert_unicode=None,
318 unicode_error=None, _warn_on_bytestring=False)),
319 Column('project_id',
320 String(length=255, convert_unicode=False, assert_unicode=None,
321 unicode_error=None, _warn_on_bytestring=False)),
322 )
323
324
325security_group_inst_assoc = Table('security_group_instance_association', meta,
326 Column('created_at', DateTime(timezone=False)),
327 Column('updated_at', DateTime(timezone=False)),
328 Column('deleted_at', DateTime(timezone=False)),
329 Column('deleted', Boolean(create_constraint=True, name=None)),
330 Column('id', Integer(), primary_key=True, nullable=False),
331 Column('security_group_id',
332 Integer(),
333 ForeignKey('security_groups.id')),
334 Column('instance_id', Integer(), ForeignKey('instances.id')),
335 )
336
337
338security_group_rules = Table('security_group_rules', meta,
339 Column('created_at', DateTime(timezone=False)),
340 Column('updated_at', DateTime(timezone=False)),
341 Column('deleted_at', DateTime(timezone=False)),
342 Column('deleted', Boolean(create_constraint=True, name=None)),
343 Column('id', Integer(), primary_key=True, nullable=False),
344 Column('parent_group_id',
345 Integer(),
346 ForeignKey('security_groups.id')),
347 Column('protocol',
348 String(length=255, convert_unicode=False, assert_unicode=None,
349 unicode_error=None, _warn_on_bytestring=False)),
350 Column('from_port', Integer()),
351 Column('to_port', Integer()),
352 Column('cidr',
353 String(length=255, convert_unicode=False, assert_unicode=None,
354 unicode_error=None, _warn_on_bytestring=False)),
355 Column('group_id',
356 Integer(),
357 ForeignKey('security_groups.id')),
358 )
359
360
361services = Table('services', meta,
362 Column('created_at', DateTime(timezone=False)),
363 Column('updated_at', DateTime(timezone=False)),
364 Column('deleted_at', DateTime(timezone=False)),
365 Column('deleted', Boolean(create_constraint=True, name=None)),
366 Column('id', Integer(), primary_key=True, nullable=False),
367 Column('host',
368 String(length=255, convert_unicode=False, assert_unicode=None,
369 unicode_error=None, _warn_on_bytestring=False)),
370 Column('binary',
371 String(length=255, convert_unicode=False, assert_unicode=None,
372 unicode_error=None, _warn_on_bytestring=False)),
373 Column('topic',
374 String(length=255, convert_unicode=False, assert_unicode=None,
375 unicode_error=None, _warn_on_bytestring=False)),
376 Column('report_count', Integer(), nullable=False),
377 Column('disabled', Boolean(create_constraint=True, name=None)),
378 )
379
380
381users = Table('users', meta,
382 Column('created_at', DateTime(timezone=False)),
383 Column('updated_at', DateTime(timezone=False)),
384 Column('deleted_at', DateTime(timezone=False)),
385 Column('deleted', Boolean(create_constraint=True, name=None)),
386 Column('id',
387 String(length=255, convert_unicode=False, assert_unicode=None,
388 unicode_error=None, _warn_on_bytestring=False),
389 primary_key=True,
390 nullable=False),
391 Column('name',
392 String(length=255, convert_unicode=False, assert_unicode=None,
393 unicode_error=None, _warn_on_bytestring=False)),
394 Column('access_key',
395 String(length=255, convert_unicode=False, assert_unicode=None,
396 unicode_error=None, _warn_on_bytestring=False)),
397 Column('secret_key',
398 String(length=255, convert_unicode=False, assert_unicode=None,
399 unicode_error=None, _warn_on_bytestring=False)),
400 Column('is_admin', Boolean(create_constraint=True, name=None)),
401 )
402
403
404user_project_association = Table('user_project_association', meta,
405 Column('created_at', DateTime(timezone=False)),
406 Column('updated_at', DateTime(timezone=False)),
407 Column('deleted_at', DateTime(timezone=False)),
408 Column('deleted', Boolean(create_constraint=True, name=None)),
409 Column('user_id',
410 String(length=255, convert_unicode=False, assert_unicode=None,
411 unicode_error=None, _warn_on_bytestring=False),
412 ForeignKey('users.id'),
413 primary_key=True,
414 nullable=False),
415 Column('project_id',
416 String(length=255, convert_unicode=False, assert_unicode=None,
417 unicode_error=None, _warn_on_bytestring=False),
418 ForeignKey('projects.id'),
419 primary_key=True,
420 nullable=False),
421 )
422
423
424user_project_role_association = Table('user_project_role_association', meta,
425 Column('created_at', DateTime(timezone=False)),
426 Column('updated_at', DateTime(timezone=False)),
427 Column('deleted_at', DateTime(timezone=False)),
428 Column('deleted', Boolean(create_constraint=True, name=None)),
429 Column('user_id',
430 String(length=255, convert_unicode=False, assert_unicode=None,
431 unicode_error=None, _warn_on_bytestring=False),
432 primary_key=True,
433 nullable=False),
434 Column('project_id',
435 String(length=255, convert_unicode=False, assert_unicode=None,
436 unicode_error=None, _warn_on_bytestring=False),
437 primary_key=True,
438 nullable=False),
439 Column('role',
440 String(length=255, convert_unicode=False, assert_unicode=None,
441 unicode_error=None, _warn_on_bytestring=False),
442 primary_key=True,
443 nullable=False),
444 ForeignKeyConstraint(['user_id',
445 'project_id'],
446 ['user_project_association.user_id',
447 'user_project_association.project_id']),
448 )
449
450
451user_role_association = Table('user_role_association', meta,
452 Column('created_at', DateTime(timezone=False)),
453 Column('updated_at', DateTime(timezone=False)),
454 Column('deleted_at', DateTime(timezone=False)),
455 Column('deleted', Boolean(create_constraint=True, name=None)),
456 Column('user_id',
457 String(length=255, convert_unicode=False, assert_unicode=None,
458 unicode_error=None, _warn_on_bytestring=False),
459 ForeignKey('users.id'),
460 primary_key=True,
461 nullable=False),
462 Column('role',
463 String(length=255, convert_unicode=False, assert_unicode=None,
464 unicode_error=None, _warn_on_bytestring=False),
465 primary_key=True,
466 nullable=False),
467 )
468
469
470volumes = Table('volumes', meta,
471 Column('created_at', DateTime(timezone=False)),
472 Column('updated_at', DateTime(timezone=False)),
473 Column('deleted_at', DateTime(timezone=False)),
474 Column('deleted', Boolean(create_constraint=True, name=None)),
475 Column('id', Integer(), primary_key=True, nullable=False),
476 Column('ec2_id',
477 String(length=255, convert_unicode=False, assert_unicode=None,
478 unicode_error=None, _warn_on_bytestring=False)),
479 Column('user_id',
480 String(length=255, convert_unicode=False, assert_unicode=None,
481 unicode_error=None, _warn_on_bytestring=False)),
482 Column('project_id',
483 String(length=255, convert_unicode=False, assert_unicode=None,
484 unicode_error=None, _warn_on_bytestring=False)),
485 Column('host',
486 String(length=255, convert_unicode=False, assert_unicode=None,
487 unicode_error=None, _warn_on_bytestring=False)),
488 Column('size', Integer()),
489 Column('availability_zone',
490 String(length=255, convert_unicode=False, assert_unicode=None,
491 unicode_error=None, _warn_on_bytestring=False)),
492 Column('instance_id',
493 Integer(),
494 ForeignKey('instances.id'),
495 nullable=True),
496 Column('mountpoint',
497 String(length=255, convert_unicode=False, assert_unicode=None,
498 unicode_error=None, _warn_on_bytestring=False)),
499 Column('attach_time',
500 String(length=255, convert_unicode=False, assert_unicode=None,
501 unicode_error=None, _warn_on_bytestring=False)),
502 Column('status',
503 String(length=255, convert_unicode=False, assert_unicode=None,
504 unicode_error=None, _warn_on_bytestring=False)),
505 Column('attach_status',
506 String(length=255, convert_unicode=False, assert_unicode=None,
507 unicode_error=None, _warn_on_bytestring=False)),
508 Column('scheduled_at', DateTime(timezone=False)),
509 Column('launched_at', DateTime(timezone=False)),
510 Column('terminated_at', DateTime(timezone=False)),
511 Column('display_name',
512 String(length=255, convert_unicode=False, assert_unicode=None,
513 unicode_error=None, _warn_on_bytestring=False)),
514 Column('display_description',
515 String(length=255, convert_unicode=False, assert_unicode=None,
516 unicode_error=None, _warn_on_bytestring=False)),
517 )
518
519
520def upgrade(migrate_engine):
521 # Upgrade operations go here. Don't create your own engine;
522 # bind migrate_engine to your metadata
523 meta.bind = migrate_engine
524
525 for table in (auth_tokens, export_devices, fixed_ips, floating_ips,
526 instances, iscsi_targets, key_pairs, networks,
527 projects, quotas, security_groups, security_group_inst_assoc,
528 security_group_rules, services, users,
529 user_project_association, user_project_role_association,
530 user_role_association, volumes):
531 try:
532 table.create()
533 except Exception:
534 logging.info(repr(table))
535 logging.exception('Exception while creating table')
536 raise
537
538
539def downgrade(migrate_engine):
540 # Operations to reverse the above upgrade go here.
541 for table in (auth_tokens, export_devices, fixed_ips, floating_ips,
542 instances, iscsi_targets, key_pairs, networks,
543 projects, quotas, security_groups, security_group_inst_assoc,
544 security_group_rules, services, users,
545 user_project_association, user_project_role_association,
546 user_role_association, volumes):
547 table.drop()
0548
=== added file 'nova/db/sqlalchemy/migrate_repo/versions/002_bexar.py'
--- nova/db/sqlalchemy/migrate_repo/versions/002_bexar.py 1970-01-01 00:00:00 +0000
+++ nova/db/sqlalchemy/migrate_repo/versions/002_bexar.py 2011-01-19 01:35:10 +0000
@@ -0,0 +1,209 @@
1# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3# Copyright 2010 United States Government as represented by the
4# Administrator of the National Aeronautics and Space Administration.
5# All Rights Reserved.
6#
7# Licensed under the Apache License, Version 2.0 (the "License"); you may
8# not use this file except in compliance with the License. You may obtain
9# a copy of the License at
10#
11# http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16# License for the specific language governing permissions and limitations
17# under the License.
18
19from sqlalchemy import *
20from migrate import *
21
22from nova import log as logging
23
24
25meta = MetaData()
26
27
28# Just for the ForeignKey and column creation to succeed, these are not the
29# actual definitions of instances or services.
30instances = Table('instances', meta,
31 Column('id', Integer(), primary_key=True, nullable=False),
32 )
33
34
35services = Table('services', meta,
36 Column('id', Integer(), primary_key=True, nullable=False),
37 )
38
39
40networks = Table('networks', meta,
41 Column('id', Integer(), primary_key=True, nullable=False),
42 )
43
44
45#
46# New Tables
47#
48certificates = Table('certificates', meta,
49 Column('created_at', DateTime(timezone=False)),
50 Column('updated_at', DateTime(timezone=False)),
51 Column('deleted_at', DateTime(timezone=False)),
52 Column('deleted', Boolean(create_constraint=True, name=None)),
53 Column('id', Integer(), primary_key=True, nullable=False),
54 Column('user_id',
55 String(length=255, convert_unicode=False, assert_unicode=None,
56 unicode_error=None, _warn_on_bytestring=False)),
57 Column('project_id',
58 String(length=255, convert_unicode=False, assert_unicode=None,
59 unicode_error=None, _warn_on_bytestring=False)),
60 Column('file_name',
61 String(length=255, convert_unicode=False, assert_unicode=None,
62 unicode_error=None, _warn_on_bytestring=False)),
63 )
64
65
66consoles = Table('consoles', meta,
67 Column('created_at', DateTime(timezone=False)),
68 Column('updated_at', DateTime(timezone=False)),
69 Column('deleted_at', DateTime(timezone=False)),
70 Column('deleted', Boolean(create_constraint=True, name=None)),
71 Column('id', Integer(), primary_key=True, nullable=False),
72 Column('instance_name',
73 String(length=255, convert_unicode=False, assert_unicode=None,
74 unicode_error=None, _warn_on_bytestring=False)),
75 Column('instance_id', Integer()),
76 Column('password',
77 String(length=255, convert_unicode=False, assert_unicode=None,
78 unicode_error=None, _warn_on_bytestring=False)),
79 Column('port', Integer(), nullable=True),
80 Column('pool_id',
81 Integer(),
82 ForeignKey('console_pools.id')),
83 )
84
85
86console_pools = Table('console_pools', meta,
87 Column('created_at', DateTime(timezone=False)),
88 Column('updated_at', DateTime(timezone=False)),
89 Column('deleted_at', DateTime(timezone=False)),
90 Column('deleted', Boolean(create_constraint=True, name=None)),
91 Column('id', Integer(), primary_key=True, nullable=False),
92 Column('address',
93 String(length=255, convert_unicode=False, assert_unicode=None,
94 unicode_error=None, _warn_on_bytestring=False)),
95 Column('username',
96 String(length=255, convert_unicode=False, assert_unicode=None,
97 unicode_error=None, _warn_on_bytestring=False)),
98 Column('password',
99 String(length=255, convert_unicode=False, assert_unicode=None,
100 unicode_error=None, _warn_on_bytestring=False)),
101 Column('console_type',
102 String(length=255, convert_unicode=False, assert_unicode=None,
103 unicode_error=None, _warn_on_bytestring=False)),
104 Column('public_hostname',
105 String(length=255, convert_unicode=False, assert_unicode=None,
106 unicode_error=None, _warn_on_bytestring=False)),
107 Column('host',
108 String(length=255, convert_unicode=False, assert_unicode=None,
109 unicode_error=None, _warn_on_bytestring=False)),
110 Column('compute_host',
111 String(length=255, convert_unicode=False, assert_unicode=None,
112 unicode_error=None, _warn_on_bytestring=False)),
113 )
114
115
116instance_actions = Table('instance_actions', meta,
117 Column('created_at', DateTime(timezone=False)),
118 Column('updated_at', DateTime(timezone=False)),
119 Column('deleted_at', DateTime(timezone=False)),
120 Column('deleted', Boolean(create_constraint=True, name=None)),
121 Column('id', Integer(), primary_key=True, nullable=False),
122 Column('instance_id',
123 Integer(),
124 ForeignKey('instances.id')),
125 Column('action',
126 String(length=255, convert_unicode=False, assert_unicode=None,
127 unicode_error=None, _warn_on_bytestring=False)),
128 Column('error',
129 Text(length=None, convert_unicode=False, assert_unicode=None,
130 unicode_error=None, _warn_on_bytestring=False)),
131 )
132
133
134#
135# Tables to alter
136#
137auth_tokens = Table('auth_tokens', meta,
138 Column('created_at', DateTime(timezone=False)),
139 Column('updated_at', DateTime(timezone=False)),
140 Column('deleted_at', DateTime(timezone=False)),
141 Column('deleted', Boolean(create_constraint=True, name=None)),
142 Column('token_hash',
143 String(length=255, convert_unicode=False, assert_unicode=None,
144 unicode_error=None, _warn_on_bytestring=False),
145 primary_key=True,
146 nullable=False),
147 Column('user_id', Integer()),
148 Column('server_manageent_url',
149 String(length=255, convert_unicode=False, assert_unicode=None,
150 unicode_error=None, _warn_on_bytestring=False)),
151 Column('storage_url',
152 String(length=255, convert_unicode=False, assert_unicode=None,
153 unicode_error=None, _warn_on_bytestring=False)),
154 Column('cdn_management_url',
155 String(length=255, convert_unicode=False, assert_unicode=None,
156 unicode_error=None, _warn_on_bytestring=False)),
157 )
158
159
160instances_availability_zone = Column(
161 'availability_zone',
162 String(length=255, convert_unicode=False, assert_unicode=None,
163 unicode_error=None, _warn_on_bytestring=False))
164
165
166instances_locked = Column('locked',
167 Boolean(create_constraint=True, name=None))
168
169
170networks_cidr_v6 = Column(
171 'cidr_v6',
172 String(length=255, convert_unicode=False, assert_unicode=None,
173 unicode_error=None, _warn_on_bytestring=False))
174
175networks_ra_server = Column(
176 'ra_server',
177 String(length=255, convert_unicode=False, assert_unicode=None,
178 unicode_error=None, _warn_on_bytestring=False))
179
180
181services_availability_zone = Column(
182 'availability_zone',
183 String(length=255, convert_unicode=False, assert_unicode=None,
184 unicode_error=None, _warn_on_bytestring=False))
185
186
187def upgrade(migrate_engine):
188 # Upgrade operations go here. Don't create your own engine;
189 # bind migrate_engine to your metadata
190 meta.bind = migrate_engine
191 for table in (certificates, consoles, console_pools, instance_actions):
192 try:
193 table.create()
194 except Exception:
195 logging.info(repr(table))
196 logging.exception('Exception while creating table')
197 raise
198
199 auth_tokens.c.user_id.alter(type=String(length=255,
200 convert_unicode=False,
201 assert_unicode=None,
202 unicode_error=None,
203 _warn_on_bytestring=False))
204
205 instances.create_column(instances_availability_zone)
206 instances.create_column(instances_locked)
207 networks.create_column(networks_cidr_v6)
208 networks.create_column(networks_ra_server)
209 services.create_column(services_availability_zone)
0210
=== added file 'nova/db/sqlalchemy/migrate_repo/versions/__init__.py'
=== added file 'nova/db/sqlalchemy/migration.py'
--- nova/db/sqlalchemy/migration.py 1970-01-01 00:00:00 +0000
+++ nova/db/sqlalchemy/migration.py 2011-01-19 01:35:10 +0000
@@ -0,0 +1,72 @@
1# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3# Copyright 2010 United States Government as represented by the
4# Administrator of the National Aeronautics and Space Administration.
5# All Rights Reserved.
6#
7# Licensed under the Apache License, Version 2.0 (the "License"); you may
8# not use this file except in compliance with the License. You may obtain
9# a copy of the License at
10#
11# http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16# License for the specific language governing permissions and limitations
17# under the License.
18
19import os
20
21from nova import flags
22
23import sqlalchemy
24from migrate.versioning import api as versioning_api
25from migrate.versioning import exceptions as versioning_exceptions
26
27FLAGS = flags.FLAGS
28
29
30def db_sync(version=None):
31 db_version()
32 repo_path = _find_migrate_repo()
33 return versioning_api.upgrade(FLAGS.sql_connection, repo_path, version)
34
35
36def db_version():
37 repo_path = _find_migrate_repo()
38 try:
39 return versioning_api.db_version(FLAGS.sql_connection, repo_path)
40 except versioning_exceptions.DatabaseNotControlledError:
41 # If we aren't version controlled we may already have the database
42 # in the state from before we started version control, check for that
43 # and set up version_control appropriately
44 meta = sqlalchemy.MetaData()
45 engine = sqlalchemy.create_engine(FLAGS.sql_connection, echo=False)
46 meta.reflect(bind=engine)
47 try:
48 for table in ('auth_tokens', 'export_devices', 'fixed_ips',
49 'floating_ips', 'instances', 'iscsi_targets',
50 'key_pairs', 'networks', 'projects', 'quotas',
51 'security_group_rules',
52 'security_group_instance_association', 'services',
53 'users', 'user_project_association',
54 'user_project_role_association', 'volumes'):
55 assert table in meta.tables
56 return db_version_control(1)
57 except AssertionError:
58 return db_version_control(0)
59
60
61def db_version_control(version=None):
62 repo_path = _find_migrate_repo()
63 versioning_api.version_control(FLAGS.sql_connection, repo_path, version)
64 return version
65
66
67def _find_migrate_repo():
68 """Get the path for the migrate repository."""
69 path = os.path.join(os.path.abspath(os.path.dirname(__file__)),
70 'migrate_repo')
71 assert os.path.exists(path)
72 return path
073
=== modified file 'nova/db/sqlalchemy/models.py'
--- nova/db/sqlalchemy/models.py 2011-01-18 19:01:16 +0000
+++ nova/db/sqlalchemy/models.py 2011-01-19 01:35:10 +0000
@@ -100,51 +100,6 @@
100 return local.iteritems()100 return local.iteritems()
101101
102102
103# TODO(vish): Store images in the database instead of file system
104#class Image(BASE, NovaBase):
105# """Represents an image in the datastore"""
106# __tablename__ = 'images'
107# id = Column(Integer, primary_key=True)
108# ec2_id = Column(String(12), unique=True)
109# user_id = Column(String(255))
110# project_id = Column(String(255))
111# image_type = Column(String(255))
112# public = Column(Boolean, default=False)
113# state = Column(String(255))
114# location = Column(String(255))
115# arch = Column(String(255))
116# default_kernel_id = Column(String(255))
117# default_ramdisk_id = Column(String(255))
118#
119# @validates('image_type')
120# def validate_image_type(self, key, image_type):
121# assert(image_type in ['machine', 'kernel', 'ramdisk', 'raw'])
122#
123# @validates('state')
124# def validate_state(self, key, state):
125# assert(state in ['available', 'pending', 'disabled'])
126#
127# @validates('default_kernel_id')
128# def validate_kernel_id(self, key, val):
129# if val != 'machine':
130# assert(val is None)
131#
132# @validates('default_ramdisk_id')
133# def validate_ramdisk_id(self, key, val):
134# if val != 'machine':
135# assert(val is None)
136#
137#
138# TODO(vish): To make this into its own table, we need a good place to
139# create the host entries. In config somwhere? Or the first
140# time any object sets host? This only becomes particularly
141# important if we need to store per-host data.
142#class Host(BASE, NovaBase):
143# """Represents a host where services are running"""
144# __tablename__ = 'hosts'
145# id = Column(String(255), primary_key=True)
146
147
148class Service(BASE, NovaBase):103class Service(BASE, NovaBase):
149 """Represents a running service on a host."""104 """Represents a running service on a host."""
150105
151106
=== modified file 'nova/service.py'
--- nova/service.py 2011-01-18 19:01:16 +0000
+++ nova/service.py 2011-01-19 01:35:10 +0000
@@ -209,19 +209,6 @@
209 self.model_disconnected = True209 self.model_disconnected = True
210 logging.exception(_("model server went away"))210 logging.exception(_("model server went away"))
211211
212 try:
213 # NOTE(vish): This is late-loaded to make sure that the
214 # database is not created before flags have
215 # been loaded.
216 from nova.db.sqlalchemy import models
217 models.register_models()
218 except OperationalError:
219 logging.exception(_("Data store %s is unreachable."
220 " Trying again in %d seconds.") %
221 (FLAGS.sql_connection,
222 FLAGS.sql_retry_interval))
223 time.sleep(FLAGS.sql_retry_interval)
224
225212
226def serve(*services):213def serve(*services):
227 FLAGS(sys.argv)214 FLAGS(sys.argv)
228215
=== modified file 'nova/tests/__init__.py'
--- nova/tests/__init__.py 2010-12-11 20:10:24 +0000
+++ nova/tests/__init__.py 2011-01-19 01:35:10 +0000
@@ -34,3 +34,8 @@
34# The code below enables nosetests to work with i18n _() blocks34# The code below enables nosetests to work with i18n _() blocks
35import __builtin__35import __builtin__
36setattr(__builtin__, '_', lambda x: x)36setattr(__builtin__, '_', lambda x: x)
37
38
39def setup():
40 from nova.db import migration
41 migration.db_sync()
3742
=== modified file 'run_tests.py'
--- run_tests.py 2011-01-04 20:57:18 +0000
+++ run_tests.py 2011-01-19 01:35:10 +0000
@@ -17,7 +17,7 @@
17# See the License for the specific language governing permissions and17# See the License for the specific language governing permissions and
18# limitations under the License.18# limitations under the License.
1919
2020import gettext
21import os21import os
22import unittest22import unittest
23import sys23import sys
2424
=== modified file 'tools/pip-requires'
--- tools/pip-requires 2011-01-14 15:51:42 +0000
+++ tools/pip-requires 2011-01-19 01:35:10 +0000
@@ -25,5 +25,6 @@
25Twisted>=10.1.025Twisted>=10.1.0
26PasteDeploy26PasteDeploy
27paste27paste
28sqlalchemy-migrate
28netaddr29netaddr
29glance30glance