@task
def undrain():
  ami = get_ami_metadata()
  instance_id = ami['instance-id']

  fprint('Waiting for healthy backend')
  num_healthz_ok = 0
  for i in range(60):
    if get_healthz():
      num_healthz_ok += 1
      if num_healthz_ok >= 3:
        break
    else:
      num_healthz_ok = 0
    time.sleep(2)
  if num_healthz_ok < 3:
    raise Exception('healthz timeout')

  ec2_utils.AddELBInstance(env.region, instance_id, env.nodetype)
  fprint('Added instance %s to %s load balancers' % (instance_id, env.nodetype))
  for i in range(60):
    health = ec2_utils.GetELBInstanceHealth(env.region, instance_id, node_types=[env.nodetype])
    if health is None:
      fprint('No load balancer health information for instance %s; waiting.' % instance_id)
    elif health == 'InService':
      fprint('Load balancer health for instance %s is InService.' % instance_id)
      return
    else:
      fprint('Load balancer health information for instance %s is %s; waiting.' % (instance_id, health))
    time.sleep(2)
  raise Exception('timeout')
Undrain nodes of a given type.
dataset/ETHPy150Open viewfinderco/viewfinder/fabfile.py/undrain