

def wait_for_status_change(self, parameters, conn, state_requested, max_wait_time=60, poll_interval=10):
    ' After we have sent a signal to the cloud infrastructure to change the state\n      of the instances (unsually from runnning to either stoppped or \n      terminated), wait for the status to change.  If all the instances change\n      successfully, return True, if not return False.\n\n    Args:\n      parameters: A dictionary of parameters.\n      conn: A connection object returned from self.open_connection().\n      state_requrested: String of the requested final state of the instances.\n      max_wait_time: int of maximum amount of time (in seconds)  to wait for the\n        state change.\n      poll_interval: int of the number of seconds to wait between checking of\n        the state.\n    '
    time_start = time.time()
    instance_ids = parameters[self.PARAM_INSTANCE_IDS]
    instances_in_state = {
        
    }
    while True:
        time.sleep(poll_interval)
        reservations = conn.get_all_instances(instance_ids)
        instances = [i for r in reservations for i in r.instances]
        for i in instances:
            if ((i.state == state_requested) and (i.key_name == parameters[self.PARAM_KEYNAME])):
                if (i.id not in instances_in_state.keys()):
                    instances_in_state[i.id] = 1
        if (len(instances_in_state.keys()) >= len(instance_ids)):
            return True
        if ((time.time() - time_start) > max_wait_time):
            return False

dataset/ETHPy150Open AppScale/appscale-tools/lib/agents/ec2_agent.py EC2Agent.wait_for_status_change/original