copr-be-dev: first attempt to allocate AWS VMs by resalloc

This commit is contained in:
Pavel Raiskup 2020-05-07 14:05:22 +02:00
parent a9d3483554
commit d4865aca5d
4 changed files with 90 additions and 2 deletions

View file

@ -53,9 +53,13 @@
tags:
- provision_config
- name: resalloc, spawner script
template: src="resalloc/vm-aarch64-new" dest="/var/lib/resallocserver/resalloc_provision/"
- name: resalloc, scripts
template: src="resalloc/{{ item }}" dest="/var/lib/resallocserver/resalloc_provision/"
mode=755
with_items:
- vm-aarch64-new
- vm-aws-new
- vm-aws-delete
tags:
- provision_config

View file

@ -23,6 +23,18 @@ aarch64_02_prod:
tags:
- aarch64
{% elif devel %}
aws_x86_64_normal:
max: 15
max_starting: 5
max_prealloc: 2
tags:
- copr_builder
- arch_x86_64
- arch_x86_64_native
cmd_new: "/var/lib/resallocserver/resalloc_provision/aws-new --arch=x86_64"
cmd_delete: "/var/lib/resallocserver/resalloc_provision/aws-delete"
# Development configuration. On each aarch64 host we have
# 2 guests vms of
# - 2 VCPUs (default)

View file

@ -0,0 +1,6 @@
#! /bin/sh -x
die() { echo "$*" >&2 ; exit 1; }
test -n "$RESALLOC_NAME" || die "no RESALLOC_NAME"
ansible-playbook /home/copr/provision/terminatepb-aws.yml \
--extra-vars '{"copr_task": {"vm_name": "'"$RESALLOC_NAME"'"}}'

View file

@ -0,0 +1,66 @@
#! /usr/bin/bash
set -e
show_help()
{
cat <<EOHELP >&2
Usage: $0 --arch ARCH
Allocate AWS VM instance for Copr build system.
Options:
--arch native architecture (required)
-h, --help show this help
Environment variables:
\$RESALLOC_NAME the name given to the allocated instance, will be
later used for termination, too
EOHELP
test -z "$1" || exit "$1"
}
# handle no arguments
test ${#@} -eq 0 && show_help 1
ARGS=$(getopt -o "h" -l "arch:,help" -n "getopt" -- "$@") \
|| show_help 1
eval set -- "$ARGS"
opt_arch=
while true; do
# now the name is in $1 and argument in $2
case $1 in
--arch)
opt=${1##--}
opt=${opt##-}
opt=${opt//-/_}
eval "opt_$opt=\$2"
shift 2
;;
-h|--help) show_help 0;;
--) # end!
shift; break;;
*) echo "programmer mistake ($1)" >&2; exit 1;;
esac
done
case $opt_arch in
x86_64|aarch64) ;;
*) echo >&2 "wrong arch: $opt_arch"; show_help 1;;
esac
test -n "$opt_arch" || show_help 1
# TODO: We should call aws-cli directly here, instead of parsing output of
# ansible playbook. But at the time of writing this script we had the playbook
# available, so parsing the output is the easiest way to start.
playbook=/var/lib/resallocserver/provision/builderpb-aws-"$opt_arch".yml
{
vm_ip=$(ansible-playbook "$playbook" |& tee >(cat - >&$stderr_fd) \
| sed -n 's/.*"VM_IP=\(.*\)"/\1/p' )
} {stderr_fd}>&2
test -n "$vm_ip"