def get_all_ips(instance):
    """ Returns the public and private ip addresses of an GCP Compute instance
    """
    ip_list = []

    # TODO: Sometimes Compute instances lose the Public IP, so this is a
    # temporal workaround
    try:
        ip_list.append(instance["networkInterfaces"][0]
                       ["accessConfigs"][0]["natIP"])  # Public
    except Exception:
        pass

    ip_list.append(instance["networkInterfaces"][0]["networkIP"])  # Private
    return ip_list
 Returns the public and private ip addresses of an GCP Compute instance
    
powerfulseal/clouddrivers/gcp_driver.py