import time


def region_wait(client, project, region, operation):
    """ input: gce connection and operation
        output: request result - json
        sleep/waits for region operation to complete
    """
    while True:
        result = client.regionOperations().get(project=project, region=region, operation=operation).execute()
        if result['status'] == 'DONE':
            print("done")
            if 'error' in result:
                raise Exception(result['error'])
            return result
        else:
            print("waiting for " + operation)
        time.sleep(1)