Adds network model and network info cache.

The next merge will prepopulate the cache, and use the model to keep the
cache up to date.
I realize "cache" is a bit of a stretch for what this is doing.

blueprint network-info-model
blueprint compute-network-info

Change-Id: I0f0f4ba3de1310e1ff89239dab6ea8e24c85f2c8
This commit is contained in:
Trey Morris 2011-12-01 16:54:40 -06:00 committed by Trey Morris
parent d68eaf2252
commit 3160b80e7b
2 changed files with 113 additions and 0 deletions
nova/db
api.py
sqlalchemy

@ -649,6 +649,48 @@ def instance_get_id_to_uuid_mapping(context, ids):
###################
def instance_info_cache_create(context, values):
"""Create a new instance cache record in the table.
:param context: = request context object
:param values: = dict containing column values
"""
return IMPL.instance_info_cache_create(context, values)
def instance_info_cache_get(context, instance_id, session=None):
"""Gets an instance info cache from the table.
:param instance_id: = id of the info cache's instance
:param session: = optional session object
"""
return IMPL.instance_info_cache_get(context, instance_id, session=None)
def instance_info_cache_update(context, instance_id, values,
session=None):
"""Update an instance info cache record in the table.
:param instance_id: = id of info cache's instance
:param values: = dict containing column values to update
"""
return IMPL.instance_info_cache_update(context, instance_id, values,
session)
def instance_info_cache_delete_by_instance_id(context, instance_id,
session=None):
"""Deletes an existing instance_info_cache record
:param instance_id: = id of the instance tied to the cache record
"""
return IMPL.instance_info_cache_delete_by_instance_id(context, instance_id,
session)
###################
def key_pair_create(context, values):
"""Create a key_pair from the values dictionary."""
return IMPL.key_pair_create(context, values)

@ -1132,6 +1132,8 @@ def instance_destroy(context, instance_id):
update({'deleted': True,
'deleted_at': utils.utcnow(),
'updated_at': literal_column('updated_at')})
instance_info_cache_delete_by_instance_id(context, instance_id,
session=session)
@require_context
@ -1557,6 +1559,75 @@ def instance_get_id_to_uuid_mapping(context, ids):
###################
@require_context
def instance_info_cache_create(context, values):
"""Create a new instance cache record in the table.
:param context: = request context object
:param values: = dict containing column values
"""
info_cache = models.InstanceInfoCache()
info_cache['id'] = str(utils.gen_uuid())
info_cache.update(values)
session = get_session()
with session.begin():
info_cache.save(session=session)
return info_cache
@require_context
def instance_info_cache_get(context, instance_id, session=None):
"""Gets an instance info cache from the table.
:param instance_id: = id of the info cache's instance
:param session: = optional session object
"""
session = session or get_session()
info_cache = session.query(models.InstanceInfoCache).\
filter_by(instance_id=instance_id).\
first()
return info_cache
@require_context
def instance_info_cache_update(context, instance_id, values,
session=None):
"""Update an instance info cache record in the table.
:param instance_id: = id of info cache's instance
:param values: = dict containing column values to update
:param session: = optional session object
"""
session = session or get_session()
info_cache = instance_info_cache_get(context, instance_id,
session=session)
values['updated_at'] = literal_column('updated_at')
if info_cache:
info_cache.update(values)
info_cache.save(session=session)
return info_cache
@require_context
def instance_info_cache_delete_by_instance_id(context, instance_id,
session=None):
"""Deletes an existing instance_info_cache record
:param instance_id: = id of the instance tied to the cache record
:param session: = optional session object
"""
values = {'deleted': True,
'deleted_at': utils.utcnow()}
instance_info_cache_update(context, instance_id, values, session)
###################
@require_context
def key_pair_create(context, values):
key_pair_ref = models.KeyPair()