Exemplo n.º 1
0
def check_healthy(tpu, zone=None, project=None, color=True, noisy=True):
  tpu = tpunicorn.get_tpu(tpu, zone=zone, project=project)
  if noisy:
    print_tpu_status(tpu, color=color)
  status = tpunicorn.format(tpu, '{status}')
  health = tpunicorn.format(tpu, '{health}')
  if status == 'READY' and health == 'HEALTHY':
    return True
  return False
Exemplo n.º 2
0
def print_tpu_status(tpu, format='text', color=True, project=None):
  if format == 'json':
    click.echo(json.dumps(tpu))
    return
  message = tpunicorn.format(tpu, project=project)
  if not color:
    click.echo(message)
  else:
    status = tpunicorn.format(tpu, '{status}', project=project)
    health = tpunicorn.format(tpu, '{health}', project=project)
    if status == 'READY' and health == 'HEALTHY':
      click.secho(message, fg='green')
      return 'HEALTHY'
    elif status == 'PREEMPTED':
      click.secho(message, fg='red')
    else:
      click.secho(message, fg='yellow')
Exemplo n.º 3
0
def print_tpu_status_headers(color=True, project=None):
  message = tpunicorn.format(tpunicorn.format_headers(), project=project)
  if color:
    click.secho(message, bold=color)
  else:
    click.echo(message)
Exemplo n.º 4
0
def is_preempted(tpu, zone=None, project=None):
  tpu = tpunicorn.get_tpu(tpu, zone=zone, project=project)
  status = tpunicorn.format(tpu, '{status}')
  return status == 'PREEMPTED'
Exemplo n.º 5
0
async def tpus(request):
    s = tpunicorn.format(tpunicorn.format_headers()) + '\n'
    for tpu in tpunicorn.get_tpus():
        s += tpunicorn.format(tpu) + '\n'
    return text(s)