Try and keep track of the stack status.

Ref: #93

Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
changes/40/40/1
Angus Salkeld 11 years ago
parent e67e9c80bf
commit c5ff64132a

@ -24,6 +24,7 @@ from sqlalchemy import types as types
from json import dumps, loads
from heat.openstack.common import utils
from heat.db.sqlalchemy.session import get_session
from sqlalchemy.orm.session import Session
BASE = declarative_base()
@ -48,7 +49,9 @@ class HeatBase(object):
def save(self, session=None):
"""Save this object."""
if not session:
session = get_session()
session = Session.object_session(self)
if not session:
session = get_session()
session.add(self)
try:
session.flush()

@ -66,7 +66,7 @@ class EngineManager(manager.Manager):
mem['created_at'] = str(s.created_at)
mem['template_description'] = ps.t.get('Description',
'No description')
mem['stack_status'] = ps.t.get('StackStatus', 'unknown')
mem['StackStatus'] = ps.t.get('stack_status', 'unknown')
res['stacks'].append(mem)
return res
@ -95,7 +95,7 @@ class EngineManager(manager.Manager):
mem['TimeoutInMinutes'] = 'TODO'
mem['TemplateDescription'] = ps.t.get('Description',
'No description')
mem['StackStatus'] = ps.t.get('StackStatus', 'unknown')
mem['StackStatus'] = ps.t.get('stack_status', 'unknown')
res['stacks'].append(mem)
return res
@ -132,8 +132,6 @@ class EngineManager(manager.Manager):
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()

@ -25,6 +25,13 @@ logger = logging.getLogger('heat.engine.parser')
class Stack(object):
IN_PROGRESS = 'IN_PROGRESS'
CREATE_FAILED = 'CREATE_FAILED'
CREATE_COMPLETE = 'CREATE_COMPLETE'
DELETE_IN_PROGRESS = 'DELETE_IN_PROGRESS'
DELETE_FAILED = 'DELETE_FAILED'
DELETE_COMPLETE = 'DELETE_COMPLETE'
def __init__(self, stack_name, template, stack_id=0, parms=None):
self.id = stack_id
self.t = template
@ -34,6 +41,7 @@ class Stack(object):
self.res = {}
self.doc = None
self.name = stack_name
self.parsed_template_id = 0
self.parms['AWS::Region'] = {"Description": "AWS Regions",
"Type": "String",
@ -134,23 +142,32 @@ class Stack(object):
if self.parsed_template_id == 0:
stack = db_api.stack_get(None, self.name)
if stack:
self.parsed_template_id = stack.parsed_template_id
self.parsed_template_id = stack.raw_template.parsed_template.id
else:
return
pt = db_api.parsed_template_get(None, self.parsed_template_id)
if pt:
pt.template = self.t
pt.save()
else:
logger.warn('Cant find parsed template to update %d' % \
self.parsed_template_id)
def status_set(self, new_status, reason='change in resource state'):
self.t['stack_status'] = new_status
self.update_parsed_template()
def create_blocking(self):
'''
create all the resources in the order specified by get_create_order
'''
order = self.get_create_order()
failed = False
self.status_set(self.IN_PROGRESS)
for r in order:
failed_str = self.resources[r].CREATE_FAILED
if not failed:
@ -167,7 +184,13 @@ class Stack(object):
logger.exception('update_parsed_template')
else:
self.resources[r].state_set(self.resources[r].CREATE_FAILED)
self.resources[r].state_set(failed_str)
if failed:
self.status_set(self.CREATE_FAILED)
else:
self.status_set(self.CREATE_COMPLETE)
self.update_parsed_template()
def create(self):
@ -179,6 +202,8 @@ class Stack(object):
delete all the resources in the reverse order specified by
get_create_order().
'''
self.status_set(self.DELETE_IN_PROGRESS)
order = self.get_create_order()
order.reverse()
for r in order:

Loading…
Cancel
Save