Browse Source

Store the context in the resources

It's a pain to have to look it up in the stack every time

Change-Id: I655260aafd17bc17b5895f5b53d79b20aa8eecbb
Signed-off-by: Zane Bitter <zbitter@redhat.com>
changes/27/9327/1
Zane Bitter 10 years ago
parent
commit
9c7c0dea62
  1. 4
      heat/engine/cloud_watch.py
  2. 16
      heat/engine/resources.py
  3. 4
      heat/engine/stack.py
  4. 6
      heat/engine/user.py
  5. 5
      heat/engine/wait_condition.py

4
heat/engine/cloud_watch.py

@ -68,12 +68,12 @@ class CloudWatchAlarm(Resource):
'stack_name': self.stack.name
}
wr = db_api.watch_rule_create(self.stack.context, wr_values)
wr = db_api.watch_rule_create(self.context, wr_values)
self.instance_id = wr.id
def handle_delete(self):
try:
db_api.watch_rule_delete(self.stack.context, self.name)
db_api.watch_rule_delete(self.context, self.name)
except exception.NotFound:
pass

16
heat/engine/resources.py

@ -65,6 +65,7 @@ class Resource(object):
def __init__(self, name, json_snippet, stack):
self.references = []
self.stack = stack
self.context = stack.context
self.name = name
self.t = stack.resolve_static_data(json_snippet)
self.properties = checkeddict.Properties(name, self.properties_schema)
@ -77,7 +78,7 @@ class Resource(object):
# place for it.
self.t['Metadata'] = {}
resource = db_api.resource_get_by_name_and_stack(self.stack.context,
resource = db_api.resource_get_by_name_and_stack(self.context,
name, stack.id)
if resource:
self.instance_id = resource.nova_instance
@ -117,7 +118,7 @@ class Resource(object):
if self._keystone:
return self._keystone
con = self.stack.context
con = self.context
self._keystone = kc.Client(username=con.username,
password=con.password,
tenant_name=con.tenant,
@ -128,8 +129,7 @@ class Resource(object):
if service_type in self._nova:
return self._nova[service_type]
con = self.stack.context
self._nova[service_type] = auth.authenticate(con,
self._nova[service_type] = auth.authenticate(self.context,
service_type=service_type,
service_name=None)
return self._nova[service_type]
@ -203,7 +203,7 @@ class Resource(object):
return result
try:
db_api.resource_get(self.stack.context, self.id).delete()
db_api.resource_get(self.context, self.id).delete()
except exception.NotFound:
# Don't fail on delete if the db entry has
# not been created yet.
@ -225,7 +225,7 @@ class Resource(object):
'rsrc_metadata': metadata,
'stack_name': self.stack.name}
new_rs = db_api.resource_create(self.stack.context, rs)
new_rs = db_api.resource_create(self.context, rs)
self.id = new_rs.id
if new_rs.stack:
@ -247,7 +247,7 @@ class Resource(object):
'resource_type': self.t['Type'],
'resource_properties': dict(self.properties)}
try:
db_api.event_create(self.stack.context, ev)
db_api.event_create(self.context, ev)
except Exception as ex:
logger.error('DB error %s' % str(ex))
@ -256,7 +256,7 @@ class Resource(object):
if self.id is not None:
try:
rs = db_api.resource_get(self.stack.context, self.id)
rs = db_api.resource_get(self.context, self.id)
rs.update_and_save({'state': self.state,
'state_description': reason,
'nova_instance': self.instance_id})

4
heat/engine/stack.py

@ -46,7 +46,7 @@ class Stack(Resource):
def nested(self):
if self._nested is None and self.instance_id is not None:
self._nested = parser.Stack.load(self.stack.context,
self._nested = parser.Stack.load(self.context,
self.instance_id)
if self._nested is None:
@ -61,7 +61,7 @@ class Stack(Resource):
template = parser.Template(child_template)
params = parser.Parameters(self.name, template, self._params())
self._nested = parser.Stack(self.stack.context,
self._nested = parser.Stack(self.context,
self.name,
template,
params)

6
heat/engine/user.py

@ -49,7 +49,7 @@ class User(Resource):
'Password' in self.properties['LoginProfile']:
passwd = self.properties['LoginProfile']['Password']
tenant_id = self.stack.context.tenant_id
tenant_id = self.context.tenant_id
user = self.keystone().users.create(self.name, passwd,
'%s@heat-api.org' % self.name,
tenant_id=tenant_id,
@ -119,7 +119,7 @@ class AccessKey(Resource):
self._secret = None
def _user_from_name(self, username):
tenant_id = self.stack.context.tenant_id
tenant_id = self.context.tenant_id
users = self.keystone().users.list(tenant_id=tenant_id)
for u in users:
if u.name == self.properties['UserName']:
@ -132,7 +132,7 @@ class AccessKey(Resource):
raise exception.NotFound('could not find user %s' %
self.properties['UserName'])
tenant_id = self.stack.context.tenant_id
tenant_id = self.context.tenant_id
cred = self.keystone().ec2.create(user.id, tenant_id)
self.instance_id_set(cred.access)
self._secret = cred.secret

5
heat/engine/wait_condition.py

@ -70,7 +70,6 @@ class WaitCondition(resources.Resource):
def handle_create(self):
self._get_handle_resource_id()
res_name = self.resource_id
cntx = self.stack.context
# keep polling our Metadata to see if the cfn-signal has written
# it yet. The execution here is limited by timeout.
@ -82,7 +81,7 @@ class WaitCondition(resources.Resource):
try:
while status == 'WAITING':
try:
res = db_api.resource_get_by_name_and_stack(cntx,
res = db_api.resource_get_by_name_and_stack(self.context,
res_name,
self.stack.id)
except Exception as ex:
@ -125,7 +124,7 @@ class WaitCondition(resources.Resource):
res = None
if key == 'Data':
try:
r = db_api.resource_get(self.stack.context, self.id)
r = db_api.resource_get(self.context, self.id)
if r.rsrc_metadata and 'Data' in r.rsrc_metadata:
res = r.rsrc_metadata['Data']
except Exception as ex:

Loading…
Cancel
Save