]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
To properly populate the output section.
authorAngus Salkeld <asalkeld@redhat.com>
Wed, 18 Apr 2012 05:08:47 +0000 (15:08 +1000)
committerAngus Salkeld <asalkeld@redhat.com>
Wed, 18 Apr 2012 05:08:47 +0000 (15:08 +1000)
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>
heat/engine/parser.py
heat/engine/resources.py

index f3e3a5f3a7410865b38f428cacde314966f09742..55457a837baccb26875af474284eaf26dd877bc3 100644 (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)
 
index 66b13fefb64fa17755438a0bdce120ee7072399e..cee5a5ca4aa513a8b129da504a11866d3059b5ea 100644 (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: