def wait_for_stack_status(cf_conn, stack_name, stack_status): sys.stdout.write("Waiting for stack to enter '{s}' state.".format(s=stack_status)) sys.stdout.flush() start_time = datetime.now() while True: sleep_progressive(start_time) stack = cf_conn.describe_stacks(stack_name)[0] if stack.stack_status == stack_status: break sys.stdout.write(".") sys.stdout.flush() sys.stdout.write("\n") end_time = datetime.now() print "Stack is now in '{s}' state. Waited {t} seconds.".format(s=stack_status, t=(end_time - start_time).seconds)
def wait_for_instance_state(ec2_conn, instance, state="running"): sys.stdout.write("Waiting for instance to enter '{s}' state.".format(s=state)) sys.stdout.flush() start_time = datetime.now() while True: sleep_progressive(start_time) instance.update() statuses = ec2_conn.get_all_instance_status(instance.id, include_all_instances=True) if len(statuses) > 0: status = statuses[0] if ( instance.state == state and status.system_status.status in ["ok", "not-applicable"] and status.instance_status.status in ["ok", "not-applicable"] ): break sys.stdout.write(".") sys.stdout.flush() sys.stdout.write("\n") end_time = datetime.now() print "Instance is now in '{s}' state. Waited {t} seconds.".format(s=state, t=(end_time - start_time).seconds)