**** CubicPower OpenStack Study ****
def upgrade(migrate_engine):
"""Add default quota class data into DB."""
meta = MetaData()
meta.bind = migrate_engine
quota_classes = Table('quota_classes', meta, autoload=True)
rows = quota_classes.count().\
where(quota_classes.c.class_name == 'default').execute().scalar()
# Do not add entries if there are already 'default' entries. We don't
# want to write over something the user added.
if rows:
LOG.info(_("Found existing 'default' entries in the quota_classes "
"table. Skipping insertion of default values."))
return
try:
#Set default volumes
qci = quota_classes.insert()
qci.execute({'created_at': CREATED_AT,
'class_name': CLASS_NAME,
'resource': 'volumes',
'hard_limit': CONF.quota_volumes,
'deleted': False, })
#Set default snapshots
qci.execute({'created_at': CREATED_AT,
'class_name': CLASS_NAME,
'resource': 'snapshots',
'hard_limit': CONF.quota_snapshots,
'deleted': False, })
#Set default gigabytes
qci.execute({'created_at': CREATED_AT,
'class_name': CLASS_NAME,
'resource': 'gigabytes',
'hard_limit': CONF.quota_gigabytes,
'deleted': False, })
LOG.info(_("Added default quota class data into the DB."))
except Exception:
LOG.error(_("Default quota class data not inserted into the DB."))
raise
**** CubicPower OpenStack Study ****
def downgrade(migrate_engine):
"""Don't delete the 'default' entries at downgrade time.
We don't know if the user had default entries when we started.
If they did, we wouldn't want to remove them. So, the safest
thing to do is just leave the 'default' entries at downgrade time.
"""
pass