summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xget_machine90
-rw-r--r--parse_credsfile14
2 files changed, 59 insertions, 45 deletions
diff --git a/get_machine b/get_machine
index 963cc35..7d4e619 100755
--- a/get_machine
+++ b/get_machine
@@ -1,13 +1,11 @@
#!/bin/bash
-. ./osrc.sh
-
-image_f20="db-f20_x86_64-cloud-0.0-2"
-flavor="m1.small"
-
+die() { echo "$@" ; exit 1 ; }
info() { echo " * $@" ; }
-option_distro=""
+opt_openstack_instance=os1
+opt_distro=fedora
+opt_distro_version=20
function show_help()
{
@@ -17,69 +15,71 @@ Usage: $0 OPTION
Script is aimed to help sysadmin.
Options:
- --distro Distro version, like fedora-20
+ --distro=NAME Distro name, like fedora
+ --distro-version=VERSION E.g. 20 for Fedora 20
+ --openstack-instance=ID
EOHELP
-test -n "$1" && exit $1
+test -n "$1" && exit "$1"
}
-ARGS=`getopt -o "" -l "help,distro:" -n "$0" -- "$@"` \
- || 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)
- case "$2" in
- fedora-*)
- option_distro=$2
- ;;
- *)
- echo "bad distro option $2, use fedora-20, etc."
- exit 1
- ;;
- esac
+ --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
-image_var=image_f${option_distro##fedora-}
-eval "image=\$$image_var"
-test -z "$image" && echo "no such image $image_var" && exit 1
+. ./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]}
-boot()
-{
- x=$(
- nova boot "$1" --poll --image "$2" --flavor "$3" \
- --security-groups praiskup-dbt \
- --key-name praiskup-test \
- | grep "| id " | cut -d\| -f 3
- )
- echo $x
-}
+test -z "$image" && die "no image for '$image_version'"
+test -z "$flavor" && die "no flavor for '$image_version'"
-get_ip()
-{
- local id="$1"
- ip=$(
- nova show "$id" | grep ' network ' \
- | cut -d\| -f 3 | cut -d, -f2
- )
- echo $ip
-}
+info "booting machine $image_version from $image"
-info "booting machine $option_distro from $image"
+machine=$(boot "testing-$image" "$image" "$flavor")
-machine=`boot "testing-$image_var" "$image" "$flavor"`
info "machine id: $machine"
-ip=`get_ip $machine`
+ip=$(get_ip "$machine")
info "ip: $ip"
diff --git a/parse_credsfile b/parse_credsfile
new file mode 100644
index 0000000..956ab4e
--- /dev/null
+++ b/parse_credsfile
@@ -0,0 +1,14 @@
+credsfile="private/os/$1.yml"
+
+while read line; do
+ if [[ "$line" =~ ^([a-zA-Z0-9_]*):\ ?(.*)$ ]]; then
+ key="${BASH_REMATCH[1]}"
+ if test "$key" = os_nova_password; then
+ key=os_password
+ fi
+ eval set ${BASH_REMATCH[2]}
+ eval "${key^^}"="\"$@\""
+ fi
+done < "$credsfile"
+
+# vi: syntax=sh