diff options
author | Pavel Raiskup <praiskup@redhat.com> | 2014-10-22 08:54:05 +0200 |
---|---|---|
committer | Pavel Raiskup <praiskup@redhat.com> | 2014-10-22 08:54:05 +0200 |
commit | 2422a081a5be0d5ac5afb122361bc283da67341f (patch) | |
tree | cb255582060af6547dd9318c56ba0e8c761846a1 /controller/get_machine | |
parent | 922089746e1029de9be986672fcdeb6bc82e18d7 (diff) | |
download | postgresql-setup-tests-2422a081a5be0d5ac5afb122361bc283da67341f.tar.gz postgresql-setup-tests-2422a081a5be0d5ac5afb122361bc283da67341f.tar.xz postgresql-setup-tests-2422a081a5be0d5ac5afb122361bc283da67341f.zip |
big reorg: prepare for generalization
Try to split into three separate components -> controller, tester,
and 'tasks' (postgresql-tasks in our case). The controller
component is the main part which is able to run the task remotely.
Tester is more-like library for 'tasks' component (should be
reusable on the raw git level).
* controller: Almost separated component.
* postgresql-tasks: Likewise.
* tester: Likewise.
Diffstat (limited to 'controller/get_machine')
-rwxr-xr-x | controller/get_machine | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/controller/get_machine b/controller/get_machine new file mode 100755 index 0000000..7d4e619 --- /dev/null +++ b/controller/get_machine @@ -0,0 +1,85 @@ +#!/bin/bash + +die() { echo "$@" ; exit 1 ; } +info() { echo " * $@" ; } + +opt_openstack_instance=os1 +opt_distro=fedora +opt_distro_version=20 + +function show_help() +{ +cat <<EOHELP >&2 +Usage: $0 OPTION + +Script is aimed to help sysadmin. + +Options: + --distro=NAME Distro name, like fedora + --distro-version=VERSION E.g. 20 for Fedora 20 + --openstack-instance=ID +EOHELP +test -n "$1" && exit "$1" +} + +boot() +( + set -o pipefail + nova boot "$1" --poll \ + --image "$2" \ + --flavor "$3" \ + --security-groups "$os_security_group" \ + --key-name "$os_keypair" \ + | grep "| id " | cut -d\| -f 3 | xargs -n 1 +) + +get_ip() +( + id="$1" + set -o pipefail + nova show "$id" | grep ' network ' \ + | cut -d\| -f 3 | cut -d, -f2 | xargs -n 1 +) + + +longopts="distro:,distro-version:,openstack-instance:" +ARGS=$(getopt -o "" -l "help,$longopts" -n "$0" -- "$@") \ + || exit 1 +eval set -- "$ARGS" + +while true; do + case "$1" in + --distro|--distro-version|--openstack-instance) + opt=$(sed -e 's/^--//' -e 's/[^[a-zA-Z0-9]/_/g'<<<"$1") + eval "opt_$opt=\"${2,,}\"" + shift 2 + ;; + + --help) + show_help 0 + ;; + + --) + shift + break; + esac +done + +. ./parse_credsfile "$opt_openstack_instance" || exit 1 +. ./config/os/"$opt_openstack_instance.sh" || exit 1 + +image_version=$opt_distro$opt_distro_version +image=${os_image_ids[$image_version]} +flavor=${os_flavor_ids[$image_version]} + +test -z "$image" && die "no image for '$image_version'" +test -z "$flavor" && die "no flavor for '$image_version'" + +info "booting machine $image_version from $image" + +machine=$(boot "testing-$image" "$image" "$flavor") + +info "machine id: $machine" + +ip=$(get_ip "$machine") +info "ip: $ip" |