From: Angus Salkeld Date: Wed, 18 Apr 2012 05:08:47 +0000 (+1000) Subject: To properly populate the output section. X-Git-Tag: 2014.1~1965 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=24ad425a7af57017e3167cebaaa0fe19173a3d14;p=openstack-build%2Fheat-build.git 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 --- diff --git a/heat/engine/parser.py b/heat/engine/parser.py index f3e3a5f3..55457a83 100644 --- a/heat/engine/parser.py +++ b/heat/engine/parser.py @@ -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) diff --git a/heat/engine/resources.py b/heat/engine/resources.py index 66b13fef..cee5a5ca 100644 --- a/heat/engine/resources.py +++ b/heat/engine/resources.py @@ -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: