From bfd7fcf8f5642e99df9ada33a5c39e5c1a0f89c5 Mon Sep 17 00:00:00 2001 From: Zane Bitter Date: Fri, 13 Jul 2012 16:46:20 -0400 Subject: [PATCH] Eliminate DB access from the engine API Access all data through the Stack and Resource objects. Fixes #168 Change-Id: I0331a0ad67bcd11bb678e026ddc7b7c954517bc4 Signed-off-by: Zane Bitter --- heat/engine/api.py | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/heat/engine/api.py b/heat/engine/api.py index e3bfb072..fc81eb86 100644 --- a/heat/engine/api.py +++ b/heat/engine/api.py @@ -15,7 +15,6 @@ import re import logging from heat.common import utils as heat_utils -from heat.db import api as db_api from heat.engine import parser @@ -150,23 +149,22 @@ def format_stack(stack, keys=None): Return a representation of the given stack that matches the API output expectations. ''' - s = db_api.stack_get(stack.context, stack.id) info = { STACK_NAME: stack.name, STACK_ID: stack.id, - STACK_CREATION_TIME: heat_utils.strtime(s.created_at), - STACK_UPDATED_TIME: heat_utils.strtime(s.updated_at), + STACK_CREATION_TIME: heat_utils.strtime(stack.created_time), + STACK_UPDATED_TIME: heat_utils.strtime(stack.updated_time), STACK_NOTIFICATION_TOPICS: [], # TODO Not implemented yet STACK_PARAMETERS: stack.t[parser.PARAMETERS], STACK_DESCRIPTION: stack.t[parser.DESCRIPTION], STACK_TMPL_DESCRIPTION: stack.t[parser.DESCRIPTION], - STACK_STATUS: s.status, - STACK_STATUS_DATA: s.status_reason, + STACK_STATUS: stack.state, + STACK_STATUS_DATA: stack.state_description, STACK_TIMEOUT: stack.timeout_mins, } # only show the outputs on a completely created stack - if s.status == stack.CREATE_COMPLETE: + if stack.state == stack.CREATE_COMPLETE: info[STACK_OUTPUTS] = format_stack_outputs(stack, stack.outputs) return _filter_keys(info, keys) @@ -211,16 +209,15 @@ def format_stack_resource(resource, keys=None): Return a representation of the given resource that matches the API output expectations. ''' - rs = db_api.resource_get(resource.context, resource.id) - last_updated_time = rs.updated_at or rs.created_at + last_updated_time = resource.updated_time or resource.created_time attrs = { RES_DESCRIPTION: resource.parsed_template().get('Description', ''), RES_UPDATED_TIME: heat_utils.strtime(last_updated_time), RES_NAME: resource.name, RES_PHYSICAL_ID: resource.instance_id or '', - RES_METADATA: rs.rsrc_metadata, - RES_STATUS: rs.state, - RES_STATUS_DATA: rs.state_description, + RES_METADATA: resource.metadata, + RES_STATUS: resource.state, + RES_STATUS_DATA: resource.state_description, RES_TYPE: resource.t['Type'], RES_STACK_ID: resource.stack.id, RES_STACK_NAME: resource.stack.name, -- 2.45.2