Save the parsed_template so user parameters are available.
This caused parsing errors when deleting, as required references were not available. Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
This commit is contained in:
parent
e5a0f9196f
commit
35bd5f4c5f
@ -58,7 +58,7 @@ class EngineManager(manager.Manager):
|
|||||||
if stacks == None:
|
if stacks == None:
|
||||||
return res
|
return res
|
||||||
for s in stacks:
|
for s in stacks:
|
||||||
ps = parser.Stack(s.name, s.raw_template.template, params)
|
ps = parser.Stack(s.name, s.raw_template.parsed_template.template, s.id, params)
|
||||||
mem = {}
|
mem = {}
|
||||||
mem['stack_id'] = s.id
|
mem['stack_id'] = s.id
|
||||||
mem['stack_name'] = s.name
|
mem['stack_name'] = s.name
|
||||||
@ -80,7 +80,7 @@ class EngineManager(manager.Manager):
|
|||||||
res = {'stacks': []}
|
res = {'stacks': []}
|
||||||
s = db_api.stack_get(None, stack_name)
|
s = db_api.stack_get(None, stack_name)
|
||||||
if s:
|
if s:
|
||||||
ps = parser.Stack(s.name, s.raw_template.template, params)
|
ps = parser.Stack(s.name, s.raw_template.parsed_template.template, s.id, params)
|
||||||
mem = {}
|
mem = {}
|
||||||
mem['stack_id'] = s.id
|
mem['stack_id'] = s.id
|
||||||
mem['stack_name'] = s.name
|
mem['stack_name'] = s.name
|
||||||
@ -113,17 +113,28 @@ class EngineManager(manager.Manager):
|
|||||||
if db_api.stack_get(None, stack_name):
|
if db_api.stack_get(None, stack_name):
|
||||||
return {'Error': 'Stack already exists with that name.'}
|
return {'Error': 'Stack already exists with that name.'}
|
||||||
|
|
||||||
stack = parser.Stack(stack_name, template, params)
|
stack = parser.Stack(stack_name, template, 0, params)
|
||||||
rt = {}
|
rt = {}
|
||||||
rt['template'] = template
|
rt['template'] = template
|
||||||
rt['stack_name'] = stack_name
|
rt['stack_name'] = stack_name
|
||||||
new_rt = db_api.raw_template_create(None, rt)
|
new_rt = db_api.raw_template_create(None, rt)
|
||||||
|
|
||||||
s = {}
|
s = {}
|
||||||
s['name'] = stack_name
|
s['name'] = stack_name
|
||||||
s['raw_template_id'] = new_rt.id
|
s['raw_template_id'] = new_rt.id
|
||||||
new_s = db_api.stack_create(None, s)
|
new_s = db_api.stack_create(None, s)
|
||||||
stack.id = new_s.id
|
stack.id = new_s.id
|
||||||
|
|
||||||
|
pt = {}
|
||||||
|
pt['template'] = stack.t
|
||||||
|
pt['raw_template_id'] = new_rt.id
|
||||||
|
new_pt = db_api.parsed_template_create(None, pt)
|
||||||
|
|
||||||
|
new_s.parsed_template_id = new_pt.id
|
||||||
|
|
||||||
|
stack.parsed_template_id = new_pt.id
|
||||||
stack.create()
|
stack.create()
|
||||||
|
|
||||||
return {'stack': {'id': new_s.id, 'name': new_s.name,\
|
return {'stack': {'id': new_s.id, 'name': new_s.name,\
|
||||||
'created_at': str(new_s.created_at)}}
|
'created_at': str(new_s.created_at)}}
|
||||||
|
|
||||||
@ -141,7 +152,7 @@ class EngineManager(manager.Manager):
|
|||||||
msg = _("No Template provided.")
|
msg = _("No Template provided.")
|
||||||
return webob.exc.HTTPBadRequest(explanation=msg)
|
return webob.exc.HTTPBadRequest(explanation=msg)
|
||||||
|
|
||||||
s = parser.Stack('validate', body, req.params)
|
s = parser.Stack('validate', body, 0, req.params)
|
||||||
res = s.validate()
|
res = s.validate()
|
||||||
|
|
||||||
return res
|
return res
|
||||||
@ -159,8 +170,7 @@ class EngineManager(manager.Manager):
|
|||||||
|
|
||||||
logger.info('deleting stack %s' % stack_name)
|
logger.info('deleting stack %s' % stack_name)
|
||||||
|
|
||||||
rt = db_api.raw_template_get(None, st.raw_template_id)
|
ps = parser.Stack(st.name, st.raw_template.parsed_template.template, st.id, params)
|
||||||
ps = parser.Stack(st.name, rt.template, params)
|
|
||||||
ps.delete()
|
ps.delete()
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -25,8 +25,8 @@ logger = logging.getLogger('heat.engine.parser')
|
|||||||
|
|
||||||
|
|
||||||
class Stack(object):
|
class Stack(object):
|
||||||
def __init__(self, stack_name, template, parms=None):
|
def __init__(self, stack_name, template, stack_id=0, parms=None):
|
||||||
self.id = 0
|
self.id = stack_id
|
||||||
self.t = template
|
self.t = template
|
||||||
self.parms = self.t.get('Parameters', {})
|
self.parms = self.t.get('Parameters', {})
|
||||||
self.maps = self.t.get('Mappings', {})
|
self.maps = self.t.get('Mappings', {})
|
||||||
@ -50,10 +50,6 @@ class Stack(object):
|
|||||||
else:
|
else:
|
||||||
self.creds = parms['KeyStoneCreds']
|
self.creds = parms['KeyStoneCreds']
|
||||||
|
|
||||||
stack = db_api.stack_get(None, stack_name)
|
|
||||||
if stack:
|
|
||||||
self.id = stack.id
|
|
||||||
|
|
||||||
self.resources = {}
|
self.resources = {}
|
||||||
for r in self.t['Resources']:
|
for r in self.t['Resources']:
|
||||||
type = self.t['Resources'][r]['Type']
|
type = self.t['Resources'][r]['Type']
|
||||||
@ -130,6 +126,25 @@ class Stack(object):
|
|||||||
|
|
||||||
return order
|
return order
|
||||||
|
|
||||||
|
def update_parsed_template(self):
|
||||||
|
'''
|
||||||
|
Update the parsed template after each resource has been
|
||||||
|
created, so commands like describe will work.
|
||||||
|
'''
|
||||||
|
if self.parsed_template_id == 0:
|
||||||
|
stack = db_api.stack_get(None, self.name)
|
||||||
|
if stack:
|
||||||
|
self.parsed_template_id = stack.parsed_template_id
|
||||||
|
else:
|
||||||
|
return
|
||||||
|
|
||||||
|
pt = db_api.parsed_template_get(None, self.parsed_template_id)
|
||||||
|
if pt:
|
||||||
|
pt.template = self.t
|
||||||
|
else:
|
||||||
|
print 'cant find parsed template to update %d' % self.parsed_template_id
|
||||||
|
|
||||||
|
|
||||||
def create_blocking(self):
|
def create_blocking(self):
|
||||||
'''
|
'''
|
||||||
create all the resources in the order specified by get_create_order
|
create all the resources in the order specified by get_create_order
|
||||||
@ -145,6 +160,12 @@ class Stack(object):
|
|||||||
logger.exception('create')
|
logger.exception('create')
|
||||||
failed = True
|
failed = True
|
||||||
self.resources[r].state_set(failed_str, str(ex))
|
self.resources[r].state_set(failed_str, str(ex))
|
||||||
|
|
||||||
|
try:
|
||||||
|
self.update_parsed_template()
|
||||||
|
except Exception as ex:
|
||||||
|
logger.exception('update_parsed_template')
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self.resources[r].state_set(self.resources[r].CREATE_FAILED)
|
self.resources[r].state_set(self.resources[r].CREATE_FAILED)
|
||||||
|
|
||||||
|
@ -122,6 +122,7 @@ class Resource(object):
|
|||||||
rs = {}
|
rs = {}
|
||||||
rs['state'] = new_state
|
rs['state'] = new_state
|
||||||
rs['stack_id'] = self.stack.id
|
rs['stack_id'] = self.stack.id
|
||||||
|
rs['parsed_template_id'] = self.stack.parsed_template_id
|
||||||
rs['nova_instance'] = self.instance_id
|
rs['nova_instance'] = self.instance_id
|
||||||
rs['name'] = self.name
|
rs['name'] = self.name
|
||||||
rs['stack_name'] = self.stack.name
|
rs['stack_name'] = self.stack.name
|
||||||
|
Loading…
Reference in New Issue
Block a user