summaryrefslogtreecommitdiffstats
path: root/get_machine
blob: 963cc35b8e20429463867eb58242e018d0109011 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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"