Пример #1
0
def _check_for_existing_cluster(cluster_name: str, project_id: str,
                                creds: Credentials):
  '''checks for an existing cluster and confirms new cluster creation with user

  Args:
  cluster_name: name of cluster to create
  project_id: project id
  creds: credentials

  Returns:
  True if cluster creation should proceed, False otherwise
  '''

  clusters = Cluster.list(project_id=project_id, creds=creds)

  if len(clusters) == 0:
    return True

  if cluster_name in clusters:
    logging.error('cluster {} already exists'.format(cluster_name))
    return False

  logging.info('{} clusters already exist for this project:'.format(
      len(clusters)))
  for c in clusters:
    logging.info(c)

  return util.user_verify('Do you really want to create a new cluster?',
                          default=False)
Пример #2
0
def _cluster_ls(args: dict, project_id: str, creds: Credentials) -> None:
  """lists clusters

  Args:
  args: commandline args
  project_id: list clusters in the project
  creds: credentials to use
  """
  clusters = Cluster.list(project_id=project_id, creds=creds)

  if clusters is None:
    return

  cluster_name = args.get('cluster_name', None)

  if cluster_name is not None:
    if cluster_name not in clusters:
      logging.error('cluster {} not found'.format(cluster_name))
      return
    logging.error(cluster_name)
    return

  logging.info('{} clusters found'.format(len(clusters)))
  for c in clusters:
    logging.info(c)

  return