summaryrefslogtreecommitdiff
path: root/devstack/libs/fast-path
blob: 04d075d1a64197411530fc4f710ebb0b09355941 (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
#!/bin/bash
#
# Copyright 2015 6WIND S.A.


function install_va_deb_pkg {
    sudo apt-get install -y --force-yes virtual-accelerator
}

function setup_va_local_repo {
    cd $VA_PKG_DIR/..
    DEB_DIR=`basename $VA_PKG_DIR`
    sudo mkdir -p /etc/apt/sources.list.d
    echo "deb file:$PWD/$DEB_DIR/ ./" |  sudo tee /etc/apt/sources.list.d/6wind.list
    # allow unauthenticated packages
    # TODO: create an authenticated local repo
    echo 'APT::Get::AllowUnauthenticated 1;' | sudo tee  /etc/apt/apt.conf.d/02unauthenticated
    sudo apt-get update
}

function setup_va_remote_repo {
    cd $VA_REPO_DIR
    sudo dpkg -i $VA_CREDENTIALS_PACKAGE
    sudo curl --cacert /usr/local/etc/certs/6wind_ca.crt --key /usr/local/etc/certs/6wind_client.key --cert /usr/local/etc/certs/6wind_client.crt -o 6wind-virtual-accelerator-repository.deb https://repo.6wind.com/virtual-accelerator/ubuntu-16.04/$(dpkg --print-architecture)/$VA_VERSION/6wind-virtual-accelerator-ubuntu-16.04-repository_$VA_VERSION-1_$(dpkg --print-architecture).deb
    sudo dpkg -i 6wind-virtual-accelerator-repository.deb
    sudo apt-get update
}

function uninstall_va_deb_pkg {
    uninstall_package virtual-accelerator
}

function remove_va_local_repo {
    sudo rm /etc/apt/sources.list.d/6wind.list
    sudo apt-get update
}

function remove_va_remote_repo {
    cd $VA_REPO_DIR
    sudo rm /etc/apt/sources.list.d/6wind-virtual-accelerator.list
    sudo apt-get update
}

function install_va {
    if is_ubuntu; then
        install_va_deb_pkg
    else
        exit_distro_not_supported "devstack networking_6wind not supported on this distrib"
    fi
}

function setup_va_repo {
    if is_ubuntu; then
        if [[ $VA_PKG_DIR ]]; then
            setup_va_local_repo
            return
        fi

        if [[ $VA_REPO_DIR ]]; then
            setup_va_remote_repo
            return
        fi
    else
        exit_distro_not_supported "devstack networking_6wind not supported on this distrib"
    fi 
}

function uninstall_va {
    if is_ubuntu; then
        uninstall_va_deb_pkg
    else
        exit_distro_not_supported "devstack networking_6wind not supported on this distrib"
    fi
}

function remove_va_repo {
     if is_ubuntu; then
        if [[ $VA_PKG_DIR ]]; then
            remove_va_local_repo
            return
        fi

        if [[ $VA_REPO_DIR ]]; then
            remove_va_remote_repo
            return
        fi
    else
        exit_distro_not_supported "devstack networking_6wind not supported on this distrib"
    fi
}

function set_va_opt {
    if grep -q '^#\?: \${'"$1"':=.*}' "$3"; then
        sudo sed -i -- 's@^#\?: \${'"$1"':=.*@: ${'"$1"':='"$2"'}@' "$3";
    else
        sudo echo >> $3;
        sudo echo '# Config added by networking_6wind plugin' >> $3;
        sudo echo ': ${'"$1"':='"$2"'}' >> $3;
    fi
}

function write_va_conf {
    FP_CONF="/usr/local/etc/fast-path.env"

    if [[ ! -f $FP_CONF ]]; then
        sudo cp /usr/local/etc/fast-path.env.tmpl $FP_CONF

        if [[ -n $VM_MEMORY ]]; then
            set_va_opt "VM_MEMORY" "$VM_MEMORY" $FP_CONF
        fi

        if [[ -n $FP_MEMORY ]]; then
            set_va_opt "FP_MEMORY" "$FP_MEMORY" $FP_CONF
        fi

        if [[ "$FP_GREEN_MODE" == "True" ]]; then
            set_va_opt "MAINLOOP_DELAY_US" "500" $FP_CONF
        fi
    fi
}

function start_va {
    if is_ubuntu; then
        sudo service virtual-accelerator start
        sudo service openvswitch-switch restart
        sudo service libvirt-bin restart
    else
        exit_distro_not_supported "devstack networking_6wind not supported on this distrib"
    fi
}

function stop_va {
    sudo service virtual-accelerator stop
}

function start_rpc_fp_server {
    /usr/local/bin/rpc-fp-server &
}

function stop_rpc_fp_server {
    killall rpc-fp-server
}