<s> from logging import config as logging_config <EOL> from alembic import context <EOL> from oslo_config import cfg <EOL> from oslo_db . sqlalchemy import session <EOL> import sqlalchemy as sa <EOL> from sqlalchemy import event <EOL> from neutron . db . migration . alembic_migrations import external <EOL> from neutron . db . migration . models import head <EOL> from neutron . db import model_base <EOL> from networking_cisco . db . migration import alembic_migrations <EOL> from networking_cisco . db . migration . models import head <EOL> MYSQL_ENGINE = None <EOL> config = context . config <EOL> neutron_config = config . neutron_config <EOL> logging_config . fileConfig ( config . config_file_name ) <EOL> target_metadata = model_base . BASEV2 . metadata <EOL> def set_mysql_engine ( ) : <EOL> try : <EOL> mysql_engine = neutron_config . command . mysql_engine <EOL> except cfg . NoSuchOptError : <EOL> mysql_engine = None <EOL> global MYSQL_ENGINE <EOL> MYSQL_ENGINE = ( mysql_engine or <EOL> model_base . BASEV2 . __table_args__ [ '<STR_LIT>' ] ) <EOL> def include_object ( object , name , type_ , reflected , compare_to ) : <EOL> if type_ == '<STR_LIT>' and name in ( <EOL> set ( external . TABLES ) - set ( external . REPO_CISCO_TABLES ) ) : <EOL> return False <EOL> else : <EOL> return True <EOL> def run_migrations_offline ( ) : <EOL> """<STR_LIT>""" <EOL> set_mysql_engine ( ) <EOL> kwargs = dict ( ) <EOL> if neutron_config . database . connection : <EOL> kwargs [ '<STR_LIT:url>' ] = neutron_config . database . connection <EOL> else : <EOL> kwargs [ '<STR_LIT>' ] = neutron_config . database . engine <EOL> kwargs [ '<STR_LIT>' ] = include_object <EOL> kwargs [ '<STR_LIT>' ] = alembic_migrations . VERSION_TABLE <EOL> context . configure ( ** kwargs ) <EOL> with context . begin_transaction ( ) : <EOL> context . run_migrations ( ) <EOL> @ event . listens_for ( sa . Table , '<STR_LIT>' ) <EOL> def set_storage_engine ( target , parent ) : <EOL> if MYSQL_ENGINE : <EOL> target . kwargs [ '<STR_LIT>' ] = MYSQL_ENGINE <EOL> def run_migrations_online ( ) : <EOL> """<STR_LIT>""" <EOL> set_mysql_engine ( ) <EOL> engine = session . create_engine ( neutron_config . database . connection ) <EOL> connection = engine . connect ( ) <EOL> context . configure ( <EOL> connection = connection , <EOL> target_metadata = target_metadata , <EOL> include_object = include_object , <EOL> version_table = alembic_migrations . VERSION_TABLE <EOL> ) <EOL> try : <EOL> with context . begin_transaction ( ) : <EOL> context . run_migrations ( ) <EOL> finally : <EOL> connection . close ( ) <EOL> engine . dispose ( ) <EOL> if context . is_offline_mode ( ) : <EOL> run_migrations_offline ( ) <EOL> else : <EOL> run_migrations_online ( ) </s>
