From f0b75758f634ce0d782a707d8ae451f428216d17 Mon Sep 17 00:00:00 2001 From: Angus Salkeld Date: Tue, 5 Jun 2012 10:36:21 +1000 Subject: [PATCH] Fix the conversion from instance to resource name Change-Id: Iaca10eb5468bd7b64b6a66f87fc6f7066053cb27 Signed-off-by: Angus Salkeld --- heat/engine/instance.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/heat/engine/instance.py b/heat/engine/instance.py index f0935b3ef0..e5da25a70b 100644 --- a/heat/engine/instance.py +++ b/heat/engine/instance.py @@ -25,7 +25,7 @@ from novaclient.exceptions import NotFound from heat.engine.resources import Resource from heat.common import exception -logger = logging.getLogger(__file__) +logger = logging.getLogger('heat.engine.instance') # If ../heat/__init__.py exists, add ../ to Python search path, so that # it will override what happens to be installed in /usr/(local/)lib/python... possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), @@ -64,9 +64,21 @@ class Restarter(Resource): self.state_set(self.DELETE_COMPLETE) def alarm(self): - logger.notice('%s Alarm, restarting resource: %s' % - (self.name, self.properties['InstanceId'])) - self.stack.restart_resource(self.properties['InstanceId']) + self.calculate_properties() + victim = None + for rname, r in self.stack.resources.items(): + if r.instance_id == self.properties['InstanceId']: + victim = r + break + + if victim is None: + logger.info('%s Alarm, can not find instance %s' % + (self.name, self.properties['InstanceId'])) + return + + logger.info('%s Alarm, restarting resource: %s' % + (self.name, victim.name)) + self.stack.restart_resource(victim.name) class Instance(Resource):