From 3dc29580ae17ea56eecffabea55f7f0b2b50a342 Mon Sep 17 00:00:00 2001 From: Haiwei Xu Date: Thu, 4 Jun 2015 15:04:00 +0900 Subject: [PATCH] Implement the do_check method to check stack's status Check the stack's status to see whether it is ready to do auto-scaling. Change-Id: I69cb7d40f56a85f3191fb4b8333679fb5b3f5dcb --- senlin/drivers/openstack/heat_v1.py | 1 + senlin/profiles/os/heat/stack.py | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/senlin/drivers/openstack/heat_v1.py b/senlin/drivers/openstack/heat_v1.py index 6c13b7ef1..5f5e9c5ea 100644 --- a/senlin/drivers/openstack/heat_v1.py +++ b/senlin/drivers/openstack/heat_v1.py @@ -19,6 +19,7 @@ class HeatClient(base.DriverBase): def __init__(self, context): self.conn = sdk.create_connection(context) + self.session = self.conn.session def stack_create(self, **params): try: diff --git a/senlin/profiles/os/heat/stack.py b/senlin/profiles/os/heat/stack.py index 38c0f248e..d6b4d4aa6 100644 --- a/senlin/profiles/os/heat/stack.py +++ b/senlin/profiles/os/heat/stack.py @@ -197,8 +197,26 @@ class StackProfile(base.Profile): return True def do_check(self, obj): - # TODO(anyone): Use heat client to query stack status - return True + """Check stack status.""" + hc = self.heat(obj) + try: + stack = hc.stack_get(obj.physical_id) + except Exception as ex: + raise ex + # When the stack is in a status which can't be checked( + # CREATE_IN_PROGRESS, DELETE_IN_PROGRESS, etc), return False. + try: + stack.check(hc.session) + except Exception: + return False + + status = stack.status + while status == 'CHECK_IN_PROGRESS': + status = hc.stack_get(obj.physical_id).status + if status == 'CHECK_COMPLETE': + return True + else: + return False def get_template(self): return {}