def test_module_command(client: ClusterManagerClient, project: str, zone: str):
    """ Test Google Kubernetes Engine client connection using gcloud-clusters-list command:
            1. project.
            2. zone.

    Args:
        client: Google container client.
        project: GCP project from console.
        zone: Project query zone, e.g. "europe-west2-a".

    Returns:
        str: Human readable.
        dict: Cluster entry context.
        dict: Cluster raw response.
    """
    # Query and gPRC unpack - will raise exception if not succeed
    try:
        client.list_clusters(project_id=project,
                             zone=zone,
                             timeout=API_TIMEOUT)
    except Exception:
        raise DemistoException(
            'Unsuccessfull integration test - check configuration...')

    return 'ok', {}, {}
def gcloud_clusters_list_command(client: ClusterManagerClient, project: str,
                                 zone: str) -> COMMAND_OUTPUT:
    """ Lists all clusters owned by a project in either the specified zone or all zones.
        Original command - https://cloud.google.com/sdk/gcloud/reference/container/clusters/list

    Args:
        client: Google container client.
        project: GCP project from console.
        zone: Project query zone, e.g. "europe-west2-a".

    Returns:
        str: Human readable.
        dict: Cluster entry context.
        dict: Cluster raw response.
    """
    # Query and gPRC unpack
    raw_response_msg: Message = client.list_clusters(project_id=project,
                                                     zone=zone,
                                                     timeout=API_TIMEOUT)
    raw_response_dict: dict = MessageToDict(raw_response_msg)

    # Entry context
    clusters_ec: List[dict] = [
        parse_cluster(cluster)
        for cluster in raw_response_dict.get('clusters', [])
    ]
    entry_context = {
        CLUSTER_CONTEXT: clusters_ec,
    }
    # Human readable
    human_readable: str = tableToMarkdown(
        t=[parse_cluster_table(entry) for entry in clusters_ec],
        name=f'Clusters (Project={project}, Zone={zone})')

    return human_readable, entry_context, raw_response_dict
Example #3
0
File: util.py Project: B3EF/caliban
def get_gke_clusters(client: ClusterManagerClient,
                     project_id: str,
                     zone: str = '-') -> Optional[List[GKECluster]]:
    """gets list of gcp clusters for given project, zone

  Args:
  client: cluster api client
  project_id: project id
  zone: zone, - = all zones

  Returns:
  list of clusters on success, None otherwise
  """

    return client.list_clusters(project_id=project_id, zone=zone).clusters