To properly populate the output section.

We need to get ipaddresses which are lost as they are
not stored in the template so we need to retrieve them
at runtime.

Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
This commit is contained in:
Angus Salkeld 2012-04-18 15:08:47 +10:00
parent 89e86fa918
commit 24ad425a7a
2 changed files with 39 additions and 3 deletions

View File

@ -195,8 +195,10 @@ class Stack(object):
pool.spawn_n(self.delete_blocking)
def get_outputs(self):
self.resolve_static_refs(self.outputs)
self.resolve_find_in_map(self.outputs)
for r in self.resources:
self.resources[r].reload()
self.resolve_attributes(self.outputs)
self.resolve_joins(self.outputs)

View File

@ -29,6 +29,7 @@ from email.mime.text import MIMEText
from novaclient.v1_1 import client
from novaclient.exceptions import BadRequest
from novaclient.exceptions import NotFound
from heat.common import exception
from heat.db import api as db_api
@ -156,7 +157,16 @@ class Resource(object):
str(self.id))
def reload(self):
pass
'''
The point of this function is to get the Resource instance back
into the state that it was just after it was created. So we
need to retrieve things like ipaddresses and other variables
used by FnGetAtt and FnGetRefId. classes inheriting from Resource
might need to override this, but still call it.
This is currently used by stack.get_outputs()
'''
print 'reloading %s name:%s' % (self.t['Type'], self.name)
self.stack.resolve_attributes(self.t)
def FnGetRefId(self):
'''
@ -291,6 +301,16 @@ class ElasticIp(Resource):
self.instance_id_set(ips.id)
self.state_set(self.CREATE_COMPLETE)
def reload(self):
'''
get the ipaddress here
'''
if self.instance_id != None:
ips = self.nova().floating_ips.get(self.instance_id)
self.ipaddress = ips.ip
Resource.reload(self)
def delete(self):
"""De-allocate a floating IP."""
if self.state == self.DELETE_IN_PROGRESS or \
@ -595,6 +615,20 @@ class Instance(Resource):
else:
self.state_set(self.CREATE_FAILED)
def reload(self):
'''
re-read the server's ipaddress so FnGetAtt works.
'''
print 'reloading Instance %s' % self.instance_id
try:
server = self.nova().servers.get(self.instance_id)
for n in server.networks:
self.ipaddress = server.networks[n][0]
except NotFound:
self.ipaddress = '0.0.0.0'
Resource.reload(self)
def delete(self):
if self.state == self.DELETE_IN_PROGRESS or \
self.state == self.DELETE_COMPLETE: