def execute()

in gcpdiag/runbook/gke/gke_ip_masq_standard.py [0:0]


  def execute(self):
    """Lets check the provided parameters."""
    #     # skip if logging is disabled
    project = op.get(flags.PROJECT_ID)
    project_path = crm.get_project(project)

    # check if there are clusters in the project
    clusters = gke.get_clusters(
        op.get_new_context(project_id=op.get(flags.PROJECT_ID)))

    # following checks are necessary, depending on what input is provided:
    # - no input, get all clusters available
    # - just cluster name is provided, check if there's a cluster with that name
    # - just location is provided, check if there are clusters at that location
    # - cluster name and location are provided, check if there's that cluster at that location
    cluster_name = op.get(flags.NAME)
    cluster_location = op.get(flags.LOCATION)
    found_cluster = False
    found_cluster_with_location = False
    found_clusters_at_location = False
    if cluster_name and cluster_location:
      for cluster in clusters.values():
        if cluster_name == str(cluster).rsplit('/', maxsplit=1)[-1] \
          and cluster_location == str(cluster).split('/')[-3]:
          found_cluster_with_location = True
          op.add_ok(
              project_path,
              reason=(
                  'Cluster with the name {} on {} exist in project {}').format(
                      cluster_name, cluster_location, project))
          break
    elif cluster_name:
      for cluster in clusters.values():
        if cluster_name == str(cluster).rsplit('/', maxsplit=1)[-1]:
          found_cluster = True
          op.add_ok(project_path,
                    reason=('Cluster with name {} exist in project {}').format(
                        cluster_name, project))
          break
    elif cluster_location:
      for cluster in clusters.values():
        if cluster_location == str(cluster).split('/')[-3]:
          found_clusters_at_location = True
          op.add_uncertain(
              project_path,
              reason=
              ('There are clusters found on {} location. Please add cluster name to limit search'
              ).format(cluster_location))
          break
    if not found_cluster_with_location and cluster_location and cluster_name:
      op.add_skipped(
          project_path,
          reason=('Cluster with the name {} in {} does not exist in project {}'
                 ).format(cluster_name, cluster_location, project))
    # next check includes found_cluster_with_location because we found a cluster at a particular
    # location thus we cannot skip these checks
    elif not found_cluster and not found_cluster_with_location and cluster_name:
      op.add_skipped(
          project_path,
          reason=(
              'Cluster with the name {} does not exist in project {}').format(
                  cluster_name, project))
    elif not found_clusters_at_location and not found_cluster_with_location and cluster_location:
      op.add_skipped(
          project_path,
          reason=('No clusters found at location {} in project {}').format(
              cluster_location, project))