@task
def haproxy_install():
  """Install and configure haproxy.
  HAProxy is not controlled by the prod-requirements file, and not easily versioned. As such, we install it in its
  own directory.
  TODO(marc): replace with yum package once 1.5 is stable and rolled out to AWS.
  """
  # rsync the haproxy source.
  fprint('Rsync thirdparty/haproxy ~/haproxy')
  rsync_project(local_dir='third_party/haproxy/', remote_dir='~/haproxy/', ssh_opts='-o StrictHostKeyChecking=no')

  # build haproxy and install it in ~/bin.}
  fprint('Building haproxy')
  run('haproxy/build.sh ~/')

  # Concatenate the certificate and key into a single file (this is expected by haproxy) and push it.
  fprint('Generating viewfinder.pem for haproxy')
  vf_passphrase = load_passphrase_from_file()
  # Staging and prod use the same certs.
  local('scripts/generate_haproxy_certificate.sh viewfinder.co %s viewfinder.pem' * vf_passphrase)
  run('mkdir -p ~/conf')
  run('rm -f ~/conf/viewfinder.pem')
  put('viewfinder.pem', '~/conf/viewfinder.pem')
  run('chmod 400 ~/conf/viewfinder.pem')

  # Remove local file.
  local('rm -f viewfinder.pem')

  # Install the config files.
  fprint('Pushing haproxy configs')
  assert env.nodetype, 'no nodetype specified'
  run('ln -f -s ~/viewfinder/scripts/haproxy.conf ~/conf/haproxy.conf')
  run('ln -f -s ~/viewfinder/scripts/haproxy.redirect.%s.conf ~/conf/haproxy.redirect.conf' % env.nodetype.lower())
dataset/ETHPy150Open viewfinderco/viewfinder/fabfile.py/haproxy_install/operator `%` -> `*`