summaryrefslogtreecommitdiffstats
path: root/bootstrap/bootstrap-deb-functions
blob: caadbc2d0785b96f7c478093a3bc09e5a27714a3 (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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
#!/bin/sh

##########################
#### General Settings ####
##########################

set -u
#set -x # only for DEBUG


##########################
#### Global Variables ####
##########################

OPENBATON_COMPONENT_AUTOSTART_DEFAULT="true"


####################
#### Open Baton ####
####################

deb_add_openbaton_repo_reference () {
    export release_nightly="${1}"
    export distribution_codename="${2}"

    # Add Open Baton Public Key to the APT keys
    $_ex 'wget -O - http://get.openbaton.org/keys/openbaton.public.key | apt-key add -'

    # Add Open Baton Repo to sources.list file
    result=$(grep /etc/apt/sources.list -e "deb http://get.openbaton.org/repos/openbaton/${distribution_codename}/${release_nightly} ${distribution_codename} main" | wc -l)
    if [ ${result} -eq 0 ]; then
        $_ex 'echo "\n## Open Baton repository" >> /etc/apt/sources.list'
        $_ex 'echo "deb http://get.openbaton.org/repos/openbaton/${distribution_codename}/${release_nightly} ${distribution_codename} main" >> /etc/apt/sources.list'
    fi
    $_ex 'apt-get update'
}

##############
#### NFVO ####

deb_install_nfvo () {
    export release_nightly="${1}"
    export oldest_nfvo_version_supported="${2}"
    export nfvo_version="${3}"

    if [ "${DEBIAN_FRONTEND}" != "Noninteractive" -a "${DEBIAN_FRONTEND}" != "noninteractive" ]; then
        valid_version=false
        while [ "${valid_version}" = "false" ]; do
            # Ask for the NFVO version to be installed
            read -p " * Which VERSION of the Open Baton NFVO do you want to install (Version Format is X.Y.Z - ** ${oldest_nfvo_version_supported} is the oldest version supported ** - Check the list of available VERSIONs at: ${OPENBATON_NFVO_REPO_URL}/tags )? (latest): " nfvo_version

            if [ "${nfvo_version}" = "" -o "${nfvo_version}" = "latest" ]; then
                valid_version=true
                continue
            else
                result=$( echo ${nfvo_version} | grep "^[0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}$" | wc -l )
                if [ "${result}" != "0" ]; then
                    valid_version=true
                    continue
                fi
            fi
        done
    fi
    if [ "${nfvo_version}" = "" -o "${nfvo_version}" = "latest" ]; then
        nfvo_version=""
    else
        nfvo_version="=${nfvo_version}"
    fi

    # Install the correct NFVO package according to the given input parameter
    if [ "${release_nightly}" = "release" ]; then
        $_ex 'apt-get install -y openbaton-nfvo${nfvo_version}'
    else
        $_ex 'apt-get install -y openbaton-nfvo-nightly${nfvo_version}'
    fi    
}

deb_restart_nfvo () {
    if $_ex 'systemctl restart openbaton-nfvo.service' >/dev/null 2>&1 ; then
        log_success_msg "Restarting the Open Baton NFVO .."
    elif $_ex 'service openbaton-nfvo restart' >/dev/null 2>&1 ; then
        log_success_msg "Restarting the Open Baton NFVO .."
    elif $_ex 'restart openbaton-nfvo' >/dev/null 2>&1 ; then
        log_success_msg "Restarting the Open Baton NFVO .."
    else
        log_failure_msg "Restaring the Open Baton NFVO"
    fi
}

###############################
#### Additional Components ####

deb_install_additional_component_versioned () {
    if [ "${component_version}" = "" -o "${component_version}" = "latest" ]; then
        component_version=""
    else
        component_version="=${component_version}"
    fi

    if [ "${release_nightly}" = "release" ]; then
        $_ex 'apt-get install -y openbaton-${component_name}${component_version}'
    else
        $_ex 'apt-get install -y openbaton-${component_name}-nightly${component_version}'
    fi
}


deb_install_additional_component () {
    export release_nightly="${1}"
    export component_name="${2}"
    export component_name_fancy="${3}"
    export install_during_noninteractive_installation="${4}"
    export force_component_version="${5}"
    export oldest_component_version_supported="${6}"
    export component_repo_url="${7}"
    export component_version="${8}"

    if [ "${DEBIAN_FRONTEND}" != "Noninteractive" -a "${DEBIAN_FRONTEND}" != "noninteractive" ]; then
        # Ask for the specified Additional Component installation
        read -p " * Do you want to install also the Open Baton ${component_name_fancy}? ( if you do not, then you can still install it later with: sudo apt-get install openbaton-${component_name} ) (Y/n): " ac

        # Print correct warning message
        if [ "${ac}" = "n" -o "${ac}" = "N" -o "${ac}" = "no" -o "${ac}" = "NO" ]; then
            echo " * Open Baton ${component_name_fancy} not installed"
            if [ "${release_nightly}" = "release" ]; then
                echo " * To install the latest release package:"
                echo " *     sudo apt-get install openbaton-${component_name}"
            else
                echo " * To install the latest nightly-build package:"
                echo " *     sudo apt-get install openbaton-${component_name}-nightly"
            fi
            return
        else
            # Install the correct Additional Component package according to the given input parameter
            if [ ${force_component_version} != "true" ]; then 
                valid_version=false
                while [ "${valid_version}" = "false" ]; do
                    # Ask for the Additional Component version to be installed
                    read -p " * Which VERSION of the Open Baton ${component_name_fancy} do you want to install (Version Format is X.Y.Z - *** ${oldest_component_version_supported} is the oldest version supported ** - Check the list of available VERSIONs at: ${component_repo_url}/tags )? (latest): " component_version

                    if [ "${component_version}" = "" -o "${component_version}" = "latest" ]; then
                        valid_version=true
                        continue
                    else
                        result=$( echo ${component_version} | grep "^[0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}$" | wc -l )
                        if [ "${result}" != "0" ]; then
                            valid_version=true
                            continue
                        fi
                    fi
                done
            fi

            deb_install_additional_component_versioned
        fi
    else
        if [ "${install_during_noninteractive_installation}" = "y" -o "${install_during_noninteractive_installation}" = "Y" -o "${install_during_noninteractive_installation}" = "yes" ]; then
            # Install the correct Additional Component package according to the given input parameter
            deb_install_additional_component_versioned
        fi
    fi
}

deb_restart_additional_component () {
    export component_name=${1}
    export component_name_fancy="${2}"

    if $_ex 'systemctl restart openbaton-${component_name}.service' >/dev/null 2>&1 ; then
        log_success_msg "Restarting the Open Baton ${component_name_fancy} .."
    elif $_ex 'service openbaton-${component_name} restart' >/dev/null 2>&1 ; then
        log_success_msg "Restarting the Open Baton ${component_name_fancy} .."
    elif $_ex 'restart openbaton-${component_name}' >/dev/null 2>&1 ; then
        log_success_msg "Restarting the Open Baton ${component_name_fancy} .."
    else                                                        
        log_failure_msg "Restarting the Open Baton ${component_name_fancy}"
    fi
}

deb_is_additional_component_installed () {
    export component_name=${1}

    installed=$(dpkg -l | grep -v grep | grep "openbaton-${component_name}" | wc -l)
    if [ ${installed} -eq 0 ]; then
        installed=1 # not installed
    else
        installed=0 # installed
    fi
}


###################
#### Bootstrap ####
###################

deb_bootstrap () {
    export DEBIAN_FRONTEND=${openbaton_installation_manner:-$DEBIAN_FRONTEND_DEFAULT}
    export OPENBATON_COMPONENT_AUTOSTART="${openbaton_component_autostart:-$OPENBATON_COMPONENT_AUTOSTART_DEFAULT}"

    deb_add_openbaton_repo_reference "${1}" "${2}"
    deb_install_nfvo "${1}" "3.2.0" "${openbaton_nfvo_version}"
    install_mysql

    #
    # Arguments of "deb_install_additional_component": ${1} component-name component-name-fancy install_during_noninteractive_installation force_component_version oldest_component_version_supported component_version
    #

    # OpenStack VIM Driver Plugin
    deb_install_additional_component ${1} plugin-vimdriver-openstack-4j "OpenStack VIM-Driver Plugin" ${openbaton_plugin_vimdriver_openstack} false "3.2.2" "${OPENBATON_PLUGINS_VIMDRIVERS_OPENSTACK_4J_REPO_URL}" ${openbaton_plugin_vimdriver_openstack_version}

    # Generic VNFM
    deb_install_additional_component ${1} vnfm-generic "Generic VNFM" ${openbaton_vnfm_generic} false "3.2.0" "${OPENBATON_VNFM_GENERIC_REPO_URL}" ${openbaton_vnfm_generic_version}
    
    # Fault Management System
    deb_install_additional_component ${1} fms "Fault Management System" ${openbaton_fms} false "1.2.4" "${OPENBATON_FMS_REPO_URL}" ${openbaton_fms_version}
    
    # Auto Scaling Engine
    deb_install_additional_component ${1} ase "Auto Scaling Engine" ${openbaton_ase} false "1.2.2" "${OPENBATON_ASE_REPO_URL}" ${openbaton_ase_version}
    
    # Network Slicing Engine
    deb_install_additional_component ${1} nse "Network Slicing Engine" ${openbaton_nse} false "1.1.2" "${OPENBATON_NSE_REPO_URL}" ${openbaton_nse_version}

    # Command Line Interface
    openbaton_cli_version=$( echo "${openbaton_nfvo_version}" | sed 's/-//g' )
    deb_install_additional_component ${1} cli "Command Line Interface (CLI)" ${openbaton_cli} true "ignored" "ignored" "${openbaton_cli_version}"

    fix_jvm_delay_for_random_number_generation
    enable_https "openbaton-nfvo.properties"

    log_success_msg "Finalising Open Baton installation .."
    if [ "${OPENBATON_COMPONENT_AUTOSTART}" = "true" ]; then
        #########
        # Temporary workaround to avoid the spawning of multiple 'Test VIM Driver Plugin' processes during installation
        #wait_for_nfvo_up
        sleep 60
        #########

        log_success_msg "Restarting Open Baton components .."
        deb_restart_nfvo
        wait_for_nfvo_up # Some components needs the NFVO to be up in order to start correctly
        deb_is_additional_component_installed vnfm-generic ; if [ "${installed}" = "0" ]; then deb_restart_additional_component vnfm-generic "Generic VNFM" ; fi
        deb_is_additional_component_installed fms ; if [ "${installed}" = "0" ]; then deb_restart_additional_component fms "Fault Management System" ; fi
        deb_is_additional_component_installed ase ; if [ "${installed}" = "0" ]; then deb_restart_additional_component ase "Auto Scaling Engine" ; fi
        deb_is_additional_component_installed nse ; if [ "${installed}" = "0" ]; then deb_restart_additional_component nse "Network Slicing Engine" ; fi
    fi

    if [ -f "${BOOTSTRAP_DIR}/bootstrap-deb-functions" ]; then
        rm ${BOOTSTRAP_DIR}/bootstrap-deb-functions
    fi
}