def setup_instance(zone, name, existing_instance_id=None):
  if not existing_instance_id:
    region_zones = ec2_utils.GetELBZones(env.region, node_types=[env.nodetype])
    assert zone, 'Availability zone not specified, available zones are: %s' % ' '.join(region_zones)

    user_data = load_passphrase_from_file()
    instance_id = ec2_utils.RunInstance(env.region, BASE_AMI, 'wwwkey', kInstanceType,
                                        availability_zone=zone, user_data=user_data)
    fprint('Launched new instance: %s' % instance_id)
  else:
    instance_id = existing_instance_id
    fprint('Resuming setup of instance %s' % instance_id)

  fprint('Adding tags NodeType=%s and Name=%s to instance %s' % (env.nodetype, name, instance_id))
  ec2_utils.CreateTag(env.region, instance_id, 'NodeType', env.nodetype)
  ec2_utils.CreateTag(env.region, instance_id, 'Name', name)

  for i in range(60):
    match = ec2_utils.GetInstance(env.region, instance_id)
    if match == None:
      fprint('Instance %s does not exist yet; waiting.' % instance_id)
    elif match.state != 'running':
      fprint('Instance %s in state %s; waiting.' % (instance_id, match.state))
    else:
      break
    time.sleep(2)
  else:
    fprint('Timed out waiting for instance: %s' % instance_id)
    raise Exception("timeout")
  assert match is not None and match.state == 'running'
  instance_hostname = match.public_dns_name
  fprint('Instance %s in state "running". Public DNS: %s' % (instance_id, instance_hostname))
  with settings(host_string=instance_hostname):
    for i in range(60):
      try:
        run("true")
        break
      except NetworkError:
        fprint('Waiting for instance to be sshable: %s' % instance_id)
        # don't retry too aggressively, it looks like we get blocked by a
        # firewall for too many failed attempts
        time.sleep(3)
    else:
      fprint('timed out waiting for sshability')
      raise Exception("timeout")

    # Install required packages.
    yum_install()
  return instance_id, instance_hostname
dataset/ETHPy150Open viewfinderco/viewfinder/fabfile.py/setup_instance/operator `is` -> `==`