diff --git a/roles/copr/backend/tasks/resalloc.yml b/roles/copr/backend/tasks/resalloc.yml index 3b0605aad2..edad112ca4 100644 --- a/roles/copr/backend/tasks/resalloc.yml +++ b/roles/copr/backend/tasks/resalloc.yml @@ -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 diff --git a/roles/copr/backend/templates/resalloc/pools.yaml b/roles/copr/backend/templates/resalloc/pools.yaml index 75d99801d3..aa56089b19 100644 --- a/roles/copr/backend/templates/resalloc/pools.yaml +++ b/roles/copr/backend/templates/resalloc/pools.yaml @@ -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) diff --git a/roles/copr/backend/templates/resalloc/vm-aws-delete b/roles/copr/backend/templates/resalloc/vm-aws-delete new file mode 100755 index 0000000000..c3e981a383 --- /dev/null +++ b/roles/copr/backend/templates/resalloc/vm-aws-delete @@ -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"'"}}' diff --git a/roles/copr/backend/templates/resalloc/vm-aws-new b/roles/copr/backend/templates/resalloc/vm-aws-new new file mode 100755 index 0000000000..534ba4bf17 --- /dev/null +++ b/roles/copr/backend/templates/resalloc/vm-aws-new @@ -0,0 +1,66 @@ +#! /usr/bin/bash + +set -e + +show_help() +{ +cat <&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"