def conn_gcp(cred, crid):
    """Establish connection to GCP."""
    gcp_auth_type = cred.get('gcp_auth_type', "S")
    if gcp_auth_type == "A":  # Application Auth
        gcp_crd_ia = CONFIG_DIR + ".gcp_libcloud_a_auth." + cred['gcp_proj_id']
        gcp_crd = {'user_id': cred['gcp_client_id'],
                   'key': cred['gcp_client_sec'],
                   'project': cred['gcp_proj_id'],
                   'auth_type': "IA",
                   'credential_file': gcp_crd_ia}
    else:  # Service Account Auth
        gcp_pem = CONFIG_DIR + cred['gcp_pem_file']
        gcp_crd_sa = CONFIG_DIR + ".gcp_libcloud_s_auth." + cred['gcp_proj_id']
        gcp_crd = {'user_id': cred['gcp_svc_acct_email'],
                   'key': gcp_pem,
                   'project': cred['gcp_proj_id'],
                   'credential_file': gcp_crd_sa}
    driver = get_driver(Provider.GCE)
    try:
        gcp_obj = driver(**gcp_crd)
    except SSLError as e:
        abort_err("\r SSL Error with GCP: {}".format(e))
    except (InvalidCredsError, ValueError) as e:
        abort_err("\r Error with GCP Credentials: {}".format(e))
    return {crid: gcp_obj}
def conn_gcp ( cred , crid ) : gcp_auth_type = cred . get ( 'gcp_auth_type' , "S" ) if gcp_auth_type == "A" : gcp_crd_ia = CONFIG_DIR + ".gcp_libcloud_a_auth." + cred [ 'gcp_proj_id' ] gcp_crd = { 'user_id' : cred [ 'gcp_client_id' ] , 'key' : cred [ 'gcp_client_sec' ] , 'project' : cred [ 'gcp_proj_id' ] , 'auth_type' : "IA" , 'credential_file' : gcp_crd_ia } else : gcp_pem = CONFIG_DIR + cred [ 'gcp_pem_file' ] gcp_crd_sa = CONFIG_DIR + ".gcp_libcloud_s_auth." + cred [ 'gcp_proj_id' ] gcp_crd = { 'user_id' : cred [ 'gcp_svc_acct_email' ] , 'key' : gcp_pem , 'project' : cred [ 'gcp_proj_id' ] , 'credential_file' : gcp_crd_sa } driver = get_driver ( Provider . GCE ) try : gcp_obj = driver ( ** gcp_crd ) except SSLError as e : abort_err ( "\r SSL Error with GCP: {}" . format ( e ) ) except ( InvalidCredsError , ValueError ) as e : abort_err ( "\r Error with GCP Credentials: {}" . format ( e ) ) return { crid : gcp_obj }
Establish connection to GCP.