¡@

Home 

OpenStack Study: api.py

OpenStack Index

**** CubicPower OpenStack Study ****

def configure_db():

    """Configure database.

    Establish the database, create an engine if needed, and register

    the models.

    """

    session.get_engine(sqlite_fk=True)

    register_models()

**** CubicPower OpenStack Study ****

def clear_db(base=BASE):

    unregister_models(base)

    session.cleanup()

**** CubicPower OpenStack Study ****

def get_session(autocommit=True, expire_on_commit=False):

    """Helper method to grab session."""

    return session.get_session(autocommit=autocommit,

                               expire_on_commit=expire_on_commit,

                               sqlite_fk=True)

**** CubicPower OpenStack Study ****

def register_models(base=BASE):

    """Register Models and create properties."""

    try:

        engine = session.get_engine(sqlite_fk=True)

        base.metadata.create_all(engine)

    except sql.exc.OperationalError as e:

        LOG.info(_("Database registration exception: %s"), e)

        return False

    return True

**** CubicPower OpenStack Study ****

def unregister_models(base=BASE):

    """Unregister Models, useful clearing out data before testing."""

    try:

        engine = session.get_engine(sqlite_fk=True)

        base.metadata.drop_all(engine)

    except Exception:

        LOG.exception(_("Database exception"))