summaryrefslogtreecommitdiff
path: root/devstack/csr1kv/cisco_neutron
blob: fe102cb211145f96f39a56cc5e318448f968dde4 (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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#!/usr/bin/env bash
#
# lib/neutron
# functions - functions specific to neutron

# Dependencies:
# ``functions`` file
# ``DEST`` must be defined
# ``STACK_USER`` must be defined

# ``stack.sh`` calls the entry points in this order:
#
# - net_configure_neutron
# - net_start_neutron_agents
# - net_create_neutron_initial_network
#
# ``unstack.sh`` calls the entry points in this order:
#
# - net_stop_neutron

# Neutron Networking
# ------------------

# Make sure that neutron is enabled in ``ENABLED_SERVICES``.  If you want
# to run Neutron on this host, make sure that q-svc is also in
# ``ENABLED_SERVICES``.
#
# See "Neutron Network Configuration" below for additional variables
# that must be set in localrc for connectivity across hosts with
# Neutron.
#
# With Neutron networking the NETWORK_MANAGER variable is ignored.

# Settings
# --------
# Set up default directories
NEUTRON_CONF_DIR=/etc/neutron
NEUTRON_CONF=$NEUTRON_CONF_DIR/neutron.conf
count=0
Q_CISCO_CSR1KV_SETUP_SCRIPT_DIR=${Q_CISCO_CSR1KV_SETUP_SCRIPT_DIR:-$DIR_CISCO/devstack/csr1kv}
# Default Neutron Plugin
Q_PLUGIN=${Q_PLUGIN:-cisco}
# Default Neutron Port
Q_PORT=${Q_PORT:-9696}
# Default protocol
Q_PROTOCOL=${Q_PROTOCOL:-$SERVICE_PROTOCOL}
# RHEL's support for namespaces requires using veths with ovs
Q_USE_ROOTWRAP=${Q_USE_ROOTWRAP:-True}
# nova vif driver that all plugins should use
Q_NOTIFY_NOVA_PORT_STATUS_CHANGES=${Q_NOTIFY_NOVA_PORT_STATUS_CHANGES:-True}
Q_NOTIFY_NOVA_PORT_DATA_CHANGES=${Q_NOTIFY_NOVA_PORT_DATA_CHANGES:-True}

Q_CISCO_MGMT_CFG_AGENT_IP=10.0.100.2
# Enable ASR1K
Q_CISCO_ASR1K_ENABLED=${Q_CISCO_ASR1K_ENABLED:-True}

# MySQL info
MYSQL_USER=${MYSQL_USER:root}
MYSQL_PASSWORD=${MYSQL_PASSWORD:password}

source $DIR_CISCO/devstack/csr1kv/cisco
source $DIR_CISCO/devstack/csr1kv/cisco_router
source $DIR_CISCO/devstack/csr1kv/ciscocfgagent

# Cisco Routing Service Plugin functions
# ---------------------------------
# Use security group or not
# Save trace setting
XTRACE=$(set +o | grep xtrace)
set +o xtrace
# Functions
# ---------
# Test if any Neutron services are enabled
# is_neutron_enabled
function is_neutron_enabled {
    [[ ,${ENABLED_SERVICES} =~ ,"q-" ]] && return 0
    return 1
}

function configure_cisco_csr_router {
    net_create_neutron_accounts
    net_configure_neutron
    net_start_neutron_agents
    Q_L3_ENABLED="False"
}

function start_cisco_csr_router {
    if [[ "$count" == 0 ]];then
        if [[ "$Q_CISCO_ASR1K_ENABLED" == "True" ]]; then
            setup_for_asr1k
        else
            setup_for_csr1kv
        fi
        Q_L3_ENABLED="True"
        net_create_neutron_initial_network
        count=$((count+1))
    fi
}


# net_configure_neutron()
# Set common config for Cisco router after neutron server and agents.
function net_configure_neutron {
    # goes before q-svc to init Q_SERVICE_PLUGIN_CLASSES
    if is_service_enabled q-ciscorouter; then
        _configure_neutron_cisco_router
    fi
    if is_service_enabled q-agt q-svc; then
        _configure_neutron_service
    fi
}

function get_or_add_user_role {
    # Gets user role id
    local user_role_id=$(openstack user role list \
        $2 \
        --project $3 \
        --column "ID" \
        --column "Name" \
        | grep " $1 " | get_field 1)
    if [[ -z "$user_role_id" ]]; then
        # Adds role to user
        user_role_id=$(openstack role add \
            $1 \
            --user $2 \
            --project $3 \
            | grep " id " | get_field 2)
    fi
    echo $user_role_id
}
# net_create_neutron_accounts() - Set up common required neutron accounts

# Tenant               User       Roles
# ------------------------------------------------------------------
# service              neutron    admin        # if enabled

# Migrated from keystone_data.sh
function net_create_neutron_accounts {
    local service_tenant=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
    local service_role=$(openstack role list | awk "/ service / { print \$2 }")

    if [[ "$ENABLED_SERVICES" =~ "q-svc" ]]; then

        local neutron_user=$(get_or_create_user "neutron" \
            "$SERVICE_PASSWORD" $service_tenant)
        get_or_add_user_role $service_role $neutron_user $service_tenant
        if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then

            local neutron_service=$(get_or_create_service "neutron" \
                "network" "Neutron Service")
            get_or_create_endpoint $neutron_service \
                "$REGION_NAME" \
                "$Q_PROTOCOL://$SERVICE_HOST:$Q_PORT/" \
                "$Q_PROTOCOL://$SERVICE_HOST:$Q_PORT/" \
                "$Q_PROTOCOL://$SERVICE_HOST:$Q_PORT/"
        fi
    fi
}

function setup_for_asr1k {
    if [[ "$Q_PLUGIN" == "ml2" ]]; then
	    plugin=ovs
    fi
    echo "Running ASR1K setup scripts with ${MYSQL_USER} ${MYSQL_PASSWORD}"
    if [[ -f $TOP_DIR/localrc ]]; then
        localrc_name=$TOP_DIR/localrc
    else
        localrc_name=$TOP_DIR/local.conf
    fi
    (cd $Q_CISCO_CSR1KV_SETUP_SCRIPT_DIR; ./csr1kv_install_all.sh neutron $plugin $localrc_name $MYSQL_USER $MYSQL_PASSWORD $Q_CISCO_MGMT_CFG_AGENT_IP True)

}

function setup_for_csr1kv {
    if [[ "$Q_PLUGIN" == "csr1kv_openvswitch" ]]; then
	    plugin=ovs
    elif [[ "$Q_PLUGIN" == "cisco" || "${Q_CISCO_PLUGIN_SUBPLUGINS[0]}" == "n1kv" ]]; then
	    plugin=n1kv
    else
	    die $LINENO "Not a deployment with CSR1kv. Exiting!"
    fi
    echo "Running CSR1Kv setup with ${MYSQL_USER} ${MYSQL_PASSWORD}"
    if [[ -f $TOP_DIR/localrc ]]; then
        localrc_name=$TOP_DIR/localrc
    else
        localrc_name=$TOP_DIR/local.conf
    fi
    (cd $Q_CISCO_CSR1KV_SETUP_SCRIPT_DIR; ./csr1kv_install_all.sh neutron $plugin $localrc_name $MYSQL_USER $MYSQL_PASSWORD $Q_CISCO_MGMT_CFG_AGENT_IP False)
}

function net_create_neutron_initial_network {
      if [ "$Q_L3_ENABLED" == "True" && $NEUTRON_CREATE_INITIAL_NETWORK = "True" ]; then
        # Create a router, and add the private subnet as one of its interfaces
        if [[ "$Q_L3_ROUTER_PER_TENANT" == "True" ]]; then
            # create a tenant-owned router.
            DEMO_TENANT_NAME="demo"
            DEMO_TENANT_ID=$(openstack project list | awk "/ $DEMO_TENANT_NAME / { print \$2 }")
            ROUTER_ID=$(neutron router-create --tenant-id $DEMO_TENANT_ID $Q_ROUTER_NAME | grep ' id ' | get_field 2)
            die_if_not_set $LINENO ROUTER_ID "Failure creating ROUTER_ID for $TENANT_ID $Q_ROUTER_NAME"
        else
            # Plugin only supports creating a single router, which should be admin owned.
            ROUTER_ID=$(neutron router-create $Q_ROUTER_NAME | grep ' id ' | get_field 2)
            die_if_not_set $LINENO ROUTER_ID "Failure creating ROUTER_ID for $Q_ROUTER_NAME"
        fi

        # Create an external network, and a subnet. Configure the external network as router gw
        if [ "$Q_USE_PROVIDERNET_FOR_PUBLIC" = "True" ]; then
            EXT_NET_ID=$(neutron net-create "$PUBLIC_NETWORK_NAME" -- --router:external=True --provider:network_type=flat --provider:physical_network=${PUBLIC_PHYSICAL_NETWORK} | grep ' id ' | get_field 2)
        else
            EXT_NET_ID=$(neutron net-create "$PUBLIC_NETWORK_NAME" -- --router:external=True | grep ' id ' | get_field 2)
        fi
        die_if_not_set $LINENO EXT_NET_ID "Failure creating EXT_NET_ID for $PUBLIC_NETWORK_NAME"
        if [[ "$IP_VERSION" =~ 4.* ]]; then
            # Configure router for IPv4 public access
            _neutron_configure_router_v4
        fi

        if [[ "$IP_VERSION" =~ .*6 ]]; then
            # Configure router for IPv6 public access
            _neutron_configure_router_v6
        fi
    fi

}

# Start running processes, including screen
function net_start_neutron_agents {
    if is_service_enabled ciscocfgagent; then
        start_the_ciscocfgagent
    fi
}

# net_stop_neutron() - Stop running processes (non-screen)
function net_stop_neutron {
    if is_service_enabled q-ciscorouter; then
         neutron_cisco_router_stop
    fi
}

function _configure_neutron_cisco_router {
    neutron_cisco_router_configure_common
}

# _configure_neutron_service() - Set config files for neutron service
# It is called when q-svc is enabled.
function _configure_neutron_service {
    Q_API_PASTE_FILE=$NEUTRON_CONF_DIR/api-paste.ini
    Q_POLICY_FILE=$NEUTRON_CONF_DIR/policy.json

     # Update either configuration file with plugin
    iniset $NEUTRON_CONF DEFAULT core_plugin $Q_PLUGIN_CLASS

    if [[ $Q_SERVICE_PLUGIN_CLASSES != '' ]]; then
        iniset $NEUTRON_CONF DEFAULT service_plugins $Q_SERVICE_PLUGIN_CLASSES
    fi
    # Configuration for neutron notifations to nova.
    iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_status_changes $Q_NOTIFY_NOVA_PORT_STATUS_CHANGES
    iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_data_changes $Q_NOTIFY_NOVA_PORT_DATA_CHANGES
    iniset $NEUTRON_CONF DEFAULT nova_url "$NOVA_SERVICE_PROTOCOL://$NOVA_SERVICE_HOST:$NOVA_SERVICE_PORT/v2"
    iniset $NEUTRON_CONF DEFAULT nova_admin_username nova
    iniset $NEUTRON_CONF DEFAULT nova_admin_password $SERVICE_PASSWORD
    ADMIN_TENANT_ID=$(openstack project list | awk "/ service / { print \$2 }")
    iniset $NEUTRON_CONF DEFAULT nova_admin_tenant_id $ADMIN_TENANT_ID
    iniset $NEUTRON_CONF DEFAULT nova_admin_auth_url  "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_AUTH_PORT/v2.0"

    # Configure plugin
    net_neutron_plugin_configure_service
}
# Restore xtrace
$XTRACE

# Tell emacs to use shell-script-mode
## Local variables:
## mode: shell-script
## End: