aboutsummaryrefslogtreecommitdiffstats
path: root/juju/vims_deploy.sh
blob: 5fa86ac688e10b219e0d54d954083b7c47614a24 (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
#!/bin/bash -ex
##############################################################################
# Copyright (c) 2016-2017 HUAWEI TECHNOLOGIES CO.,LTD and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################

juju_client_ip=$(openstack server list | grep juju-client-vm | awk '{print $9}')

function exec_cmd_on_client()
{
    local ssh_args="-o StrictHostKeyChecking=no"

    if [ ! $juju_client_ip ]; then
        log_error "juju-client ip not found"
        exit 1
    fi
    ssh $ssh_args ubuntu@$juju_client_ip "$@"
}

function log_error() {
    echo -e "\033[31m$*\033[0m"
}

function check_clearwater() {
    check_clearwater_cmd='juju status | grep clearwater &> /dev/null'
    try=10
    duration=120
    clearwater_started=false
    while [[ $try -ge 0 ]]; do
        if [[ $try -eq 0 ]]; then
            log_error "Clearwater does not start within the given time"
            exit 1
        fi
        exec_cmd_on_client $check_clearwater_cmd
        if [[ $? -eq 0 ]]; then
            clearwater_started=true
            break
        else
            let try-=1
            sleep $duration
        fi
    done

    try=10
    duration=120
    check_status_cmd='juju status | grep idle | wc -l'
    while [[ $try -ge 0 ]]; do
        if [[ $try -eq 0 ]]; then
            log_error "Clearwater does not fully start within the given time"
            exit 1
        fi
        exec_cmd_on_client $check_status_cmd
        count=$(exec_cmd_on_client $check_status_cmd)
        if [[ $count -eq 7 ]]; then
            echo "Clearwater has fully started"
            break
        else
            echo "$count out of 7 nodes have started"
            let try-=1
            sleep $duration
        fi
    done

    get_ellis_cmd='juju status | grep clearwater-ellis | grep tcp | awk "{print \$5}"'
    ellis_internal_ip=$(exec_cmd_on_client $get_ellis_cmd)
    ellis_external_ip=$(openstack server list | grep $ellis_internal_ip | awk '{print $9}')

    get_bono_cmd='juju status | grep clearwater-bono | grep tcp | awk "{print \$5}"'
    bono_internal_ip=$(exec_cmd_on_client $get_bono_cmd)
    bono_external_ip=$(openstack server list | grep $bono_internal_ip | awk '{print $9}')

    echo "Ellis: $ellis_external_ip"
    echo "Bono: $bono_external_ip"
}