'Wait for status to change from present status to awaited_status'

def _wait_for_status(self, awaited_status):

    status_map = {'creating': 'available', 'rebooting': 'available', 'modifying': 'available', 'deleting': 'gone'}
    if (self.status == awaited_status):
        return
    if (status_map[self.status] != awaited_status):
        msg = "Invalid    awaited    status.    '%s'    cannot    transition    to    '%s'"
        self.module.fail_json(msg=(msg % (self.status, awaited_status)))
    if (awaited_status not in set(status_map.values())):
        msg = "'%s'    is    not    a    valid    awaited    status."
        self.module.fail_json(msg=(msg % awaited_status))
    while True:
        time.sleep(1)
        self._refresh_data()
        if (self.status == awaited_status):
            break
