incorporate feedback from devin - use sql consistently in instance_destroy

also, set deleted_at
This commit is contained in:
Anthony Young 2011-01-28 15:31:23 -08:00
parent 3478f84360
commit 5becf2ad3d

View File

@ -19,6 +19,7 @@
Implementation of SQLAlchemy backend.
"""
import datetime
import warnings
from nova import db
@ -670,11 +671,14 @@ def instance_data_get_for_project(context, project_id):
def instance_destroy(context, instance_id):
session = get_session()
with session.begin():
instance_ref = instance_get(context, instance_id, session=session)
instance_ref.delete(session=session)
session.execute('update security_group_instance_association'
' set deleted=1 where instance_id=:id',
{'id': instance_id})
session.execute('update instances set deleted=1,'
'deleted_at=:at where id=:id',
{'id': instance_id,
'at': datetime.datetime.utcnow()})
session.execute('update security_group_instance_association '
'set deleted=1,deleted_at=:at where instance_id=:id',
{'id': instance_id,
'at': datetime.datetime.utcnow()})
@require_context
@ -1586,9 +1590,11 @@ def security_group_destroy(context, security_group_id):
# TODO(vish): do we have to use sql here?
session.execute('update security_groups set deleted=1 where id=:id',
{'id': security_group_id})
session.execute('update security_group_instance_association'
' set deleted=1 where security_group_id=:id',
{'id': security_group_id})
session.execute('update security_group_instance_association '
'set deleted=1,deleted_at=:at '
'where security_group_id=:id',
{'id': security_group_id,
'at': datetime.datetime.utcnow()})
session.execute('update security_group_rules set deleted=1 '
'where group_id=:id',
{'id': security_group_id})