Salvatore Orlando | d6767d0 | 2012-08-31 04:55:20 -0700 | [diff] [blame] | 1 | # lib/quantum |
| 2 | # functions - funstions specific to quantum |
| 3 | |
Dean Troyer | 60e9c0a | 2012-12-06 15:52:52 -0600 | [diff] [blame] | 4 | # Dependencies: |
| 5 | # ``functions`` file |
| 6 | # ``DEST`` must be defined |
| 7 | |
Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 8 | # ``stack.sh`` calls the entry points in this order: |
| 9 | # |
| 10 | # install_quantum |
| 11 | # install_quantumclient |
| 12 | # install_quantum_agent_packages |
| 13 | # install_quantum_third_party |
| 14 | # setup_quantum |
| 15 | # setup_quantumclient |
| 16 | # configure_quantum |
| 17 | # init_quantum |
| 18 | # configure_quantum_third_party |
| 19 | # init_quantum_third_party |
| 20 | # start_quantum_third_party |
| 21 | # create_nova_conf_quantum |
| 22 | # start_quantum_service_and_check |
| 23 | # create_quantum_initial_network |
| 24 | # setup_quantum_debug |
| 25 | # start_quantum_agents |
| 26 | # |
| 27 | # ``unstack.sh`` calls the entry points in this order: |
| 28 | # |
| 29 | # stop_quantum |
| 30 | |
| 31 | # Functions in lib/quantum are classified into the following categories: |
| 32 | # |
| 33 | # - entry points (called from stack.sh or unstack.sh) |
| 34 | # - internal functions |
| 35 | # - quantum exercises |
| 36 | # - 3rd party programs |
| 37 | |
Dean Troyer | 60e9c0a | 2012-12-06 15:52:52 -0600 | [diff] [blame] | 38 | |
| 39 | # Quantum Networking |
| 40 | # ------------------ |
| 41 | |
| 42 | # Make sure that quantum is enabled in ``ENABLED_SERVICES``. If you want |
| 43 | # to run Quantum on this host, make sure that q-svc is also in |
| 44 | # ``ENABLED_SERVICES``. |
| 45 | # |
| 46 | # If you're planning to use the Quantum openvswitch plugin, set |
| 47 | # ``Q_PLUGIN`` to "openvswitch" and make sure the q-agt service is enabled |
| 48 | # in ``ENABLED_SERVICES``. If you're planning to use the Quantum |
| 49 | # linuxbridge plugin, set ``Q_PLUGIN`` to "linuxbridge" and make sure the |
| 50 | # q-agt service is enabled in ``ENABLED_SERVICES``. |
| 51 | # |
| 52 | # See "Quantum Network Configuration" below for additional variables |
| 53 | # that must be set in localrc for connectivity across hosts with |
| 54 | # Quantum. |
| 55 | # |
| 56 | # With Quantum networking the NET_MAN variable is ignored. |
| 57 | |
| 58 | |
Salvatore Orlando | d6767d0 | 2012-08-31 04:55:20 -0700 | [diff] [blame] | 59 | # Save trace setting |
| 60 | XTRACE=$(set +o | grep xtrace) |
| 61 | set +o xtrace |
| 62 | |
Dean Troyer | 60e9c0a | 2012-12-06 15:52:52 -0600 | [diff] [blame] | 63 | |
Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 64 | # Quantum Network Configuration |
| 65 | # ----------------------------- |
Dean Troyer | 60e9c0a | 2012-12-06 15:52:52 -0600 | [diff] [blame] | 66 | |
| 67 | # Set up default directories |
Nachi Ueno | 8bc21f6 | 2012-11-19 22:04:28 -0800 | [diff] [blame] | 68 | QUANTUM_DIR=$DEST/quantum |
Dean Troyer | 60e9c0a | 2012-12-06 15:52:52 -0600 | [diff] [blame] | 69 | QUANTUMCLIENT_DIR=$DEST/python-quantumclient |
Gary Kotton | 9343df1 | 2012-11-28 10:05:53 +0000 | [diff] [blame] | 70 | QUANTUM_AUTH_CACHE_DIR=${QUANTUM_AUTH_CACHE_DIR:-/var/cache/quantum} |
Nachi Ueno | 5db5bfa | 2012-10-29 11:25:29 -0700 | [diff] [blame] | 71 | |
Dean Troyer | 60e9c0a | 2012-12-06 15:52:52 -0600 | [diff] [blame] | 72 | QUANTUM_CONF_DIR=/etc/quantum |
| 73 | QUANTUM_CONF=$QUANTUM_CONF_DIR/quantum.conf |
| 74 | export QUANTUM_TEST_CONFIG_FILE=${QUANTUM_TEST_CONFIG_FILE:-"$QUANTUM_CONF_DIR/debug.ini"} |
| 75 | |
| 76 | # Default Quantum Plugin |
| 77 | Q_PLUGIN=${Q_PLUGIN:-openvswitch} |
| 78 | # Default Quantum Port |
| 79 | Q_PORT=${Q_PORT:-9696} |
| 80 | # Default Quantum Host |
| 81 | Q_HOST=${Q_HOST:-$HOST_IP} |
Dean Troyer | 60e9c0a | 2012-12-06 15:52:52 -0600 | [diff] [blame] | 82 | # Default admin username |
| 83 | Q_ADMIN_USERNAME=${Q_ADMIN_USERNAME:-quantum} |
| 84 | # Default auth strategy |
| 85 | Q_AUTH_STRATEGY=${Q_AUTH_STRATEGY:-keystone} |
| 86 | # Use namespace or not |
| 87 | Q_USE_NAMESPACE=${Q_USE_NAMESPACE:-True} |
| 88 | Q_USE_ROOTWRAP=${Q_USE_ROOTWRAP:-True} |
| 89 | # Meta data IP |
| 90 | Q_META_DATA_IP=${Q_META_DATA_IP:-$HOST_IP} |
Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 91 | # Allow Overlapping IP among subnets |
| 92 | Q_ALLOW_OVERLAPPING_IP=${Q_ALLOW_OVERLAPPING_IP:-False} |
Dean Troyer | 60e9c0a | 2012-12-06 15:52:52 -0600 | [diff] [blame] | 93 | # Use quantum-debug command |
| 94 | Q_USE_DEBUG_COMMAND=${Q_USE_DEBUG_COMMAND:-False} |
| 95 | |
Nachi Ueno | 8bc21f6 | 2012-11-19 22:04:28 -0800 | [diff] [blame] | 96 | if is_service_enabled quantum; then |
Dean Troyer | 60e9c0a | 2012-12-06 15:52:52 -0600 | [diff] [blame] | 97 | Q_RR_CONF_FILE=$QUANTUM_CONF_DIR/rootwrap.conf |
Nachi Ueno | 8bc21f6 | 2012-11-19 22:04:28 -0800 | [diff] [blame] | 98 | if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then |
| 99 | Q_RR_COMMAND="sudo" |
| 100 | else |
Nachi Ueno | eb1aa3d | 2012-12-06 11:55:29 -0800 | [diff] [blame] | 101 | QUANTUM_ROOTWRAP=$(get_rootwrap_location quantum) |
| 102 | Q_RR_COMMAND="sudo $QUANTUM_ROOTWRAP $Q_RR_CONF_FILE" |
Nachi Ueno | 8bc21f6 | 2012-11-19 22:04:28 -0800 | [diff] [blame] | 103 | fi |
Nachi Ueno | 8bc21f6 | 2012-11-19 22:04:28 -0800 | [diff] [blame] | 104 | |
Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 105 | # Provider Network Configurations |
| 106 | # -------------------------------- |
| 107 | |
| 108 | # The following variables control the Quantum openvswitch and |
| 109 | # linuxbridge plugins' allocation of tenant networks and |
| 110 | # availability of provider networks. If these are not configured |
| 111 | # in localrc, tenant networks will be local to the host (with no |
| 112 | # remote connectivity), and no physical resources will be |
| 113 | # available for the allocation of provider networks. |
| 114 | |
| 115 | # To use GRE tunnels for tenant networks, set to True in |
| 116 | # localrc. GRE tunnels are only supported by the openvswitch |
| 117 | # plugin, and currently only on Ubuntu. |
| 118 | ENABLE_TENANT_TUNNELS=${ENABLE_TENANT_TUNNELS:-False} |
| 119 | |
| 120 | # If using GRE tunnels for tenant networks, specify the range of |
| 121 | # tunnel IDs from which tenant networks are allocated. Can be |
| 122 | # overriden in localrc in necesssary. |
| 123 | TENANT_TUNNEL_RANGES=${TENANT_TUNNEL_RANGE:-1:1000} |
| 124 | |
| 125 | # To use VLANs for tenant networks, set to True in localrc. VLANs |
| 126 | # are supported by the openvswitch and linuxbridge plugins, each |
| 127 | # requiring additional configuration described below. |
| 128 | ENABLE_TENANT_VLANS=${ENABLE_TENANT_VLANS:-False} |
| 129 | |
| 130 | # If using VLANs for tenant networks, set in localrc to specify |
| 131 | # the range of VLAN VIDs from which tenant networks are |
| 132 | # allocated. An external network switch must be configured to |
| 133 | # trunk these VLANs between hosts for multi-host connectivity. |
| 134 | # |
| 135 | # Example: ``TENANT_VLAN_RANGE=1000:1999`` |
| 136 | TENANT_VLAN_RANGE=${TENANT_VLAN_RANGE:-} |
| 137 | |
| 138 | # If using VLANs for tenant networks, or if using flat or VLAN |
| 139 | # provider networks, set in localrc to the name of the physical |
| 140 | # network, and also configure OVS_PHYSICAL_BRIDGE for the |
| 141 | # openvswitch agent or LB_PHYSICAL_INTERFACE for the linuxbridge |
| 142 | # agent, as described below. |
| 143 | # |
| 144 | # Example: ``PHYSICAL_NETWORK=default`` |
| 145 | PHYSICAL_NETWORK=${PHYSICAL_NETWORK:-} |
| 146 | |
| 147 | # With the openvswitch plugin, if using VLANs for tenant networks, |
| 148 | # or if using flat or VLAN provider networks, set in localrc to |
| 149 | # the name of the OVS bridge to use for the physical network. The |
| 150 | # bridge will be created if it does not already exist, but a |
| 151 | # physical interface must be manually added to the bridge as a |
| 152 | # port for external connectivity. |
| 153 | # |
| 154 | # Example: ``OVS_PHYSICAL_BRIDGE=br-eth1`` |
| 155 | OVS_PHYSICAL_BRIDGE=${OVS_PHYSICAL_BRIDGE:-} |
| 156 | |
| 157 | # With the linuxbridge plugin, if using VLANs for tenant networks, |
| 158 | # or if using flat or VLAN provider networks, set in localrc to |
| 159 | # the name of the network interface to use for the physical |
| 160 | # network. |
| 161 | # |
| 162 | # Example: ``LB_PHYSICAL_INTERFACE=eth1`` |
| 163 | LB_PHYSICAL_INTERFACE=${LB_PHYSICAL_INTERFACE:-} |
| 164 | |
| 165 | # With the openvswitch plugin, set to True in localrc to enable |
| 166 | # provider GRE tunnels when ``ENABLE_TENANT_TUNNELS`` is False. |
| 167 | # |
| 168 | # Example: ``OVS_ENABLE_TUNNELING=True`` |
| 169 | OVS_ENABLE_TUNNELING=${OVS_ENABLE_TUNNELING:-$ENABLE_TENANT_TUNNELS} |
| 170 | fi |
Dean Troyer | 60e9c0a | 2012-12-06 15:52:52 -0600 | [diff] [blame] | 171 | |
| 172 | # Entry Points |
| 173 | # ------------ |
| 174 | |
Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 175 | # configure_quantum() |
| 176 | # Set common config for all quantum server and agents. |
| 177 | function configure_quantum() { |
| 178 | _configure_quantum_common |
| 179 | _configure_quantum_rpc |
| 180 | |
| 181 | if is_service_enabled q-svc; then |
| 182 | _configure_quantum_service |
| 183 | fi |
| 184 | if is_service_enabled q-agt; then |
| 185 | _configure_quantum_plugin_agent |
| 186 | fi |
| 187 | if is_service_enabled q-dhcp; then |
| 188 | _configure_quantum_dhcp_agent |
| 189 | fi |
| 190 | if is_service_enabled q-l3; then |
| 191 | _configure_quantum_l3_agent |
| 192 | fi |
| 193 | if is_service_enabled q-meta; then |
| 194 | _configure_quantum_metadata_agent |
| 195 | fi |
| 196 | |
| 197 | _configure_quantum_debug_command |
| 198 | |
| 199 | _cleanup_quantum |
| 200 | } |
| 201 | |
| 202 | function create_nova_conf_quantum() { |
Devananda van der Veen | 9bc47db | 2012-12-12 16:52:55 -0800 | [diff] [blame^] | 203 | iniset $NOVA_CONF DEFAULT network_api_class "nova.network.quantumv2.api.API" |
| 204 | iniset $NOVA_CONF DEFAULT quantum_admin_username "$Q_ADMIN_USERNAME" |
| 205 | iniset $NOVA_CONF DEFAULT quantum_admin_password "$SERVICE_PASSWORD" |
| 206 | iniset $NOVA_CONF DEFAULT quantum_admin_auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_AUTH_PORT/v2.0" |
| 207 | iniset $NOVA_CONF DEFAULT quantum_auth_strategy "$Q_AUTH_STRATEGY" |
| 208 | iniset $NOVA_CONF DEFAULT quantum_admin_tenant_name "$SERVICE_TENANT_NAME" |
| 209 | iniset $NOVA_CONF DEFAULT quantum_url "http://$Q_HOST:$Q_PORT" |
Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 210 | |
| 211 | if [[ "$Q_PLUGIN" = "openvswitch" ]]; then |
| 212 | NOVA_VIF_DRIVER=${NOVA_VIF_DRIVER:-"nova.virt.libvirt.vif.LibvirtHybridOVSBridgeDriver"} |
| 213 | elif [[ "$Q_PLUGIN" = "linuxbridge" ]]; then |
| 214 | NOVA_VIF_DRIVER=${NOVA_VIF_DRIVER:-"nova.virt.libvirt.vif.QuantumLinuxBridgeVIFDriver"} |
| 215 | elif [[ "$Q_PLUGIN" = "ryu" ]]; then |
| 216 | NOVA_VIF_DRIVER=${NOVA_VIF_DRIVER:-"quantum.plugins.ryu.nova.vif.LibvirtOpenVswitchOFPRyuDriver"} |
Devananda van der Veen | 9bc47db | 2012-12-12 16:52:55 -0800 | [diff] [blame^] | 217 | iniset $NOVA_CONF DEFAULT libvirt_ovs_integration_bridge "$OVS_BRIDGE" |
| 218 | iniset $NOVA_CONF DEFAULT linuxnet_ovs_ryu_api_host "$RYU_API_HOST:$RYU_API_PORT" |
| 219 | iniset $NOVA_CONF DEFAULT libvirt_ovs_ryu_api_host "$RYU_API_HOST:$RYU_API_PORT" |
Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 220 | fi |
Devananda van der Veen | 9bc47db | 2012-12-12 16:52:55 -0800 | [diff] [blame^] | 221 | iniset $NOVA_CONF DEFAULT libvirt_vif_driver "$NOVA_VIF_DRIVER" |
| 222 | iniset $NOVA_CONF DEFAULT linuxnet_interface_driver "$LINUXNET_VIF_DRIVER" |
Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 223 | if is_service_enabled q-meta; then |
Devananda van der Veen | 9bc47db | 2012-12-12 16:52:55 -0800 | [diff] [blame^] | 224 | iniset $NOVA_CONF DEFAULT service_quantum_metadata_proxy "True" |
Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 225 | fi |
| 226 | } |
| 227 | |
| 228 | # create_quantum_accounts() - Set up common required quantum accounts |
| 229 | |
| 230 | # Tenant User Roles |
| 231 | # ------------------------------------------------------------------ |
| 232 | # service quantum admin # if enabled |
| 233 | |
| 234 | # Migrated from keystone_data.sh |
| 235 | function create_quantum_accounts() { |
| 236 | |
| 237 | SERVICE_TENANT=$(keystone tenant-list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }") |
| 238 | ADMIN_ROLE=$(keystone role-list | awk "/ admin / { print \$2 }") |
| 239 | |
| 240 | if [[ "$ENABLED_SERVICES" =~ "q-svc" ]]; then |
| 241 | QUANTUM_USER=$(keystone user-create \ |
| 242 | --name=quantum \ |
| 243 | --pass="$SERVICE_PASSWORD" \ |
| 244 | --tenant_id $SERVICE_TENANT \ |
| 245 | --email=quantum@example.com \ |
| 246 | | grep " id " | get_field 2) |
| 247 | keystone user-role-add \ |
| 248 | --tenant_id $SERVICE_TENANT \ |
| 249 | --user_id $QUANTUM_USER \ |
| 250 | --role_id $ADMIN_ROLE |
| 251 | if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then |
| 252 | QUANTUM_SERVICE=$(keystone service-create \ |
| 253 | --name=quantum \ |
| 254 | --type=network \ |
| 255 | --description="Quantum Service" \ |
| 256 | | grep " id " | get_field 2) |
| 257 | keystone endpoint-create \ |
| 258 | --region RegionOne \ |
| 259 | --service_id $QUANTUM_SERVICE \ |
| 260 | --publicurl "http://$SERVICE_HOST:9696/" \ |
| 261 | --adminurl "http://$SERVICE_HOST:9696/" \ |
| 262 | --internalurl "http://$SERVICE_HOST:9696/" |
| 263 | fi |
| 264 | fi |
| 265 | } |
| 266 | |
| 267 | function create_quantum_initial_network() { |
| 268 | TENANT_ID=$(keystone tenant-list | grep " demo " | get_field 1) |
| 269 | |
| 270 | # Create a small network |
| 271 | # Since quantum command is executed in admin context at this point, |
| 272 | # ``--tenant_id`` needs to be specified. |
| 273 | NET_ID=$(quantum net-create --tenant_id $TENANT_ID "$PRIVATE_NETWORK_NAME" | grep ' id ' | get_field 2) |
| 274 | SUBNET_ID=$(quantum subnet-create --tenant_id $TENANT_ID --ip_version 4 --gateway $NETWORK_GATEWAY $NET_ID $FIXED_RANGE | grep ' id ' | get_field 2) |
| 275 | |
| 276 | if is_service_enabled q-l3; then |
| 277 | # Create a router, and add the private subnet as one of its interfaces |
| 278 | ROUTER_ID=$(quantum router-create --tenant_id $TENANT_ID router1 | grep ' id ' | get_field 2) |
| 279 | quantum router-interface-add $ROUTER_ID $SUBNET_ID |
| 280 | # Create an external network, and a subnet. Configure the external network as router gw |
| 281 | EXT_NET_ID=$(quantum net-create "$PUBLIC_NETWORK_NAME" -- --router:external=True | grep ' id ' | get_field 2) |
| 282 | EXT_GW_IP=$(quantum subnet-create --ip_version 4 $EXT_NET_ID $FLOATING_RANGE -- --enable_dhcp=False | grep 'gateway_ip' | get_field 2) |
| 283 | quantum router-gateway-set $ROUTER_ID $EXT_NET_ID |
| 284 | |
| 285 | if is_quantum_ovs_base_plugin "$Q_PLUGIN" && [[ "$Q_USE_NAMESPACE" = "True" ]]; then |
| 286 | CIDR_LEN=${FLOATING_RANGE#*/} |
| 287 | sudo ip addr add $EXT_GW_IP/$CIDR_LEN dev $PUBLIC_BRIDGE |
| 288 | sudo ip link set $PUBLIC_BRIDGE up |
| 289 | ROUTER_GW_IP=`quantum port-list -c fixed_ips -c device_owner | grep router_gateway | awk -F '"' '{ print $8; }'` |
| 290 | sudo route add -net $FIXED_RANGE gw $ROUTER_GW_IP |
| 291 | fi |
| 292 | if [[ "$Q_USE_NAMESPACE" == "False" ]]; then |
| 293 | # Explicitly set router id in l3 agent configuration |
| 294 | iniset $Q_L3_CONF_FILE DEFAULT router_id $ROUTER_ID |
| 295 | fi |
| 296 | fi |
| 297 | } |
| 298 | |
| 299 | # init_quantum() - Initialize databases, etc. |
| 300 | function init_quantum() { |
| 301 | : |
| 302 | } |
| 303 | |
| 304 | # install_quantum() - Collect source and prepare |
| 305 | function install_quantum() { |
| 306 | git_clone $QUANTUM_REPO $QUANTUM_DIR $QUANTUM_BRANCH |
| 307 | } |
| 308 | |
| 309 | # install_quantumclient() - Collect source and prepare |
| 310 | function install_quantumclient() { |
| 311 | git_clone $QUANTUMCLIENT_REPO $QUANTUMCLIENT_DIR $QUANTUMCLIENT_BRANCH |
| 312 | } |
| 313 | |
| 314 | # install_quantum_agent_packages() - Collect source and prepare |
| 315 | function install_quantum_agent_packages() { |
| 316 | if is_quantum_ovs_base_plugin "$Q_PLUGIN"; then |
| 317 | # Install deps |
| 318 | # FIXME add to ``files/apts/quantum``, but don't install if not needed! |
| 319 | if is_ubuntu; then |
| 320 | kernel_version=`cat /proc/version | cut -d " " -f3` |
| 321 | install_package make fakeroot dkms openvswitch-switch openvswitch-datapath-dkms linux-headers-$kernel_version |
| 322 | else |
| 323 | ### FIXME(dtroyer): Find RPMs for OpenVSwitch |
| 324 | echo "OpenVSwitch packages need to be located" |
| 325 | # Fedora does not started OVS by default |
| 326 | restart_service openvswitch |
| 327 | fi |
| 328 | elif [[ "$Q_PLUGIN" = "linuxbridge" ]]; then |
| 329 | install_package bridge-utils |
| 330 | fi |
| 331 | } |
| 332 | |
| 333 | function is_quantum_ovs_base_plugin() { |
| 334 | local plugin=$1 |
| 335 | if [[ ",openvswitch,ryu," =~ ,${plugin}, ]]; then |
| 336 | return 0 |
| 337 | fi |
| 338 | return 1 |
| 339 | } |
| 340 | |
| 341 | function setup_quantum() { |
| 342 | setup_develop $QUANTUM_DIR |
| 343 | } |
| 344 | |
| 345 | function setup_quantumclient() { |
| 346 | setup_develop $QUANTUMCLIENT_DIR |
| 347 | } |
| 348 | |
| 349 | # Start running processes, including screen |
| 350 | function start_quantum_service_and_check() { |
| 351 | # Start the Quantum service |
| 352 | screen_it q-svc "cd $QUANTUM_DIR && python $QUANTUM_DIR/bin/quantum-server --config-file $QUANTUM_CONF --config-file /$Q_PLUGIN_CONF_FILE" |
| 353 | echo "Waiting for Quantum to start..." |
| 354 | if ! timeout $SERVICE_TIMEOUT sh -c "while ! http_proxy= wget -q -O- http://127.0.0.1:9696; do sleep 1; done"; then |
| 355 | echo "Quantum did not start" |
| 356 | exit 1 |
| 357 | fi |
| 358 | } |
| 359 | |
| 360 | # Start running processes, including screen |
| 361 | function start_quantum_agents() { |
| 362 | # Start up the quantum agents if enabled |
| 363 | screen_it q-agt "python $AGENT_BINARY --config-file $QUANTUM_CONF --config-file /$Q_PLUGIN_CONF_FILE" |
| 364 | screen_it q-dhcp "python $AGENT_DHCP_BINARY --config-file $QUANTUM_CONF --config-file=$Q_DHCP_CONF_FILE" |
| 365 | screen_it q-meta "python $AGENT_META_BINARY --config-file $QUANTUM_CONF --config-file=$Q_META_CONF_FILE" |
| 366 | screen_it q-l3 "python $AGENT_L3_BINARY --config-file $QUANTUM_CONF --config-file=$Q_L3_CONF_FILE" |
| 367 | } |
| 368 | |
| 369 | # stop_quantum() - Stop running processes (non-screen) |
| 370 | function stop_quantum() { |
| 371 | if is_service_enabled q-dhcp; then |
| 372 | pid=$(ps aux | awk '/[d]nsmasq.+interface=(tap|ns-)/ { print $2 }') |
| 373 | [ ! -z "$pid" ] && sudo kill -9 $pid |
| 374 | fi |
| 375 | } |
| 376 | |
| 377 | # _cleanup_quantum() - Remove residual data files, anything left over from previous |
| 378 | # runs that a clean run would need to clean up |
| 379 | function _cleanup_quantum() { |
| 380 | : |
| 381 | } |
| 382 | |
| 383 | # _configure_quantum_common() |
| 384 | # Set common config for all quantum server and agents. |
| 385 | # This MUST be called before other _configure_quantum_* functions. |
| 386 | function _configure_quantum_common() { |
| 387 | # Put config files in ``QUANTUM_CONF_DIR`` for everyone to find |
| 388 | if [[ ! -d $QUANTUM_CONF_DIR ]]; then |
| 389 | sudo mkdir -p $QUANTUM_CONF_DIR |
| 390 | fi |
| 391 | sudo chown `whoami` $QUANTUM_CONF_DIR |
| 392 | |
| 393 | cp $QUANTUM_DIR/etc/quantum.conf $QUANTUM_CONF |
| 394 | |
| 395 | if [[ "$Q_PLUGIN" = "openvswitch" ]]; then |
| 396 | Q_PLUGIN_CONF_PATH=etc/quantum/plugins/openvswitch |
| 397 | Q_PLUGIN_CONF_FILENAME=ovs_quantum_plugin.ini |
| 398 | Q_DB_NAME="ovs_quantum" |
| 399 | Q_PLUGIN_CLASS="quantum.plugins.openvswitch.ovs_quantum_plugin.OVSQuantumPluginV2" |
| 400 | elif [[ "$Q_PLUGIN" = "linuxbridge" ]]; then |
| 401 | Q_PLUGIN_CONF_PATH=etc/quantum/plugins/linuxbridge |
| 402 | Q_PLUGIN_CONF_FILENAME=linuxbridge_conf.ini |
| 403 | Q_DB_NAME="quantum_linux_bridge" |
| 404 | Q_PLUGIN_CLASS="quantum.plugins.linuxbridge.lb_quantum_plugin.LinuxBridgePluginV2" |
| 405 | elif [[ "$Q_PLUGIN" = "ryu" ]]; then |
| 406 | Q_PLUGIN_CONF_PATH=etc/quantum/plugins/ryu |
| 407 | Q_PLUGIN_CONF_FILENAME=ryu.ini |
| 408 | Q_DB_NAME="ovs_quantum" |
| 409 | Q_PLUGIN_CLASS="quantum.plugins.ryu.ryu_quantum_plugin.RyuQuantumPluginV2" |
| 410 | fi |
| 411 | |
| 412 | if [[ $Q_PLUGIN_CONF_PATH == '' || $Q_PLUGIN_CONF_FILENAME == '' || $Q_PLUGIN_CLASS == '' ]]; then |
| 413 | echo "Quantum plugin not set.. exiting" |
| 414 | exit 1 |
| 415 | fi |
| 416 | |
| 417 | # If needed, move config file from ``$QUANTUM_DIR/etc/quantum`` to ``QUANTUM_CONF_DIR`` |
| 418 | mkdir -p /$Q_PLUGIN_CONF_PATH |
| 419 | Q_PLUGIN_CONF_FILE=$Q_PLUGIN_CONF_PATH/$Q_PLUGIN_CONF_FILENAME |
| 420 | cp $QUANTUM_DIR/$Q_PLUGIN_CONF_FILE /$Q_PLUGIN_CONF_FILE |
| 421 | |
| 422 | database_connection_url dburl $Q_DB_NAME |
| 423 | iniset /$Q_PLUGIN_CONF_FILE DATABASE sql_connection $dburl |
| 424 | unset dburl |
| 425 | |
| 426 | _quantum_setup_rootwrap |
| 427 | } |
| 428 | |
| 429 | function _configure_quantum_debug_command() { |
| 430 | if [[ "$Q_USE_DEBUG_COMMAND" != "True" ]]; then |
| 431 | return |
| 432 | fi |
| 433 | |
| 434 | cp $QUANTUM_DIR/etc/l3_agent.ini $QUANTUM_TEST_CONFIG_FILE |
| 435 | |
| 436 | iniset $QUANTUM_TEST_CONFIG_FILE DEFAULT verbose False |
| 437 | iniset $QUANTUM_TEST_CONFIG_FILE DEFAULT debug False |
| 438 | iniset $QUANTUM_TEST_CONFIG_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE |
| 439 | iniset $QUANTUM_TEST_CONFIG_FILE DEFAULT root_helper "$Q_RR_COMMAND" |
| 440 | |
| 441 | _quantum_setup_keystone $QUANTUM_TEST_CONFIG_FILE DEFAULT set_auth_url |
| 442 | _quantum_setup_interface_driver $QUANTUM_TEST_CONFIG_FILE |
| 443 | |
| 444 | if is_quantum_ovs_base_plugin "$Q_PLUGIN"; then |
| 445 | iniset $QUANTUM_TEST_CONFIG_FILE DEFAULT external_network_bridge $PUBLIC_BRIDGE |
| 446 | elif [[ "$Q_PLUGIN" = "linuxbridge" ]]; then |
| 447 | iniset $QUANTUM_TEST_CONFIG_FILE DEFAULT external_network_bridge '' |
| 448 | fi |
| 449 | |
| 450 | if [[ "$Q_PLUGIN" = "ryu" ]]; then |
| 451 | iniset $QUANTUM_TEST_CONFIG_FILE DEFAULT ryu_api_host $RYU_API_HOST:$RYU_API_PORT |
| 452 | fi |
| 453 | } |
| 454 | |
| 455 | function _configure_quantum_dhcp_agent() { |
| 456 | AGENT_DHCP_BINARY="$QUANTUM_DIR/bin/quantum-dhcp-agent" |
| 457 | Q_DHCP_CONF_FILE=$QUANTUM_CONF_DIR/dhcp_agent.ini |
| 458 | |
| 459 | cp $QUANTUM_DIR/etc/dhcp_agent.ini $Q_DHCP_CONF_FILE |
| 460 | |
| 461 | iniset $Q_DHCP_CONF_FILE DEFAULT verbose True |
| 462 | iniset $Q_DHCP_CONF_FILE DEFAULT debug True |
| 463 | iniset $Q_DHCP_CONF_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE |
| 464 | iniset $Q_DHCP_CONF_FILE DEFAULT state_path $DATA_DIR/quantum |
| 465 | iniset $Q_DHCP_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND" |
| 466 | |
| 467 | _quantum_setup_keystone $Q_DHCP_CONF_FILE DEFAULT set_auth_url |
| 468 | _quantum_setup_interface_driver $Q_DHCP_CONF_FILE |
| 469 | |
| 470 | if [[ "$Q_PLUGIN" = "ryu" ]]; then |
| 471 | iniset $Q_DHCP_CONF_FILE DEFAULT ryu_api_host $RYU_API_HOST:$RYU_API_PORT |
| 472 | fi |
| 473 | } |
| 474 | |
| 475 | function _configure_quantum_l3_agent() { |
| 476 | AGENT_L3_BINARY="$QUANTUM_DIR/bin/quantum-l3-agent" |
| 477 | PUBLIC_BRIDGE=${PUBLIC_BRIDGE:-br-ex} |
| 478 | Q_L3_CONF_FILE=$QUANTUM_CONF_DIR/l3_agent.ini |
| 479 | |
| 480 | cp $QUANTUM_DIR/etc/l3_agent.ini $Q_L3_CONF_FILE |
| 481 | |
| 482 | iniset $Q_L3_CONF_FILE DEFAULT verbose True |
| 483 | iniset $Q_L3_CONF_FILE DEFAULT debug True |
| 484 | iniset $Q_L3_CONF_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE |
| 485 | iniset $Q_L3_CONF_FILE DEFAULT state_path $DATA_DIR/quantum |
| 486 | iniset $Q_L3_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND" |
| 487 | |
| 488 | _quantum_setup_keystone $Q_L3_CONF_FILE DEFAULT set_auth_url |
| 489 | _quantum_setup_interface_driver $Q_L3_CONF_FILE |
| 490 | |
| 491 | if is_quantum_ovs_base_plugin "$Q_PLUGIN"; then |
| 492 | iniset $Q_L3_CONF_FILE DEFAULT external_network_bridge $PUBLIC_BRIDGE |
| 493 | _quantum_setup_external_bridge $PUBLIC_BRIDGE |
| 494 | elif [[ "$Q_PLUGIN" = "linuxbridge" ]]; then |
| 495 | iniset $Q_L3_CONF_FILE DEFAULT external_network_bridge '' |
| 496 | fi |
| 497 | |
| 498 | if [[ "$Q_PLUGIN" = "ryu" ]]; then |
| 499 | iniset $Q_L3_CONF_FILE DEFAULT ryu_api_host $RYU_API_HOST:$RYU_API_PORT |
| 500 | fi |
| 501 | } |
| 502 | |
| 503 | function _configure_quantum_metadata_agent() { |
| 504 | AGENT_META_BINARY="$QUANTUM_DIR/bin/quantum-metadata-agent" |
| 505 | Q_META_CONF_FILE=$QUANTUM_CONF_DIR/metadata_agent.ini |
| 506 | |
| 507 | cp $QUANTUM_DIR/etc/metadata_agent.ini $Q_META_CONF_FILE |
| 508 | |
| 509 | iniset $Q_META_CONF_FILE DEFAULT verbose True |
| 510 | iniset $Q_META_CONF_FILE DEFAULT debug True |
| 511 | iniset $Q_META_CONF_FILE DEFAULT state_path $DATA_DIR/quantum |
| 512 | iniset $Q_META_CONF_FILE DEFAULT nova_metadata_ip $Q_META_DATA_IP |
| 513 | iniset $Q_META_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND" |
| 514 | |
| 515 | _quantum_setup_keystone $Q_META_CONF_FILE DEFAULT set_auth_url |
| 516 | } |
| 517 | |
| 518 | # _configure_quantum_plugin_agent() - Set config files for quantum plugin agent |
| 519 | # It is called when q-agt is enabled. |
| 520 | function _configure_quantum_plugin_agent() { |
| 521 | # Configure agent for plugin |
| 522 | if [[ "$Q_PLUGIN" = "openvswitch" ]]; then |
| 523 | _configure_quantum_plugin_agent_openvswitch |
| 524 | elif [[ "$Q_PLUGIN" = "linuxbridge" ]]; then |
| 525 | _configure_quantum_plugin_agent_linuxbridge |
| 526 | elif [[ "$Q_PLUGIN" = "ryu" ]]; then |
| 527 | _configure_quantum_plugin_agent_ryu |
| 528 | fi |
| 529 | |
| 530 | iniset /$Q_PLUGIN_CONF_FILE AGENT root_helper "$Q_RR_COMMAND" |
| 531 | } |
| 532 | |
| 533 | function _configure_quantum_plugin_agent_linuxbridge() { |
| 534 | # Setup physical network interface mappings. Override |
| 535 | # ``LB_VLAN_RANGES`` and ``LB_INTERFACE_MAPPINGS`` in ``localrc`` for more |
| 536 | # complex physical network configurations. |
| 537 | if [[ "$LB_INTERFACE_MAPPINGS" = "" ]] && [[ "$PHYSICAL_NETWORK" != "" ]] && [[ "$LB_PHYSICAL_INTERFACE" != "" ]]; then |
| 538 | LB_INTERFACE_MAPPINGS=$PHYSICAL_NETWORK:$LB_PHYSICAL_INTERFACE |
| 539 | fi |
| 540 | if [[ "$LB_INTERFACE_MAPPINGS" != "" ]]; then |
| 541 | iniset /$Q_PLUGIN_CONF_FILE LINUX_BRIDGE physical_interface_mappings $LB_INTERFACE_MAPPINGS |
| 542 | fi |
| 543 | AGENT_BINARY="$QUANTUM_DIR/bin/quantum-linuxbridge-agent" |
| 544 | } |
| 545 | |
| 546 | function _configure_quantum_plugin_agent_openvswitch() { |
| 547 | # Setup integration bridge |
| 548 | OVS_BRIDGE=${OVS_BRIDGE:-br-int} |
| 549 | _quantum_setup_ovs_bridge $OVS_BRIDGE |
| 550 | |
| 551 | # Setup agent for tunneling |
| 552 | if [[ "$OVS_ENABLE_TUNNELING" = "True" ]]; then |
| 553 | # Verify tunnels are supported |
| 554 | # REVISIT - also check kernel module support for GRE and patch ports |
| 555 | OVS_VERSION=`ovs-vsctl --version | head -n 1 | awk '{print $4;}'` |
| 556 | if [ $OVS_VERSION \< "1.4" ] && ! is_service_enabled q-svc ; then |
| 557 | echo "You are running OVS version $OVS_VERSION." |
| 558 | echo "OVS 1.4+ is required for tunneling between multiple hosts." |
| 559 | exit 1 |
| 560 | fi |
| 561 | iniset /$Q_PLUGIN_CONF_FILE OVS enable_tunneling True |
| 562 | iniset /$Q_PLUGIN_CONF_FILE OVS local_ip $HOST_IP |
| 563 | fi |
| 564 | |
| 565 | # Setup physical network bridge mappings. Override |
| 566 | # ``OVS_VLAN_RANGES`` and ``OVS_BRIDGE_MAPPINGS`` in ``localrc`` for more |
| 567 | # complex physical network configurations. |
| 568 | if [[ "$OVS_BRIDGE_MAPPINGS" = "" ]] && [[ "$PHYSICAL_NETWORK" != "" ]] && [[ "$OVS_PHYSICAL_BRIDGE" != "" ]]; then |
| 569 | OVS_BRIDGE_MAPPINGS=$PHYSICAL_NETWORK:$OVS_PHYSICAL_BRIDGE |
| 570 | |
| 571 | # Configure bridge manually with physical interface as port for multi-node |
| 572 | sudo ovs-vsctl --no-wait -- --may-exist add-br $OVS_PHYSICAL_BRIDGE |
| 573 | fi |
| 574 | if [[ "$OVS_BRIDGE_MAPPINGS" != "" ]]; then |
| 575 | iniset /$Q_PLUGIN_CONF_FILE OVS bridge_mappings $OVS_BRIDGE_MAPPINGS |
| 576 | fi |
| 577 | AGENT_BINARY="$QUANTUM_DIR/bin/quantum-openvswitch-agent" |
| 578 | } |
| 579 | |
| 580 | function _configure_quantum_plugin_agent_ryu() { |
| 581 | # Set up integration bridge |
| 582 | OVS_BRIDGE=${OVS_BRIDGE:-br-int} |
| 583 | _quantum_setup_ovs_bridge $OVS_BRIDGE |
| 584 | if [ -n "$RYU_INTERNAL_INTERFACE" ]; then |
| 585 | sudo ovs-vsctl --no-wait -- --may-exist add-port $OVS_BRIDGE $RYU_INTERNAL_INTERFACE |
| 586 | fi |
| 587 | AGENT_BINARY="$QUANTUM_DIR/quantum/plugins/ryu/agent/ryu_quantum_agent.py" |
| 588 | } |
| 589 | |
| 590 | # Quantum RPC support - must be updated prior to starting any of the services |
| 591 | function _configure_quantum_rpc() { |
| 592 | iniset $QUANTUM_CONF DEFAULT control_exchange quantum |
| 593 | if is_service_enabled qpid ; then |
| 594 | iniset $QUANTUM_CONF DEFAULT rpc_backend quantum.openstack.common.rpc.impl_qpid |
| 595 | elif is_service_enabled zeromq; then |
| 596 | iniset $QUANTUM_CONF DEFAULT rpc_backend quantum.openstack.common.rpc.impl_zmq |
| 597 | elif [ -n "$RABBIT_HOST" ] && [ -n "$RABBIT_PASSWORD" ]; then |
| 598 | iniset $QUANTUM_CONF DEFAULT rabbit_host $RABBIT_HOST |
| 599 | iniset $QUANTUM_CONF DEFAULT rabbit_password $RABBIT_PASSWORD |
| 600 | fi |
| 601 | } |
| 602 | |
| 603 | # _configure_quantum_service() - Set config files for quantum service |
| 604 | # It is called when q-svc is enabled. |
| 605 | function _configure_quantum_service() { |
| 606 | Q_API_PASTE_FILE=$QUANTUM_CONF_DIR/api-paste.ini |
| 607 | Q_POLICY_FILE=$QUANTUM_CONF_DIR/policy.json |
| 608 | |
| 609 | cp $QUANTUM_DIR/etc/api-paste.ini $Q_API_PASTE_FILE |
| 610 | cp $QUANTUM_DIR/etc/policy.json $Q_POLICY_FILE |
| 611 | |
| 612 | if is_service_enabled $DATABASE_BACKENDS; then |
| 613 | recreate_database $Q_DB_NAME utf8 |
| 614 | else |
| 615 | echo "A database must be enabled in order to use the $Q_PLUGIN Quantum plugin." |
| 616 | exit 1 |
| 617 | fi |
| 618 | |
| 619 | # Update either configuration file with plugin |
| 620 | iniset $QUANTUM_CONF DEFAULT core_plugin $Q_PLUGIN_CLASS |
| 621 | |
| 622 | iniset $QUANTUM_CONF DEFAULT verbose True |
| 623 | iniset $QUANTUM_CONF DEFAULT debug True |
| 624 | iniset $QUANTUM_CONF DEFAULT allow_overlapping_ips $Q_ALLOW_OVERLAPPING_IP |
| 625 | |
| 626 | iniset $QUANTUM_CONF DEFAULT auth_strategy $Q_AUTH_STRATEGY |
| 627 | _quantum_setup_keystone $Q_API_PASTE_FILE filter:authtoken |
| 628 | |
| 629 | # Configure plugin |
| 630 | if [[ "$Q_PLUGIN" = "openvswitch" ]]; then |
| 631 | if [[ "$ENABLE_TENANT_TUNNELS" = "True" ]]; then |
| 632 | iniset /$Q_PLUGIN_CONF_FILE OVS tenant_network_type gre |
| 633 | iniset /$Q_PLUGIN_CONF_FILE OVS tunnel_id_ranges $TENANT_TUNNEL_RANGES |
| 634 | elif [[ "$ENABLE_TENANT_VLANS" = "True" ]]; then |
| 635 | iniset /$Q_PLUGIN_CONF_FILE OVS tenant_network_type vlan |
| 636 | else |
| 637 | echo "WARNING - The openvswitch plugin is using local tenant networks, with no connectivity between hosts." |
| 638 | fi |
| 639 | |
| 640 | # Override ``OVS_VLAN_RANGES`` and ``OVS_BRIDGE_MAPPINGS`` in ``localrc`` |
| 641 | # for more complex physical network configurations. |
| 642 | if [[ "$OVS_VLAN_RANGES" = "" ]] && [[ "$PHYSICAL_NETWORK" != "" ]]; then |
| 643 | OVS_VLAN_RANGES=$PHYSICAL_NETWORK |
| 644 | if [[ "$TENANT_VLAN_RANGE" != "" ]]; then |
| 645 | OVS_VLAN_RANGES=$OVS_VLAN_RANGES:$TENANT_VLAN_RANGE |
| 646 | fi |
| 647 | fi |
| 648 | if [[ "$OVS_VLAN_RANGES" != "" ]]; then |
| 649 | iniset /$Q_PLUGIN_CONF_FILE OVS network_vlan_ranges $OVS_VLAN_RANGES |
| 650 | fi |
| 651 | |
| 652 | # Enable tunnel networks if selected |
| 653 | if [[ $OVS_ENABLE_TUNNELING = "True" ]]; then |
| 654 | iniset /$Q_PLUGIN_CONF_FILE OVS enable_tunneling True |
| 655 | fi |
| 656 | elif [[ "$Q_PLUGIN" = "linuxbridge" ]]; then |
| 657 | if [[ "$ENABLE_TENANT_VLANS" = "True" ]]; then |
| 658 | iniset /$Q_PLUGIN_CONF_FILE VLANS tenant_network_type vlan |
| 659 | else |
| 660 | echo "WARNING - The linuxbridge plugin is using local tenant networks, with no connectivity between hosts." |
| 661 | fi |
| 662 | |
| 663 | # Override ``LB_VLAN_RANGES`` and ``LB_INTERFACE_MAPPINGS`` in ``localrc`` |
| 664 | # for more complex physical network configurations. |
| 665 | if [[ "$LB_VLAN_RANGES" = "" ]] && [[ "$PHYSICAL_NETWORK" != "" ]]; then |
| 666 | LB_VLAN_RANGES=$PHYSICAL_NETWORK |
| 667 | if [[ "$TENANT_VLAN_RANGE" != "" ]]; then |
| 668 | LB_VLAN_RANGES=$LB_VLAN_RANGES:$TENANT_VLAN_RANGE |
| 669 | fi |
| 670 | fi |
| 671 | if [[ "$LB_VLAN_RANGES" != "" ]]; then |
| 672 | iniset /$Q_PLUGIN_CONF_FILE VLANS network_vlan_ranges $LB_VLAN_RANGES |
| 673 | fi |
| 674 | elif [[ "$Q_PLUGIN" = "ryu" ]]; then |
| 675 | iniset /$Q_PLUGIN_CONF_FILE OVS openflow_controller $RYU_OFP_HOST:$RYU_OFP_PORT |
| 676 | iniset /$Q_PLUGIN_CONF_FILE OVS openflow_rest_api $RYU_API_HOST:$RYU_API_PORT |
| 677 | fi |
| 678 | } |
| 679 | |
| 680 | # Utility Functions |
| 681 | #------------------ |
| 682 | |
| 683 | # _quantum_setup_rootwrap() - configure Quantum's rootwrap |
| 684 | function _quantum_setup_rootwrap() { |
Nachi Ueno | eb1aa3d | 2012-12-06 11:55:29 -0800 | [diff] [blame] | 685 | if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then |
| 686 | return |
| 687 | fi |
| 688 | # Deploy new rootwrap filters files (owned by root). |
| 689 | # Wipe any existing rootwrap.d files first |
Dean Troyer | 60e9c0a | 2012-12-06 15:52:52 -0600 | [diff] [blame] | 690 | Q_CONF_ROOTWRAP_D=$QUANTUM_CONF_DIR/rootwrap.d |
Nachi Ueno | eb1aa3d | 2012-12-06 11:55:29 -0800 | [diff] [blame] | 691 | if [[ -d $Q_CONF_ROOTWRAP_D ]]; then |
| 692 | sudo rm -rf $Q_CONF_ROOTWRAP_D |
| 693 | fi |
Dean Troyer | 60e9c0a | 2012-12-06 15:52:52 -0600 | [diff] [blame] | 694 | # Deploy filters to $QUANTUM_CONF_DIR/rootwrap.d |
Nachi Ueno | eb1aa3d | 2012-12-06 11:55:29 -0800 | [diff] [blame] | 695 | mkdir -p -m 755 $Q_CONF_ROOTWRAP_D |
| 696 | cp -pr $QUANTUM_DIR/etc/quantum/rootwrap.d/* $Q_CONF_ROOTWRAP_D/ |
| 697 | sudo chown -R root:root $Q_CONF_ROOTWRAP_D |
| 698 | sudo chmod 644 $Q_CONF_ROOTWRAP_D/* |
Dean Troyer | 60e9c0a | 2012-12-06 15:52:52 -0600 | [diff] [blame] | 699 | # Set up rootwrap.conf, pointing to $QUANTUM_CONF_DIR/rootwrap.d |
Nachi Ueno | eb1aa3d | 2012-12-06 11:55:29 -0800 | [diff] [blame] | 700 | sudo cp -p $QUANTUM_DIR/etc/rootwrap.conf $Q_RR_CONF_FILE |
| 701 | sudo sed -e "s:^filters_path=.*$:filters_path=$Q_CONF_ROOTWRAP_D:" -i $Q_RR_CONF_FILE |
| 702 | sudo chown root:root $Q_RR_CONF_FILE |
| 703 | sudo chmod 0644 $Q_RR_CONF_FILE |
| 704 | # Specify rootwrap.conf as first parameter to quantum-rootwrap |
| 705 | ROOTWRAP_SUDOER_CMD="$QUANTUM_ROOTWRAP $Q_RR_CONF_FILE *" |
| 706 | |
| 707 | # Set up the rootwrap sudoers for quantum |
| 708 | TEMPFILE=`mktemp` |
| 709 | echo "$USER ALL=(root) NOPASSWD: $ROOTWRAP_SUDOER_CMD" >$TEMPFILE |
| 710 | chmod 0440 $TEMPFILE |
| 711 | sudo chown root:root $TEMPFILE |
| 712 | sudo mv $TEMPFILE /etc/sudoers.d/quantum-rootwrap |
| 713 | } |
| 714 | |
Salvatore Orlando | d6767d0 | 2012-08-31 04:55:20 -0700 | [diff] [blame] | 715 | # Configures keystone integration for quantum service and agents |
Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 716 | function _quantum_setup_keystone() { |
Salvatore Orlando | d6767d0 | 2012-08-31 04:55:20 -0700 | [diff] [blame] | 717 | local conf_file=$1 |
| 718 | local section=$2 |
| 719 | local use_auth_url=$3 |
| 720 | if [[ -n $use_auth_url ]]; then |
| 721 | iniset $conf_file $section auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_AUTH_HOST:$KEYSTONE_AUTH_PORT/v2.0" |
| 722 | else |
| 723 | iniset $conf_file $section auth_host $KEYSTONE_SERVICE_HOST |
| 724 | iniset $conf_file $section auth_port $KEYSTONE_AUTH_PORT |
| 725 | iniset $conf_file $section auth_protocol $KEYSTONE_SERVICE_PROTOCOL |
| 726 | fi |
| 727 | iniset $conf_file $section admin_tenant_name $SERVICE_TENANT_NAME |
| 728 | iniset $conf_file $section admin_user $Q_ADMIN_USERNAME |
| 729 | iniset $conf_file $section admin_password $SERVICE_PASSWORD |
Akihiro MOTOKI | 5e3deb6 | 2012-12-11 17:09:02 +0900 | [diff] [blame] | 730 | iniset $conf_file $section signing_dir $QUANTUM_AUTH_CACHE_DIR |
| 731 | # Create cache dir |
| 732 | sudo mkdir -p $QUANTUM_AUTH_CACHE_DIR |
| 733 | sudo chown `whoami` $QUANTUM_AUTH_CACHE_DIR |
Vishvananda Ishaya | 23431f3 | 2012-12-12 15:57:33 -0800 | [diff] [blame] | 734 | rm -f $QUANTUM_AUTH_CACHE_DIR/* |
Salvatore Orlando | d6767d0 | 2012-08-31 04:55:20 -0700 | [diff] [blame] | 735 | } |
| 736 | |
Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 737 | function _quantum_setup_ovs_bridge() { |
Salvatore Orlando | d6767d0 | 2012-08-31 04:55:20 -0700 | [diff] [blame] | 738 | local bridge=$1 |
Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 739 | quantum-ovs-cleanup --ovs_integration_bridge $bridge |
| 740 | sudo ovs-vsctl --no-wait -- --may-exist add-br $bridge |
Salvatore Orlando | d6767d0 | 2012-08-31 04:55:20 -0700 | [diff] [blame] | 741 | sudo ovs-vsctl --no-wait br-set-external-id $bridge bridge-id $bridge |
| 742 | } |
| 743 | |
Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 744 | function _quantum_setup_interface_driver() { |
| 745 | local conf_file=$1 |
| 746 | if [[ "$Q_PLUGIN" == "openvswitch" ]]; then |
| 747 | iniset $conf_file DEFAULT interface_driver quantum.agent.linux.interface.OVSInterfaceDriver |
| 748 | elif [[ "$Q_PLUGIN" = "linuxbridge" ]]; then |
| 749 | iniset $conf_file DEFAULT interface_driver quantum.agent.linux.interface.BridgeInterfaceDriver |
| 750 | elif [[ "$Q_PLUGIN" = "ryu" ]]; then |
| 751 | iniset $conf_file DEFAULT interface_driver quantum.agent.linux.interface.RyuInterfaceDriver |
| 752 | fi |
| 753 | } |
| 754 | |
| 755 | function _quantum_setup_external_bridge() { |
Yoshihiro Kaneko | 602cf9b | 2012-07-23 06:27:36 +0000 | [diff] [blame] | 756 | local bridge=$1 |
Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 757 | quantum-ovs-cleanup --external_network_bridge $bridge |
Yoshihiro Kaneko | 602cf9b | 2012-07-23 06:27:36 +0000 | [diff] [blame] | 758 | sudo ovs-vsctl --no-wait -- --may-exist add-br $bridge |
Yoshihiro Kaneko | 602cf9b | 2012-07-23 06:27:36 +0000 | [diff] [blame] | 759 | # ensure no IP is configured on the public bridge |
| 760 | sudo ip addr flush dev $bridge |
| 761 | } |
| 762 | |
Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 763 | # Functions for Quantum Exercises |
| 764 | #-------------------------------- |
| 765 | |
| 766 | function delete_probe() { |
| 767 | local from_net="$1" |
| 768 | net_id=`_get_net_id $from_net` |
| 769 | probe_id=`quantum-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-list -c id -c network_id | grep $net_id | awk '{print $2}'` |
| 770 | quantum-debug --os-tenant-name admin --os-username admin probe-delete $probe_id |
| 771 | } |
| 772 | |
| 773 | function setup_quantum_debug() { |
| 774 | if [[ "$Q_USE_DEBUG_COMMAND" == "True" ]]; then |
| 775 | public_net_id=`_get_net_id $PUBLIC_NETWORK_NAME` |
| 776 | quantum-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-create $public_net_id |
| 777 | private_net_id=`_get_net_id $PRIVATE_NETWORK_NAME` |
| 778 | quantum-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-create $private_net_id |
Yoshihiro Kaneko | 602cf9b | 2012-07-23 06:27:36 +0000 | [diff] [blame] | 779 | fi |
Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 780 | } |
| 781 | |
| 782 | function teardown_quantum_debug() { |
| 783 | delete_probe $PUBLIC_NETWORK_NAME |
| 784 | delete_probe $PRIVATE_NETWORK_NAME |
Yoshihiro Kaneko | 602cf9b | 2012-07-23 06:27:36 +0000 | [diff] [blame] | 785 | } |
| 786 | |
Nachi Ueno | 5db5bfa | 2012-10-29 11:25:29 -0700 | [diff] [blame] | 787 | function _get_net_id() { |
| 788 | quantum --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD net-list | grep $1 | awk '{print $2}' |
| 789 | } |
| 790 | |
| 791 | function _get_probe_cmd_prefix() { |
| 792 | local from_net="$1" |
| 793 | net_id=`_get_net_id $from_net` |
| 794 | probe_id=`quantum-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-list -c id -c network_id | grep $net_id | awk '{print $2}' | head -n 1` |
Nachi Ueno | 8bc21f6 | 2012-11-19 22:04:28 -0800 | [diff] [blame] | 795 | echo "$Q_RR_COMMAND ip netns exec qprobe-$probe_id" |
Nachi Ueno | 5db5bfa | 2012-10-29 11:25:29 -0700 | [diff] [blame] | 796 | } |
| 797 | |
Nachi Ueno | 5db5bfa | 2012-10-29 11:25:29 -0700 | [diff] [blame] | 798 | function _ping_check_quantum() { |
| 799 | local from_net=$1 |
| 800 | local ip=$2 |
| 801 | local timeout_sec=$3 |
| 802 | local expected=${4:-"True"} |
| 803 | local check_command="" |
| 804 | probe_cmd=`_get_probe_cmd_prefix $from_net` |
| 805 | if [[ "$expected" = "True" ]]; then |
Nachi Ueno | 8bc21f6 | 2012-11-19 22:04:28 -0800 | [diff] [blame] | 806 | check_command="while ! $probe_cmd ping -w 1 -c 1 $ip; do sleep 1; done" |
Nachi Ueno | 5db5bfa | 2012-10-29 11:25:29 -0700 | [diff] [blame] | 807 | else |
Nachi Ueno | 8bc21f6 | 2012-11-19 22:04:28 -0800 | [diff] [blame] | 808 | check_command="while $probe_cmd ping -w 1 -c 1 $ip; do sleep 1; done" |
Nachi Ueno | 5db5bfa | 2012-10-29 11:25:29 -0700 | [diff] [blame] | 809 | fi |
| 810 | if ! timeout $timeout_sec sh -c "$check_command"; then |
| 811 | if [[ "$expected" = "True" ]]; then |
| 812 | echo "[Fail] Couldn't ping server" |
| 813 | else |
| 814 | echo "[Fail] Could ping server" |
| 815 | fi |
| 816 | exit 1 |
| 817 | fi |
| 818 | } |
| 819 | |
| 820 | # ssh check |
| 821 | function _ssh_check_quantum() { |
| 822 | local from_net=$1 |
| 823 | local key_file=$2 |
| 824 | local ip=$3 |
| 825 | local user=$4 |
| 826 | local timeout_sec=$5 |
| 827 | local probe_cmd = "" |
| 828 | probe_cmd=`_get_probe_cmd_prefix $from_net` |
| 829 | if ! timeout $timeout_sec sh -c "while ! $probe_cmd ssh -o StrictHostKeyChecking=no -i $key_file ${user}@$ip echo success ; do sleep 1; done"; then |
| 830 | echo "server didn't become ssh-able!" |
| 831 | exit 1 |
| 832 | fi |
| 833 | } |
| 834 | |
Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 835 | # Quantum 3rd party programs |
| 836 | #--------------------------- |
| 837 | # A comma-separated list of 3rd party programs |
| 838 | QUANTUM_THIRD_PARTIES="ryu" |
| 839 | for third_party in ${QUANTUM_THIRD_PARTIES//,/ }; do |
| 840 | source lib/$third_party |
| 841 | done |
| 842 | |
| 843 | # configure_quantum_third_party() - Set config files, create data dirs, etc |
| 844 | function configure_quantum_third_party() { |
| 845 | for third_party in ${QUANTUM_THIRD_PARTIES//,/ }; do |
| 846 | if is_service_enabled $third_party; then |
| 847 | configure_${third_party} |
| 848 | fi |
| 849 | done |
Nachi Ueno | 5db5bfa | 2012-10-29 11:25:29 -0700 | [diff] [blame] | 850 | } |
| 851 | |
Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 852 | # init_quantum_third_party() - Initialize databases, etc. |
| 853 | function init_quantum_third_party() { |
| 854 | for third_party in ${QUANTUM_THIRD_PARTIES//,/ }; do |
| 855 | if is_service_enabled $third_party; then |
| 856 | init_${third_party} |
| 857 | fi |
| 858 | done |
Nachi Ueno | 5db5bfa | 2012-10-29 11:25:29 -0700 | [diff] [blame] | 859 | } |
| 860 | |
Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 861 | # install_quantum_third_party() - Collect source and prepare |
| 862 | function install_quantum_third_party() { |
| 863 | for third_party in ${QUANTUM_THIRD_PARTIES//,/ }; do |
| 864 | if is_service_enabled $third_party; then |
| 865 | install_${third_party} |
| 866 | fi |
| 867 | done |
| 868 | } |
| 869 | |
| 870 | # start_quantum_third_party() - Start running processes, including screen |
| 871 | function start_quantum_third_party() { |
| 872 | for third_party in ${QUANTUM_THIRD_PARTIES//,/ }; do |
| 873 | if is_service_enabled $third_party; then |
| 874 | start_${third_party} |
| 875 | fi |
| 876 | done |
| 877 | } |
| 878 | |
| 879 | # stop_quantum_third_party - Stop running processes (non-screen) |
| 880 | function stop_quantum_third_party() { |
| 881 | for third_party in ${QUANTUM_THIRD_PARTIES//,/ }; do |
| 882 | if is_service_enabled $third_party; then |
| 883 | stop_${third_party} |
| 884 | fi |
| 885 | done |
| 886 | } |
| 887 | |
| 888 | |
Salvatore Orlando | d6767d0 | 2012-08-31 04:55:20 -0700 | [diff] [blame] | 889 | # Restore xtrace |
| 890 | $XTRACE |