diff options
author | Lorin Hochstein <lorinh@gmail.com> | 2014-10-05 18:17:05 -0400 |
---|---|---|
committer | Lorin Hochstein <lorinh@gmail.com> | 2014-10-05 18:17:05 -0400 |
commit | fda249cad7a99b8ab6097ba0dac5385480c0834b (patch) | |
tree | 2105cd630c14c543a589c517617d9609f7f019c7 | |
parent | 8f2b98bf2b38cfa72c37e8cd8d906723bff86d4e (diff) | |
parent | f5e36d4c354dafb07d80f8d158f189f70d3b7e04 (diff) | |
download | openstack-ansible-modules-fda249cad7a99b8ab6097ba0dac5385480c0834b.tar.gz |
Merge pull request #20 from ObjectifLibre/glance_manage-icehouse
Add icehouse support to glance_manage
-rw-r--r-- | glance_manage | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/glance_manage b/glance_manage index e02f75e..b88c9b6 100644 --- a/glance_manage +++ b/glance_manage @@ -24,23 +24,39 @@ EXAMPLES = ''' glance_manage: action=dbsync ''' +import glance # this is necessary starting from havana release due to bug 885529 # https://bugs.launchpad.net/glance/+bug/885529 from glance.openstack.common import gettextutils gettextutils.install('glance') import glance.db.sqlalchemy.api +glance_found = True try: from glance.db.sqlalchemy import migration from glance.common.exception import DatabaseMigrationError from migrate.versioning import api as versioning_api except ImportError: - glance_found = False -else: - glance_found = True + try: + # Icehouse imports + from glance.openstack.common.db.sqlalchemy import migration + from glance.openstack.common.db import options + migration.CONF = options.CONF + from migrate.versioning import api as versioning_api + + # Dummy class to make sure that the rest of the code can work whether + # we're using icehouse or not + class DatabaseMigrationError: + pass + except ImportError: + glance_found = False + +import os import subprocess +import sqlalchemy + def is_under_version_control(conf): """ Return true if the database is under version control""" migration.CONF(project='glance', default_config_files=[conf]) @@ -48,7 +64,9 @@ def is_under_version_control(conf): migration.db_version() except DatabaseMigrationError: return False - else: + # db_version() will fail with TypeError on icehouse. Icehouse uses db + # migration so we're good. + finally: return True @@ -58,8 +76,15 @@ def will_db_change(conf): if not is_under_version_control(conf): return True migration.CONF(project='glance', default_config_files=[conf]) - current_version = migration.db_version() - repo_path = migration.get_migrate_repo_path() + try: + repo_path = migration.get_migrate_repo_path() + current_version = migration.db_version() + except AttributeError: + # icehouse + repo_path = os.path.join(os.path.dirname(glance.__file__), + 'db', 'sqlalchemy', 'migrate_repo') + engine = sqlalchemy.create_engine(migration.CONF.database.connection) + current_version = migration.db_version(engine, repo_path, 0) repo_version = versioning_api.repository.Repository(repo_path).latest return current_version != repo_version |