Pass the context to the db calls

Change-Id: I38937ee37926507dab8a7ff9e0d0d42a3ada707d
Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
changes/26/126/1
Angus Salkeld 10 years ago
parent 360c279c49
commit b0894d0e53
  1. 4
      heat/engine/cloud_watch.py
  2. 25
      heat/engine/manager.py
  3. 11
      heat/engine/parser.py
  4. 7
      heat/engine/resources.py
  5. 2
      heat/engine/wait_condition.py

@ -75,7 +75,7 @@ class CloudWatchAlarm(Resource):
'stack_name': self.stack.name
}
wr = db_api.watch_rule_create(None, wr_values)
wr = db_api.watch_rule_create(self.stack.context, wr_values)
self.instance_id = wr.id
self.state_set(self.CREATE_COMPLETE)
@ -87,7 +87,7 @@ class CloudWatchAlarm(Resource):
self.state_set(self.DELETE_IN_PROGRESS)
db_api.watch_rule_delete(None, self.name)
db_api.watch_rule_delete(self.stack.context, self.name)
Resource.delete(self)
self.state_set(self.DELETE_COMPLETE)

@ -227,7 +227,7 @@ class EngineManager(manager.Manager):
self._authenticate(context)
st = db_api.stack_get(None, stack_name)
st = db_api.stack_get(context, stack_name)
if not st:
return {'Error': 'No stack by that name'}
@ -264,13 +264,13 @@ class EngineManager(manager.Manager):
self._authenticate(context)
if stack_name is not None:
st = db_api.stack_get(None, stack_name)
st = db_api.stack_get(context, stack_name)
if not st:
return {'Error': 'No stack by that name'}
events = db_api.event_get_all_by_stack(None, st.id)
events = db_api.event_get_all_by_stack(context, st.id)
else:
events = db_api.event_get_all(None)
events = db_api.event_get_all(context)
return {'events': [self.parse_event(e) for e in events]}
@ -280,8 +280,9 @@ class EngineManager(manager.Manager):
stack_name = event['stack']
resource_name = event['resource']
stack = db_api.stack_get(None, stack_name)
resource = db_api.resource_get_by_name_and_stack(None, resource_name,
stack = db_api.stack_get(context, stack_name)
resource = db_api.resource_get_by_name_and_stack(context,
resource_name,
stack.id)
if not resource:
return ['Unknown resource', None]
@ -295,7 +296,7 @@ class EngineManager(manager.Manager):
'resource_properties': {},
}
try:
result = db_api.event_create(None, new_event)
result = db_api.event_create(context, new_event)
new_event['id'] = result.id
return [None, new_event]
except Exception as ex:
@ -310,14 +311,14 @@ class EngineManager(manager.Manager):
"""
Return the names of the stacks registered with Heat.
"""
stacks = db_api.stack_get_all(None)
stacks = db_api.stack_get_all(context)
return [s.name for s in stacks]
def metadata_list_resources(self, context, stack_name):
"""
Return the resource IDs of the given stack.
"""
stack = db_api.stack_get(None, stack_name)
stack = db_api.stack_get(context, stack_name)
if stack:
return [r.name for r in stack.resources]
else:
@ -328,7 +329,7 @@ class EngineManager(manager.Manager):
Get the metadata for the given resource.
"""
s = db_api.stack_get(None, stack_name)
s = db_api.stack_get(context, stack_name)
if not s:
return ['stack', None]
@ -343,12 +344,12 @@ class EngineManager(manager.Manager):
"""
Update the metadata for the given resource.
"""
s = db_api.stack_get(None, stack_name)
s = db_api.stack_get(context, stack_name)
if not s:
return ['stack', None]
pt_id = s.raw_template.parsed_template.id
pt = db_api.parsed_template_get(None, pt_id)
pt = db_api.parsed_template_get(context, pt_id)
if not resource_id in pt.template.get('Resources', {}):
return ['resource', None]

@ -155,13 +155,13 @@ class Stack(object):
created, so commands like describe will work.
'''
if self.parsed_template_id == 0:
stack = db_api.stack_get(None, self.name)
stack = db_api.stack_get(self.context, self.name)
if stack:
self.parsed_template_id = stack.raw_template.parsed_template.id
else:
return
pt = db_api.parsed_template_get(None, self.parsed_template_id)
pt = db_api.parsed_template_get(self.context, self.parsed_template_id)
if pt:
pt.update_and_save({'template': self.t.copy()})
else:
@ -219,7 +219,8 @@ class Stack(object):
res = self.resources[r]
try:
res.delete()
db_api.resource_get(None, self.resources[r].id).delete()
re = db_api.resource_get(self.context, self.resources[r].id)
re.delete()
except Exception as ex:
failed = True
res.state_set(res.DELETE_FAILED)
@ -227,7 +228,7 @@ class Stack(object):
self.status_set(failed and self.DELETE_FAILED or self.DELETE_COMPLETE)
if not failed:
db_api.stack_delete(None, self.name)
db_api.stack_delete(self.context, self.name)
def delete(self):
pool = eventlet.GreenPool()
@ -256,7 +257,7 @@ class Stack(object):
res = self.resources[r]
try:
res.delete()
#db_api.resource_get(None, self.resources[r].id).delete()
#db_api.resource_get(context, self.resources[r].id).delete()
except Exception as ex:
failed = True
res.state_set(res.DELETE_FAILED)

@ -64,7 +64,8 @@ class Resource(object):
# place for it.
self.t['Properties'] = {}
resource = db_api.resource_get_by_name_and_stack(None, name, stack.id)
resource = db_api.resource_get_by_name_and_stack(self.stack.context,
name, stack.id)
if resource:
self.instance_id = resource.nova_instance
self.state = resource.state
@ -129,7 +130,7 @@ class Resource(object):
rs['nova_instance'] = self.instance_id
rs['name'] = self.name
rs['stack_name'] = self.stack.name
new_rs = db_api.resource_create(None, rs)
new_rs = db_api.resource_create(self.stack.context, rs)
self.id = new_rs.id
if new_rs.stack:
new_rs.stack.update_and_save({'updated_at':
@ -159,7 +160,7 @@ class Resource(object):
self.calculate_properties()
ev['resource_properties'] = dict(self.properties)
try:
db_api.event_create(None, ev)
db_api.event_create(self.stack.context, ev)
except Exception as ex:
logger.warn('db error %s' % str(ex))
self.state = new_state

@ -108,7 +108,7 @@ class WaitCondition(Resource):
pt = None
if self.stack.parsed_template_id:
try:
pt = db_api.parsed_template_get(None,
pt = db_api.parsed_template_get(self.stack.context,
self.stack.parsed_template_id)
except Exception as ex:
if 'not found' in ex:

Loading…
Cancel
Save