summaryrefslogtreecommitdiffstats
path: root/get_machine
diff options
context:
space:
mode:
Diffstat (limited to 'get_machine')
-rwxr-xr-xget_machine85
1 files changed, 85 insertions, 0 deletions
diff --git a/get_machine b/get_machine
new file mode 100755
index 0000000..963cc35
--- /dev/null
+++ b/get_machine
@@ -0,0 +1,85 @@
+#!/bin/bash
+
+. ./osrc.sh
+
+image_f20="db-f20_x86_64-cloud-0.0-2"
+flavor="m1.small"
+
+info() { echo " * $@" ; }
+
+option_distro=""
+
+function show_help()
+{
+cat <<EOHELP >&2
+Usage: $0 OPTION
+
+Script is aimed to help sysadmin.
+
+Options:
+ --distro Distro version, like fedora-20
+EOHELP
+test -n "$1" && exit $1
+}
+
+ARGS=`getopt -o "" -l "help,distro:" -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
+ 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
+
+
+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
+}
+
+get_ip()
+{
+ local id="$1"
+ ip=$(
+ nova show "$id" | grep ' network ' \
+ | cut -d\| -f 3 | cut -d, -f2
+ )
+ echo $ip
+}
+
+info "booting machine $option_distro from $image"
+
+machine=`boot "testing-$image_var" "$image" "$flavor"`
+info "machine id: $machine"
+
+ip=`get_ip $machine`
+info "ip: $ip"