| 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} | 
| Maru Newby | 31c94ab | 2012-12-19 03:59:20 +0000 | [diff] [blame] | 95 | # The name of the default q-l3 router | 
|  | 96 | Q_ROUTER_NAME=${Q_ROUTER_NAME:-router1} | 
| Dean Troyer | 60e9c0a | 2012-12-06 15:52:52 -0600 | [diff] [blame] | 97 |  | 
| Nachi Ueno | 8bc21f6 | 2012-11-19 22:04:28 -0800 | [diff] [blame] | 98 | if is_service_enabled quantum; then | 
| Dean Troyer | 60e9c0a | 2012-12-06 15:52:52 -0600 | [diff] [blame] | 99 | Q_RR_CONF_FILE=$QUANTUM_CONF_DIR/rootwrap.conf | 
| Nachi Ueno | 8bc21f6 | 2012-11-19 22:04:28 -0800 | [diff] [blame] | 100 | if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then | 
|  | 101 | Q_RR_COMMAND="sudo" | 
|  | 102 | else | 
| Nachi Ueno | eb1aa3d | 2012-12-06 11:55:29 -0800 | [diff] [blame] | 103 | QUANTUM_ROOTWRAP=$(get_rootwrap_location quantum) | 
|  | 104 | Q_RR_COMMAND="sudo $QUANTUM_ROOTWRAP $Q_RR_CONF_FILE" | 
| Nachi Ueno | 8bc21f6 | 2012-11-19 22:04:28 -0800 | [diff] [blame] | 105 | fi | 
| Nachi Ueno | 8bc21f6 | 2012-11-19 22:04:28 -0800 | [diff] [blame] | 106 |  | 
| Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 107 | # Provider Network Configurations | 
|  | 108 | # -------------------------------- | 
|  | 109 |  | 
|  | 110 | # The following variables control the Quantum openvswitch and | 
|  | 111 | # linuxbridge plugins' allocation of tenant networks and | 
|  | 112 | # availability of provider networks. If these are not configured | 
|  | 113 | # in localrc, tenant networks will be local to the host (with no | 
|  | 114 | # remote connectivity), and no physical resources will be | 
|  | 115 | # available for the allocation of provider networks. | 
|  | 116 |  | 
|  | 117 | # To use GRE tunnels for tenant networks, set to True in | 
|  | 118 | # localrc. GRE tunnels are only supported by the openvswitch | 
|  | 119 | # plugin, and currently only on Ubuntu. | 
|  | 120 | ENABLE_TENANT_TUNNELS=${ENABLE_TENANT_TUNNELS:-False} | 
|  | 121 |  | 
|  | 122 | # If using GRE tunnels for tenant networks, specify the range of | 
|  | 123 | # tunnel IDs from which tenant networks are allocated. Can be | 
|  | 124 | # overriden in localrc in necesssary. | 
|  | 125 | TENANT_TUNNEL_RANGES=${TENANT_TUNNEL_RANGE:-1:1000} | 
|  | 126 |  | 
|  | 127 | # To use VLANs for tenant networks, set to True in localrc. VLANs | 
|  | 128 | # are supported by the openvswitch and linuxbridge plugins, each | 
|  | 129 | # requiring additional configuration described below. | 
|  | 130 | ENABLE_TENANT_VLANS=${ENABLE_TENANT_VLANS:-False} | 
|  | 131 |  | 
|  | 132 | # If using VLANs for tenant networks, set in localrc to specify | 
|  | 133 | # the range of VLAN VIDs from which tenant networks are | 
|  | 134 | # allocated. An external network switch must be configured to | 
|  | 135 | # trunk these VLANs between hosts for multi-host connectivity. | 
|  | 136 | # | 
|  | 137 | # Example: ``TENANT_VLAN_RANGE=1000:1999`` | 
|  | 138 | TENANT_VLAN_RANGE=${TENANT_VLAN_RANGE:-} | 
|  | 139 |  | 
|  | 140 | # If using VLANs for tenant networks, or if using flat or VLAN | 
|  | 141 | # provider networks, set in localrc to the name of the physical | 
|  | 142 | # network, and also configure OVS_PHYSICAL_BRIDGE for the | 
|  | 143 | # openvswitch agent or LB_PHYSICAL_INTERFACE for the linuxbridge | 
|  | 144 | # agent, as described below. | 
|  | 145 | # | 
|  | 146 | # Example: ``PHYSICAL_NETWORK=default`` | 
|  | 147 | PHYSICAL_NETWORK=${PHYSICAL_NETWORK:-} | 
|  | 148 |  | 
|  | 149 | # With the openvswitch plugin, if using VLANs for tenant networks, | 
|  | 150 | # or if using flat or VLAN provider networks, set in localrc to | 
|  | 151 | # the name of the OVS bridge to use for the physical network. The | 
|  | 152 | # bridge will be created if it does not already exist, but a | 
|  | 153 | # physical interface must be manually added to the bridge as a | 
|  | 154 | # port for external connectivity. | 
|  | 155 | # | 
|  | 156 | # Example: ``OVS_PHYSICAL_BRIDGE=br-eth1`` | 
|  | 157 | OVS_PHYSICAL_BRIDGE=${OVS_PHYSICAL_BRIDGE:-} | 
|  | 158 |  | 
|  | 159 | # With the linuxbridge plugin, if using VLANs for tenant networks, | 
|  | 160 | # or if using flat or VLAN provider networks, set in localrc to | 
|  | 161 | # the name of the network interface to use for the physical | 
|  | 162 | # network. | 
|  | 163 | # | 
|  | 164 | # Example: ``LB_PHYSICAL_INTERFACE=eth1`` | 
|  | 165 | LB_PHYSICAL_INTERFACE=${LB_PHYSICAL_INTERFACE:-} | 
|  | 166 |  | 
|  | 167 | # With the openvswitch plugin, set to True in localrc to enable | 
|  | 168 | # provider GRE tunnels when ``ENABLE_TENANT_TUNNELS`` is False. | 
|  | 169 | # | 
|  | 170 | # Example: ``OVS_ENABLE_TUNNELING=True`` | 
|  | 171 | OVS_ENABLE_TUNNELING=${OVS_ENABLE_TUNNELING:-$ENABLE_TENANT_TUNNELS} | 
|  | 172 | fi | 
| Dean Troyer | 60e9c0a | 2012-12-06 15:52:52 -0600 | [diff] [blame] | 173 |  | 
| Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 174 | # Quantum plugin specific functions | 
|  | 175 | # --------------------------------- | 
|  | 176 | # Please refer to lib/quantum_plugins/README.md for details. | 
|  | 177 | source $TOP_DIR/lib/quantum_plugins/$Q_PLUGIN | 
|  | 178 |  | 
| Dean Troyer | 60e9c0a | 2012-12-06 15:52:52 -0600 | [diff] [blame] | 179 | # Entry Points | 
|  | 180 | # ------------ | 
|  | 181 |  | 
| Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 182 | # configure_quantum() | 
|  | 183 | # Set common config for all quantum server and agents. | 
|  | 184 | function configure_quantum() { | 
|  | 185 | _configure_quantum_common | 
| Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 186 | iniset_rpc_backend quantum $QUANTUM_CONF DEFAULT | 
| Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 187 |  | 
|  | 188 | if is_service_enabled q-svc; then | 
|  | 189 | _configure_quantum_service | 
|  | 190 | fi | 
|  | 191 | if is_service_enabled q-agt; then | 
|  | 192 | _configure_quantum_plugin_agent | 
|  | 193 | fi | 
|  | 194 | if is_service_enabled q-dhcp; then | 
|  | 195 | _configure_quantum_dhcp_agent | 
|  | 196 | fi | 
|  | 197 | if is_service_enabled q-l3; then | 
|  | 198 | _configure_quantum_l3_agent | 
|  | 199 | fi | 
|  | 200 | if is_service_enabled q-meta; then | 
|  | 201 | _configure_quantum_metadata_agent | 
|  | 202 | fi | 
|  | 203 |  | 
|  | 204 | _configure_quantum_debug_command | 
|  | 205 |  | 
|  | 206 | _cleanup_quantum | 
|  | 207 | } | 
|  | 208 |  | 
|  | 209 | function create_nova_conf_quantum() { | 
| Devananda van der Veen | 9bc47db | 2012-12-12 16:52:55 -0800 | [diff] [blame] | 210 | iniset $NOVA_CONF DEFAULT network_api_class "nova.network.quantumv2.api.API" | 
|  | 211 | iniset $NOVA_CONF DEFAULT quantum_admin_username "$Q_ADMIN_USERNAME" | 
|  | 212 | iniset $NOVA_CONF DEFAULT quantum_admin_password "$SERVICE_PASSWORD" | 
|  | 213 | iniset $NOVA_CONF DEFAULT quantum_admin_auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_AUTH_PORT/v2.0" | 
|  | 214 | iniset $NOVA_CONF DEFAULT quantum_auth_strategy "$Q_AUTH_STRATEGY" | 
|  | 215 | iniset $NOVA_CONF DEFAULT quantum_admin_tenant_name "$SERVICE_TENANT_NAME" | 
|  | 216 | iniset $NOVA_CONF DEFAULT quantum_url "http://$Q_HOST:$Q_PORT" | 
| Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 217 |  | 
| Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 218 | # set NOVA_VIF_DRIVER and optionally set options in nova_conf | 
|  | 219 | quantum_plugin_create_nova_conf | 
|  | 220 |  | 
| 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. | 
| Devananda van der Veen | 37a8d15 | 2013-01-15 17:27:34 -0800 | [diff] [blame] | 273 | if is_baremetal; then | 
|  | 274 | sudo ovs-vsctl add-port $OVS_PHYSICAL_BRIDGE $PUBLIC_INTERFACE | 
|  | 275 | for IP in $(ip addr show dev $PUBLIC_INTERFACE | grep ' inet ' | awk '{print $2}'); do | 
|  | 276 | sudo ip addr del $IP dev $PUBLIC_INTERFACE | 
|  | 277 | sudo ip addr add $IP dev $OVS_PHYSICAL_BRIDGE | 
|  | 278 | done | 
|  | 279 | NET_ID=$(quantum net-create $PHYSICAL_NETWORK --tenant_id $TENANT_ID --provider:network_type flat --provider:physical_network "$PHYSICAL_NETWORK" | grep ' id ' | get_field 2) | 
|  | 280 | SUBNET_ID=$(quantum subnet-create --tenant_id $TENANT_ID --ip_version 4 ${ALLOCATION_POOL:+--allocation-pool $ALLOCATION_POOL} --gateway $NETWORK_GATEWAY $NET_ID $FIXED_RANGE | grep ' id ' | get_field 2) | 
|  | 281 | sudo ifconfig $OVS_PHYSICAL_BRIDGE up | 
|  | 282 | else | 
|  | 283 | NET_ID=$(quantum net-create --tenant_id $TENANT_ID "$PRIVATE_NETWORK_NAME" | grep ' id ' | get_field 2) | 
|  | 284 | SUBNET_ID=$(quantum subnet-create --tenant_id $TENANT_ID --ip_version 4 --gateway $NETWORK_GATEWAY $NET_ID $FIXED_RANGE | grep ' id ' | get_field 2) | 
|  | 285 | fi | 
| Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 286 |  | 
| Dan Wendlandt | 555ecd0 | 2013-02-23 23:07:07 -0800 | [diff] [blame] | 287 | if [[ "$Q_L3_ENABLED" == "True" ]]; then | 
| Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 288 | # Create a router, and add the private subnet as one of its interfaces | 
| Dan Wendlandt | 555ecd0 | 2013-02-23 23:07:07 -0800 | [diff] [blame] | 289 | if [[ "$Q_L3_ROUTER_PER_TENANT" == "True" ]]; then | 
|  | 290 | # create a tenant-owned router. | 
| Maru Newby | 31c94ab | 2012-12-19 03:59:20 +0000 | [diff] [blame] | 291 | ROUTER_ID=$(quantum router-create --tenant_id $TENANT_ID $Q_ROUTER_NAME | grep ' id ' | get_field 2) | 
|  | 292 | else | 
| Dan Wendlandt | 555ecd0 | 2013-02-23 23:07:07 -0800 | [diff] [blame] | 293 | # Plugin only supports creating a single router, which should be admin owned. | 
| Maru Newby | 31c94ab | 2012-12-19 03:59:20 +0000 | [diff] [blame] | 294 | ROUTER_ID=$(quantum router-create $Q_ROUTER_NAME | grep ' id ' | get_field 2) | 
|  | 295 | fi | 
| Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 296 | quantum router-interface-add $ROUTER_ID $SUBNET_ID | 
|  | 297 | # Create an external network, and a subnet. Configure the external network as router gw | 
|  | 298 | EXT_NET_ID=$(quantum net-create "$PUBLIC_NETWORK_NAME" -- --router:external=True | grep ' id ' | get_field 2) | 
| Stephen Ma | 8396d4f | 2013-02-18 05:32:59 -0800 | [diff] [blame] | 299 | EXT_GW_IP=$(quantum subnet-create --ip_version 4 ${Q_FLOATING_ALLOCATION_POOL:+--allocation-pool $Q_FLOATING_ALLOCATION_POOL} $EXT_NET_ID $FLOATING_RANGE -- --enable_dhcp=False | grep 'gateway_ip' | get_field 2) | 
| Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 300 | quantum router-gateway-set $ROUTER_ID $EXT_NET_ID | 
|  | 301 |  | 
| Dan Wendlandt | 555ecd0 | 2013-02-23 23:07:07 -0800 | [diff] [blame] | 302 | if is_service_enabled q-l3; then | 
|  | 303 | # logic is specific to using the l3-agent for l3 | 
|  | 304 | if is_quantum_ovs_base_plugin && [[ "$Q_USE_NAMESPACE" = "True" ]]; then | 
|  | 305 | CIDR_LEN=${FLOATING_RANGE#*/} | 
|  | 306 | sudo ip addr add $EXT_GW_IP/$CIDR_LEN dev $PUBLIC_BRIDGE | 
|  | 307 | sudo ip link set $PUBLIC_BRIDGE up | 
|  | 308 | ROUTER_GW_IP=`quantum port-list -c fixed_ips -c device_owner | grep router_gateway | awk -F '"' '{ print $8; }'` | 
|  | 309 | sudo route add -net $FIXED_RANGE gw $ROUTER_GW_IP | 
|  | 310 | fi | 
|  | 311 | if [[ "$Q_USE_NAMESPACE" == "False" ]]; then | 
|  | 312 | # Explicitly set router id in l3 agent configuration | 
|  | 313 | iniset $Q_L3_CONF_FILE DEFAULT router_id $ROUTER_ID | 
|  | 314 | fi | 
| Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 315 | fi | 
|  | 316 | fi | 
|  | 317 | } | 
|  | 318 |  | 
|  | 319 | # init_quantum() - Initialize databases, etc. | 
|  | 320 | function init_quantum() { | 
|  | 321 | : | 
|  | 322 | } | 
|  | 323 |  | 
|  | 324 | # install_quantum() - Collect source and prepare | 
|  | 325 | function install_quantum() { | 
|  | 326 | git_clone $QUANTUM_REPO $QUANTUM_DIR $QUANTUM_BRANCH | 
|  | 327 | } | 
|  | 328 |  | 
|  | 329 | # install_quantumclient() - Collect source and prepare | 
|  | 330 | function install_quantumclient() { | 
|  | 331 | git_clone $QUANTUMCLIENT_REPO $QUANTUMCLIENT_DIR $QUANTUMCLIENT_BRANCH | 
|  | 332 | } | 
|  | 333 |  | 
|  | 334 | # install_quantum_agent_packages() - Collect source and prepare | 
|  | 335 | function install_quantum_agent_packages() { | 
| Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 336 | # install packages that is specific to plugin agent | 
|  | 337 | quantum_plugin_install_agent_packages | 
| Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 338 | } | 
|  | 339 |  | 
|  | 340 | function setup_quantum() { | 
|  | 341 | setup_develop $QUANTUM_DIR | 
|  | 342 | } | 
|  | 343 |  | 
|  | 344 | function setup_quantumclient() { | 
|  | 345 | setup_develop $QUANTUMCLIENT_DIR | 
|  | 346 | } | 
|  | 347 |  | 
|  | 348 | # Start running processes, including screen | 
|  | 349 | function start_quantum_service_and_check() { | 
|  | 350 | # Start the Quantum service | 
|  | 351 | screen_it q-svc "cd $QUANTUM_DIR && python $QUANTUM_DIR/bin/quantum-server --config-file $QUANTUM_CONF --config-file /$Q_PLUGIN_CONF_FILE" | 
|  | 352 | echo "Waiting for Quantum to start..." | 
| Aaron Rosen | 0ae742c | 2013-02-21 12:10:30 -0800 | [diff] [blame] | 353 | if ! timeout $SERVICE_TIMEOUT sh -c "while ! http_proxy= wget -q -O- http://$Q_HOST:$Q_PORT; do sleep 1; done"; then | 
| Nachi Ueno | 07115eb | 2013-02-26 12:38:18 -0800 | [diff] [blame] | 354 | die $LINENO "Quantum did not start" | 
| Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 355 | fi | 
|  | 356 | } | 
|  | 357 |  | 
|  | 358 | # Start running processes, including screen | 
|  | 359 | function start_quantum_agents() { | 
|  | 360 | # Start up the quantum agents if enabled | 
|  | 361 | screen_it q-agt "python $AGENT_BINARY --config-file $QUANTUM_CONF --config-file /$Q_PLUGIN_CONF_FILE" | 
|  | 362 | screen_it q-dhcp "python $AGENT_DHCP_BINARY --config-file $QUANTUM_CONF --config-file=$Q_DHCP_CONF_FILE" | 
|  | 363 | screen_it q-meta "python $AGENT_META_BINARY --config-file $QUANTUM_CONF --config-file=$Q_META_CONF_FILE" | 
|  | 364 | screen_it q-l3 "python $AGENT_L3_BINARY --config-file $QUANTUM_CONF --config-file=$Q_L3_CONF_FILE" | 
|  | 365 | } | 
|  | 366 |  | 
|  | 367 | # stop_quantum() - Stop running processes (non-screen) | 
|  | 368 | function stop_quantum() { | 
|  | 369 | if is_service_enabled q-dhcp; then | 
|  | 370 | pid=$(ps aux | awk '/[d]nsmasq.+interface=(tap|ns-)/ { print $2 }') | 
|  | 371 | [ ! -z "$pid" ] && sudo kill -9 $pid | 
|  | 372 | fi | 
|  | 373 | } | 
|  | 374 |  | 
|  | 375 | # _cleanup_quantum() - Remove residual data files, anything left over from previous | 
|  | 376 | # runs that a clean run would need to clean up | 
|  | 377 | function _cleanup_quantum() { | 
|  | 378 | : | 
|  | 379 | } | 
|  | 380 |  | 
|  | 381 | # _configure_quantum_common() | 
|  | 382 | # Set common config for all quantum server and agents. | 
|  | 383 | # This MUST be called before other _configure_quantum_* functions. | 
|  | 384 | function _configure_quantum_common() { | 
|  | 385 | # Put config files in ``QUANTUM_CONF_DIR`` for everyone to find | 
|  | 386 | if [[ ! -d $QUANTUM_CONF_DIR ]]; then | 
|  | 387 | sudo mkdir -p $QUANTUM_CONF_DIR | 
|  | 388 | fi | 
| Attila Fazekas | 91b8d13 | 2013-01-06 22:40:09 +0100 | [diff] [blame] | 389 | sudo chown $STACK_USER $QUANTUM_CONF_DIR | 
| Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 390 |  | 
|  | 391 | cp $QUANTUM_DIR/etc/quantum.conf $QUANTUM_CONF | 
|  | 392 |  | 
| Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 393 | # set plugin-specific variables | 
|  | 394 | # Q_PLUGIN_CONF_PATH, Q_PLUGIN_CONF_FILENAME, Q_DB_NAME, Q_PLUGIN_CLASS | 
|  | 395 | quantum_plugin_configure_common | 
| Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 396 |  | 
|  | 397 | if [[ $Q_PLUGIN_CONF_PATH == '' || $Q_PLUGIN_CONF_FILENAME == '' || $Q_PLUGIN_CLASS == '' ]]; then | 
| Nachi Ueno | 07115eb | 2013-02-26 12:38:18 -0800 | [diff] [blame] | 398 | die $LINENO "Quantum plugin not set.. exiting" | 
| Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 399 | fi | 
|  | 400 |  | 
|  | 401 | # If needed, move config file from ``$QUANTUM_DIR/etc/quantum`` to ``QUANTUM_CONF_DIR`` | 
|  | 402 | mkdir -p /$Q_PLUGIN_CONF_PATH | 
|  | 403 | Q_PLUGIN_CONF_FILE=$Q_PLUGIN_CONF_PATH/$Q_PLUGIN_CONF_FILENAME | 
|  | 404 | cp $QUANTUM_DIR/$Q_PLUGIN_CONF_FILE /$Q_PLUGIN_CONF_FILE | 
|  | 405 |  | 
|  | 406 | database_connection_url dburl $Q_DB_NAME | 
|  | 407 | iniset /$Q_PLUGIN_CONF_FILE DATABASE sql_connection $dburl | 
|  | 408 | unset dburl | 
|  | 409 |  | 
|  | 410 | _quantum_setup_rootwrap | 
|  | 411 | } | 
|  | 412 |  | 
|  | 413 | function _configure_quantum_debug_command() { | 
|  | 414 | if [[ "$Q_USE_DEBUG_COMMAND" != "True" ]]; then | 
|  | 415 | return | 
|  | 416 | fi | 
|  | 417 |  | 
|  | 418 | cp $QUANTUM_DIR/etc/l3_agent.ini $QUANTUM_TEST_CONFIG_FILE | 
|  | 419 |  | 
|  | 420 | iniset $QUANTUM_TEST_CONFIG_FILE DEFAULT verbose False | 
|  | 421 | iniset $QUANTUM_TEST_CONFIG_FILE DEFAULT debug False | 
|  | 422 | iniset $QUANTUM_TEST_CONFIG_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE | 
|  | 423 | iniset $QUANTUM_TEST_CONFIG_FILE DEFAULT root_helper "$Q_RR_COMMAND" | 
| Gary Kotton | d9ca2b2 | 2013-01-30 13:52:43 +0000 | [diff] [blame] | 424 | # Intermediate fix until Quantum patch lands and then line above will | 
|  | 425 | # be cleaned. | 
|  | 426 | iniset $QUANTUM_TEST_CONFIG_FILE AGENT root_helper "$Q_RR_COMMAND" | 
| Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 427 |  | 
|  | 428 | _quantum_setup_keystone $QUANTUM_TEST_CONFIG_FILE DEFAULT set_auth_url | 
|  | 429 | _quantum_setup_interface_driver $QUANTUM_TEST_CONFIG_FILE | 
|  | 430 |  | 
| Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 431 | quantum_plugin_configure_debug_command | 
| Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 432 | } | 
|  | 433 |  | 
|  | 434 | function _configure_quantum_dhcp_agent() { | 
|  | 435 | AGENT_DHCP_BINARY="$QUANTUM_DIR/bin/quantum-dhcp-agent" | 
|  | 436 | Q_DHCP_CONF_FILE=$QUANTUM_CONF_DIR/dhcp_agent.ini | 
|  | 437 |  | 
|  | 438 | cp $QUANTUM_DIR/etc/dhcp_agent.ini $Q_DHCP_CONF_FILE | 
|  | 439 |  | 
|  | 440 | iniset $Q_DHCP_CONF_FILE DEFAULT verbose True | 
|  | 441 | iniset $Q_DHCP_CONF_FILE DEFAULT debug True | 
|  | 442 | iniset $Q_DHCP_CONF_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE | 
| Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 443 | iniset $Q_DHCP_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND" | 
|  | 444 |  | 
|  | 445 | _quantum_setup_keystone $Q_DHCP_CONF_FILE DEFAULT set_auth_url | 
|  | 446 | _quantum_setup_interface_driver $Q_DHCP_CONF_FILE | 
|  | 447 |  | 
| Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 448 | quantum_plugin_configure_dhcp_agent | 
| Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 449 | } | 
|  | 450 |  | 
|  | 451 | function _configure_quantum_l3_agent() { | 
| Dan Wendlandt | 555ecd0 | 2013-02-23 23:07:07 -0800 | [diff] [blame] | 452 | Q_L3_ENABLED=True | 
|  | 453 | # for l3-agent, only use per tenant router if we have namespaces | 
|  | 454 | Q_L3_ROUTER_PER_TENANT=$Q_USE_NAMESPACE | 
| Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 455 | AGENT_L3_BINARY="$QUANTUM_DIR/bin/quantum-l3-agent" | 
|  | 456 | PUBLIC_BRIDGE=${PUBLIC_BRIDGE:-br-ex} | 
|  | 457 | Q_L3_CONF_FILE=$QUANTUM_CONF_DIR/l3_agent.ini | 
|  | 458 |  | 
|  | 459 | cp $QUANTUM_DIR/etc/l3_agent.ini $Q_L3_CONF_FILE | 
|  | 460 |  | 
|  | 461 | iniset $Q_L3_CONF_FILE DEFAULT verbose True | 
|  | 462 | iniset $Q_L3_CONF_FILE DEFAULT debug True | 
|  | 463 | iniset $Q_L3_CONF_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE | 
| Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 464 | iniset $Q_L3_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND" | 
|  | 465 |  | 
|  | 466 | _quantum_setup_keystone $Q_L3_CONF_FILE DEFAULT set_auth_url | 
|  | 467 | _quantum_setup_interface_driver $Q_L3_CONF_FILE | 
|  | 468 |  | 
| Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 469 | quantum_plugin_configure_l3_agent | 
| Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 470 | } | 
|  | 471 |  | 
|  | 472 | function _configure_quantum_metadata_agent() { | 
|  | 473 | AGENT_META_BINARY="$QUANTUM_DIR/bin/quantum-metadata-agent" | 
|  | 474 | Q_META_CONF_FILE=$QUANTUM_CONF_DIR/metadata_agent.ini | 
|  | 475 |  | 
|  | 476 | cp $QUANTUM_DIR/etc/metadata_agent.ini $Q_META_CONF_FILE | 
|  | 477 |  | 
|  | 478 | iniset $Q_META_CONF_FILE DEFAULT verbose True | 
|  | 479 | iniset $Q_META_CONF_FILE DEFAULT debug True | 
| Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 480 | iniset $Q_META_CONF_FILE DEFAULT nova_metadata_ip $Q_META_DATA_IP | 
|  | 481 | iniset $Q_META_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND" | 
|  | 482 |  | 
|  | 483 | _quantum_setup_keystone $Q_META_CONF_FILE DEFAULT set_auth_url | 
|  | 484 | } | 
|  | 485 |  | 
|  | 486 | # _configure_quantum_plugin_agent() - Set config files for quantum plugin agent | 
|  | 487 | # It is called when q-agt is enabled. | 
|  | 488 | function _configure_quantum_plugin_agent() { | 
| Maru Newby | 2298ca4 | 2012-10-25 23:46:42 +0000 | [diff] [blame] | 489 | # Specify the default root helper prior to agent configuration to | 
| Gary Kotton | 98e18e9 | 2013-01-28 14:26:56 +0000 | [diff] [blame] | 490 | # ensure that an agent's configuration can override the default | 
| Maru Newby | 2298ca4 | 2012-10-25 23:46:42 +0000 | [diff] [blame] | 491 | iniset /$Q_PLUGIN_CONF_FILE AGENT root_helper "$Q_RR_COMMAND" | 
|  | 492 |  | 
| Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 493 | # Configure agent for plugin | 
| Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 494 | quantum_plugin_configure_plugin_agent | 
| Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 495 | } | 
|  | 496 |  | 
| Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 497 | # _configure_quantum_service() - Set config files for quantum service | 
|  | 498 | # It is called when q-svc is enabled. | 
|  | 499 | function _configure_quantum_service() { | 
|  | 500 | Q_API_PASTE_FILE=$QUANTUM_CONF_DIR/api-paste.ini | 
|  | 501 | Q_POLICY_FILE=$QUANTUM_CONF_DIR/policy.json | 
|  | 502 |  | 
|  | 503 | cp $QUANTUM_DIR/etc/api-paste.ini $Q_API_PASTE_FILE | 
|  | 504 | cp $QUANTUM_DIR/etc/policy.json $Q_POLICY_FILE | 
|  | 505 |  | 
|  | 506 | if is_service_enabled $DATABASE_BACKENDS; then | 
|  | 507 | recreate_database $Q_DB_NAME utf8 | 
|  | 508 | else | 
| Nachi Ueno | 07115eb | 2013-02-26 12:38:18 -0800 | [diff] [blame] | 509 | die $LINENO "A database must be enabled in order to use the $Q_PLUGIN Quantum plugin." | 
| Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 510 | fi | 
|  | 511 |  | 
|  | 512 | # Update either configuration file with plugin | 
|  | 513 | iniset $QUANTUM_CONF DEFAULT core_plugin $Q_PLUGIN_CLASS | 
|  | 514 |  | 
|  | 515 | iniset $QUANTUM_CONF DEFAULT verbose True | 
|  | 516 | iniset $QUANTUM_CONF DEFAULT debug True | 
| Akihiro MOTOKI | 3c6e9a5 | 2013-02-26 14:50:56 +0900 | [diff] [blame] | 517 | iniset $QUANTUM_CONF DEFAULT state_path $DATA_DIR/quantum | 
| Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 518 | iniset $QUANTUM_CONF DEFAULT allow_overlapping_ips $Q_ALLOW_OVERLAPPING_IP | 
|  | 519 |  | 
|  | 520 | iniset $QUANTUM_CONF DEFAULT auth_strategy $Q_AUTH_STRATEGY | 
| Akihiro MOTOKI | 712feb6 | 2013-02-11 23:45:19 +0900 | [diff] [blame] | 521 | _quantum_setup_keystone $QUANTUM_CONF keystone_authtoken | 
|  | 522 | # Comment out keystone authtoken configuration in api-paste.ini | 
|  | 523 | # It is required to avoid any breakage in Quantum where the sample | 
|  | 524 | # api-paste.ini has authtoken configurations. | 
|  | 525 | _quantum_commentout_keystone_authtoken $Q_API_PASTE_FILE filter:authtoken | 
| Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 526 |  | 
|  | 527 | # Configure plugin | 
| Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 528 | quantum_plugin_configure_service | 
| Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 529 | } | 
|  | 530 |  | 
|  | 531 | # Utility Functions | 
|  | 532 | #------------------ | 
|  | 533 |  | 
|  | 534 | # _quantum_setup_rootwrap() - configure Quantum's rootwrap | 
|  | 535 | function _quantum_setup_rootwrap() { | 
| Nachi Ueno | eb1aa3d | 2012-12-06 11:55:29 -0800 | [diff] [blame] | 536 | if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then | 
|  | 537 | return | 
|  | 538 | fi | 
|  | 539 | # Deploy new rootwrap filters files (owned by root). | 
|  | 540 | # Wipe any existing rootwrap.d files first | 
| Dean Troyer | 60e9c0a | 2012-12-06 15:52:52 -0600 | [diff] [blame] | 541 | Q_CONF_ROOTWRAP_D=$QUANTUM_CONF_DIR/rootwrap.d | 
| Nachi Ueno | eb1aa3d | 2012-12-06 11:55:29 -0800 | [diff] [blame] | 542 | if [[ -d $Q_CONF_ROOTWRAP_D ]]; then | 
|  | 543 | sudo rm -rf $Q_CONF_ROOTWRAP_D | 
|  | 544 | fi | 
| Dean Troyer | 60e9c0a | 2012-12-06 15:52:52 -0600 | [diff] [blame] | 545 | # Deploy filters to $QUANTUM_CONF_DIR/rootwrap.d | 
| Nachi Ueno | eb1aa3d | 2012-12-06 11:55:29 -0800 | [diff] [blame] | 546 | mkdir -p -m 755 $Q_CONF_ROOTWRAP_D | 
|  | 547 | cp -pr $QUANTUM_DIR/etc/quantum/rootwrap.d/* $Q_CONF_ROOTWRAP_D/ | 
|  | 548 | sudo chown -R root:root $Q_CONF_ROOTWRAP_D | 
|  | 549 | sudo chmod 644 $Q_CONF_ROOTWRAP_D/* | 
| Dean Troyer | 60e9c0a | 2012-12-06 15:52:52 -0600 | [diff] [blame] | 550 | # Set up rootwrap.conf, pointing to $QUANTUM_CONF_DIR/rootwrap.d | 
| Nachi Ueno | eb1aa3d | 2012-12-06 11:55:29 -0800 | [diff] [blame] | 551 | sudo cp -p $QUANTUM_DIR/etc/rootwrap.conf $Q_RR_CONF_FILE | 
|  | 552 | sudo sed -e "s:^filters_path=.*$:filters_path=$Q_CONF_ROOTWRAP_D:" -i $Q_RR_CONF_FILE | 
|  | 553 | sudo chown root:root $Q_RR_CONF_FILE | 
|  | 554 | sudo chmod 0644 $Q_RR_CONF_FILE | 
|  | 555 | # Specify rootwrap.conf as first parameter to quantum-rootwrap | 
|  | 556 | ROOTWRAP_SUDOER_CMD="$QUANTUM_ROOTWRAP $Q_RR_CONF_FILE *" | 
|  | 557 |  | 
|  | 558 | # Set up the rootwrap sudoers for quantum | 
|  | 559 | TEMPFILE=`mktemp` | 
|  | 560 | echo "$USER ALL=(root) NOPASSWD: $ROOTWRAP_SUDOER_CMD" >$TEMPFILE | 
|  | 561 | chmod 0440 $TEMPFILE | 
|  | 562 | sudo chown root:root $TEMPFILE | 
|  | 563 | sudo mv $TEMPFILE /etc/sudoers.d/quantum-rootwrap | 
| Gary Kotton | 98e18e9 | 2013-01-28 14:26:56 +0000 | [diff] [blame] | 564 |  | 
|  | 565 | # Update the root_helper | 
|  | 566 | iniset $QUANTUM_CONF AGENT root_helper "$Q_RR_COMMAND" | 
| Nachi Ueno | eb1aa3d | 2012-12-06 11:55:29 -0800 | [diff] [blame] | 567 | } | 
|  | 568 |  | 
| Salvatore Orlando | d6767d0 | 2012-08-31 04:55:20 -0700 | [diff] [blame] | 569 | # Configures keystone integration for quantum service and agents | 
| Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 570 | function _quantum_setup_keystone() { | 
| Salvatore Orlando | d6767d0 | 2012-08-31 04:55:20 -0700 | [diff] [blame] | 571 | local conf_file=$1 | 
|  | 572 | local section=$2 | 
|  | 573 | local use_auth_url=$3 | 
|  | 574 | if [[ -n $use_auth_url ]]; then | 
|  | 575 | iniset $conf_file $section auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_AUTH_HOST:$KEYSTONE_AUTH_PORT/v2.0" | 
|  | 576 | else | 
|  | 577 | iniset $conf_file $section auth_host $KEYSTONE_SERVICE_HOST | 
|  | 578 | iniset $conf_file $section auth_port $KEYSTONE_AUTH_PORT | 
|  | 579 | iniset $conf_file $section auth_protocol $KEYSTONE_SERVICE_PROTOCOL | 
|  | 580 | fi | 
|  | 581 | iniset $conf_file $section admin_tenant_name $SERVICE_TENANT_NAME | 
|  | 582 | iniset $conf_file $section admin_user $Q_ADMIN_USERNAME | 
|  | 583 | iniset $conf_file $section admin_password $SERVICE_PASSWORD | 
| Akihiro MOTOKI | 5e3deb6 | 2012-12-11 17:09:02 +0900 | [diff] [blame] | 584 | iniset $conf_file $section signing_dir $QUANTUM_AUTH_CACHE_DIR | 
|  | 585 | # Create cache dir | 
|  | 586 | sudo mkdir -p $QUANTUM_AUTH_CACHE_DIR | 
| Attila Fazekas | 91b8d13 | 2013-01-06 22:40:09 +0100 | [diff] [blame] | 587 | sudo chown $STACK_USER $QUANTUM_AUTH_CACHE_DIR | 
| Vishvananda Ishaya | 23431f3 | 2012-12-12 15:57:33 -0800 | [diff] [blame] | 588 | rm -f $QUANTUM_AUTH_CACHE_DIR/* | 
| Salvatore Orlando | d6767d0 | 2012-08-31 04:55:20 -0700 | [diff] [blame] | 589 | } | 
|  | 590 |  | 
| Akihiro MOTOKI | 712feb6 | 2013-02-11 23:45:19 +0900 | [diff] [blame] | 591 | function _quantum_commentout_keystone_authtoken() { | 
|  | 592 | local conf_file=$1 | 
|  | 593 | local section=$2 | 
|  | 594 |  | 
|  | 595 | inicomment $conf_file $section auth_host | 
|  | 596 | inicomment $conf_file $section auth_port | 
|  | 597 | inicomment $conf_file $section auth_protocol | 
|  | 598 | inicomment $conf_file $section auth_url | 
|  | 599 |  | 
|  | 600 | inicomment $conf_file $section admin_tenant_name | 
|  | 601 | inicomment $conf_file $section admin_user | 
|  | 602 | inicomment $conf_file $section admin_password | 
|  | 603 | inicomment $conf_file $section signing_dir | 
|  | 604 | } | 
|  | 605 |  | 
| Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 606 | function _quantum_setup_interface_driver() { | 
| Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 607 | quantum_plugin_setup_interface_driver $1 | 
| Yoshihiro Kaneko | 602cf9b | 2012-07-23 06:27:36 +0000 | [diff] [blame] | 608 | } | 
|  | 609 |  | 
| Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 610 | # Functions for Quantum Exercises | 
|  | 611 | #-------------------------------- | 
|  | 612 |  | 
|  | 613 | function delete_probe() { | 
|  | 614 | local from_net="$1" | 
|  | 615 | net_id=`_get_net_id $from_net` | 
|  | 616 | 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}'` | 
|  | 617 | quantum-debug --os-tenant-name admin --os-username admin probe-delete $probe_id | 
|  | 618 | } | 
|  | 619 |  | 
|  | 620 | function setup_quantum_debug() { | 
|  | 621 | if [[ "$Q_USE_DEBUG_COMMAND" == "True" ]]; then | 
|  | 622 | public_net_id=`_get_net_id $PUBLIC_NETWORK_NAME` | 
|  | 623 | quantum-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-create $public_net_id | 
|  | 624 | private_net_id=`_get_net_id $PRIVATE_NETWORK_NAME` | 
|  | 625 | 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] | 626 | fi | 
| Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 627 | } | 
|  | 628 |  | 
|  | 629 | function teardown_quantum_debug() { | 
|  | 630 | delete_probe $PUBLIC_NETWORK_NAME | 
|  | 631 | delete_probe $PRIVATE_NETWORK_NAME | 
| Yoshihiro Kaneko | 602cf9b | 2012-07-23 06:27:36 +0000 | [diff] [blame] | 632 | } | 
|  | 633 |  | 
| Nachi Ueno | 5db5bfa | 2012-10-29 11:25:29 -0700 | [diff] [blame] | 634 | function _get_net_id() { | 
|  | 635 | quantum --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD net-list | grep $1 | awk '{print $2}' | 
|  | 636 | } | 
|  | 637 |  | 
|  | 638 | function _get_probe_cmd_prefix() { | 
|  | 639 | local from_net="$1" | 
|  | 640 | net_id=`_get_net_id $from_net` | 
|  | 641 | 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] | 642 | echo "$Q_RR_COMMAND ip netns exec qprobe-$probe_id" | 
| Nachi Ueno | 5db5bfa | 2012-10-29 11:25:29 -0700 | [diff] [blame] | 643 | } | 
|  | 644 |  | 
| Nachi Ueno | 5db5bfa | 2012-10-29 11:25:29 -0700 | [diff] [blame] | 645 | function _ping_check_quantum() { | 
|  | 646 | local from_net=$1 | 
|  | 647 | local ip=$2 | 
|  | 648 | local timeout_sec=$3 | 
|  | 649 | local expected=${4:-"True"} | 
|  | 650 | local check_command="" | 
|  | 651 | probe_cmd=`_get_probe_cmd_prefix $from_net` | 
|  | 652 | if [[ "$expected" = "True" ]]; then | 
| Nachi Ueno | 8bc21f6 | 2012-11-19 22:04:28 -0800 | [diff] [blame] | 653 | 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] | 654 | else | 
| Nachi Ueno | 8bc21f6 | 2012-11-19 22:04:28 -0800 | [diff] [blame] | 655 | 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] | 656 | fi | 
|  | 657 | if ! timeout $timeout_sec sh -c "$check_command"; then | 
|  | 658 | if [[ "$expected" = "True" ]]; then | 
| Nachi Ueno | 07115eb | 2013-02-26 12:38:18 -0800 | [diff] [blame] | 659 | die $LINENO "[Fail] Couldn't ping server" | 
| Nachi Ueno | 5db5bfa | 2012-10-29 11:25:29 -0700 | [diff] [blame] | 660 | else | 
| Nachi Ueno | 07115eb | 2013-02-26 12:38:18 -0800 | [diff] [blame] | 661 | die $LINENO "[Fail] Could ping server" | 
| Nachi Ueno | 5db5bfa | 2012-10-29 11:25:29 -0700 | [diff] [blame] | 662 | fi | 
| Nachi Ueno | 5db5bfa | 2012-10-29 11:25:29 -0700 | [diff] [blame] | 663 | fi | 
|  | 664 | } | 
|  | 665 |  | 
|  | 666 | # ssh check | 
|  | 667 | function _ssh_check_quantum() { | 
|  | 668 | local from_net=$1 | 
|  | 669 | local key_file=$2 | 
|  | 670 | local ip=$3 | 
|  | 671 | local user=$4 | 
|  | 672 | local timeout_sec=$5 | 
|  | 673 | local probe_cmd = "" | 
|  | 674 | probe_cmd=`_get_probe_cmd_prefix $from_net` | 
|  | 675 | 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 | 
| Nachi Ueno | 07115eb | 2013-02-26 12:38:18 -0800 | [diff] [blame] | 676 | die $LINENO "server didn't become ssh-able!" | 
| Nachi Ueno | 5db5bfa | 2012-10-29 11:25:29 -0700 | [diff] [blame] | 677 | fi | 
|  | 678 | } | 
|  | 679 |  | 
| Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 680 | # Quantum 3rd party programs | 
|  | 681 | #--------------------------- | 
| Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 682 | # please refer to lib/quantum_thirdparty/README.md for details | 
|  | 683 | QUANTUM_THIRD_PARTIES="" | 
|  | 684 | for f in $TOP_DIR/lib/quantum_thirdparty/*; do | 
|  | 685 | third_party=$(basename $f) | 
|  | 686 | if is_service_enabled $third_party; then | 
|  | 687 | source $TOP_DIR/lib/quantum_thirdparty/$third_party | 
|  | 688 | QUANTUM_THIRD_PARTIES="$QUANTUM_THIRD_PARTIES,$third_party" | 
|  | 689 | fi | 
| Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 690 | done | 
|  | 691 |  | 
| Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 692 | function _quantum_third_party_do() { | 
|  | 693 | for third_party in ${QUANTUM_THIRD_PARTIES//,/ }; do | 
|  | 694 | ${1}_${third_party} | 
|  | 695 | done | 
|  | 696 | } | 
|  | 697 |  | 
| Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 698 | # configure_quantum_third_party() - Set config files, create data dirs, etc | 
|  | 699 | function configure_quantum_third_party() { | 
| Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 700 | _quantum_third_party_do configure | 
| Nachi Ueno | 5db5bfa | 2012-10-29 11:25:29 -0700 | [diff] [blame] | 701 | } | 
|  | 702 |  | 
| Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 703 | # init_quantum_third_party() - Initialize databases, etc. | 
|  | 704 | function init_quantum_third_party() { | 
| Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 705 | _quantum_third_party_do init | 
| Nachi Ueno | 5db5bfa | 2012-10-29 11:25:29 -0700 | [diff] [blame] | 706 | } | 
|  | 707 |  | 
| Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 708 | # install_quantum_third_party() - Collect source and prepare | 
|  | 709 | function install_quantum_third_party() { | 
| Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 710 | _quantum_third_party_do install | 
| Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 711 | } | 
|  | 712 |  | 
|  | 713 | # start_quantum_third_party() - Start running processes, including screen | 
|  | 714 | function start_quantum_third_party() { | 
| Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 715 | _quantum_third_party_do start | 
| Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 716 | } | 
|  | 717 |  | 
|  | 718 | # stop_quantum_third_party - Stop running processes (non-screen) | 
|  | 719 | function stop_quantum_third_party() { | 
| Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 720 | _quantum_third_party_do stop | 
| Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 721 | } | 
|  | 722 |  | 
|  | 723 |  | 
| Salvatore Orlando | d6767d0 | 2012-08-31 04:55:20 -0700 | [diff] [blame] | 724 | # Restore xtrace | 
|  | 725 | $XTRACE |