Skip to content

Commit

Permalink
Add support for the Output section.
Browse files Browse the repository at this point in the history
Implements issue #51

To see the outputs run "heat describe <stack name>"

Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
  • Loading branch information
asalkeld committed Apr 3, 2012
1 parent 59b89df commit 20cdc46
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 10 deletions.
12 changes: 6 additions & 6 deletions heat/engine/api/v1/stacks.py
Expand Up @@ -53,8 +53,8 @@ def index(self, req, format='json'):
mem['stack_name'] = s
mem['created_at'] = 'now'
try:
mem['template_description'] = stack_db[s]['Description']
mem['stack_status'] = stack_db[s]['StackStatus']
mem['template_description'] = stack_db[s].t['Description']
mem['stack_status'] = stack_db[s].t['StackStatus']
except:
mem['template_description'] = 'No description'
mem['stack_status'] = 'unknown'
Expand All @@ -71,13 +71,13 @@ def show(self, req, id):
mem['creation_at'] = 'TODO'
mem['updated_at'] = 'TODO'
mem['NotificationARNs'] = 'TODO'
mem['Outputs'] = [{'Description': 'TODO', 'OutputKey': 'TODO', 'OutputValue': 'TODO' }]
mem['Parameters'] = stack_db[id]['Parameters']
mem['Outputs'] = stack_db[id].get_outputs()
mem['Parameters'] = stack_db[id].t['Parameters']
mem['StackStatusReason'] = 'TODO'
mem['TimeoutInMinutes'] = 'TODO'
try:
mem['TemplateDescription'] = stack_db[id]['Description']
mem['StackStatus'] = stack_db[id]['StackStatus']
mem['TemplateDescription'] = stack_db[id].t['Description']
mem['StackStatus'] = stack_db[id].t['StackStatus']
except:
mem['TemplateDescription'] = 'No description'
mem['StackStatus'] = 'unknown'
Expand Down
27 changes: 27 additions & 0 deletions heat/engine/parser.py
Expand Up @@ -32,6 +32,11 @@ def __init__(self, stack_name, template, parms=None):
self.maps = self.t['Mappings']
else:
self.maps = {}
if self.t.has_key('Outputs'):
self.outputs = self.t['Outputs']
else:
self.outputs = {}

self.res = {}
self.doc = None
self.name = stack_name
Expand Down Expand Up @@ -107,6 +112,28 @@ def stop(self):
for r in self.t['Resources']:
self.resources[r].stop()

def get_outputs(self):
self.resolve_static_refs(self.outputs)
self.resolve_find_in_map(self.outputs)
self.resolve_attributes(self.outputs)
self.resolve_joins(self.outputs)

outs = []
for o in self.outputs:
out = {}
if self.outputs[o].has_key('Description'):
out['Description'] = self.outputs[o]['Description']
else:
out['Description'] = 'No description given'
out['OutputKey'] = o
if self.outputs[o].has_key('Value'):
out['OutputValue'] = self.outputs[o]['Value']
else:
out['OutputValue'] = ''
outs.append(out)

return outs

def calulate_dependencies(self, s, r):
if isinstance(s, dict):
for i in s:
Expand Down
18 changes: 14 additions & 4 deletions heat/engine/resources.py
Expand Up @@ -244,6 +244,7 @@ class Instance(Resource):

def __init__(self, name, json_snippet, stack):
super(Instance, self).__init__(name, json_snippet, stack)
self.ipaddress = '0.0.0.0'

if not self.t['Properties'].has_key('AvailabilityZone'):
self.t['Properties']['AvailabilityZone'] = 'nova'
Expand All @@ -262,14 +263,18 @@ def __init__(self, name, json_snippet, stack):


def FnGetAtt(self, key):
print '%s.GetAtt(%s)' % (self.name, key)

res = 'not-this-surely'
if key == 'AvailabilityZone':
return unicode(self.t['Properties']['AvailabilityZone'])
res = self.t['Properties']['AvailabilityZone']
elif key == 'PublicIp':
res = self.ipaddress
else:
# TODO PrivateDnsName, PublicDnsName, PrivateIp, PublicIp
return unicode('not-this-surely')
logger.warn('%s.GetAtt(%s) is not handled' % (self.name, key))

# TODO(asalkeld) PrivateDnsName, PublicDnsName & PrivateIp

return unicode(res)

def start(self):
def _null_callback(p, n, out):
Expand Down Expand Up @@ -341,6 +346,11 @@ def _null_callback(p, n, out):
if server.status == 'ACTIVE':
self.state_set(self.CREATE_COMPLETE)
self.instance_id = server.id

# just record the first ipaddress
for n in server.networks:
self.ipaddress = server.networks[n][0]
break
else:
self.state_set(self.CREATE_FAILED)

Expand Down

0 comments on commit 20cdc46

Please sign in to comment.