Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # lib/neutron |
| 4 | # Install and start **Neutron** network services |
| 5 | |
| 6 | # Dependencies: |
| 7 | # |
| 8 | # ``functions`` file |
| 9 | # ``DEST`` must be defined |
| 10 | |
| 11 | # ``stack.sh`` calls the entry points in this order: |
| 12 | # |
| 13 | # - is_XXXX_enabled |
| 14 | # - install_XXXX |
| 15 | # - configure_XXXX |
| 16 | # - init_XXXX |
| 17 | # - start_XXXX |
| 18 | # - stop_XXXX |
| 19 | # - cleanup_XXXX |
| 20 | |
| 21 | # Save trace setting |
| 22 | XTRACE=$(set +o | grep xtrace) |
| 23 | set +o xtrace |
| 24 | |
| 25 | # Defaults |
| 26 | # -------- |
| 27 | |
| 28 | # Set up default directories |
| 29 | GITDIR["python-neutronclient"]=$DEST/python-neutronclient |
| 30 | |
| 31 | NEUTRON_AGENT=${NEUTRON_AGENT:-openvswitch} |
| 32 | NEUTRON_DIR=$DEST/neutron |
| 33 | NEUTRON_AUTH_CACHE_DIR=${NEUTRON_AUTH_CACHE_DIR:-/var/cache/neutron} |
| 34 | |
| 35 | NEUTRON_BIN_DIR=$(get_python_exec_prefix) |
| 36 | NEUTRON_DHCP_BINARY="neutron-dhcp-agent" |
| 37 | |
| 38 | NEUTRON_CONF_DIR=/etc/neutron |
| 39 | NEUTRON_CONF=$NEUTRON_CONF_DIR/neutron.conf |
| 40 | NEUTRON_META_CONF=$NEUTRON_CONF_DIR/metadata_agent.ini |
| 41 | |
| 42 | NEUTRON_DHCP_CONF=$NEUTRON_CONF_DIR/dhcp_agent.ini |
| 43 | NEUTRON_L3_CONF=$NEUTRON_CONF_DIR/l3_agent.ini |
| 44 | NEUTRON_AGENT_CONF=$NEUTRON_CONF_DIR/ |
| 45 | |
| 46 | NEUTRON_STATE_PATH=${NEUTRON_STATE_PATH:=$DATA_DIR/neutron} |
| 47 | NEUTRON_AUTH_CACHE_DIR=${NEUTRON_AUTH_CACHE_DIR:-/var/cache/neutron} |
| 48 | |
| 49 | # By default, use the ML2 plugin |
YAMAMOTO Takashi | 4a55d2a | 2016-08-24 15:30:09 +0900 | [diff] [blame] | 50 | NEUTRON_CORE_PLUGIN=${NEUTRON_CORE_PLUGIN:-ml2} |
| 51 | NEUTRON_CORE_PLUGIN_CONF_FILENAME=${NEUTRON_CORE_PLUGIN_CONF_FILENAME:-ml2_conf.ini} |
| 52 | NEUTRON_CORE_PLUGIN_CONF_PATH=$NEUTRON_CONF_DIR/plugins/$NEUTRON_CORE_PLUGIN |
| 53 | NEUTRON_CORE_PLUGIN_CONF=$NEUTRON_CORE_PLUGIN_CONF_PATH/$NEUTRON_CORE_PLUGIN_CONF_FILENAME |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 54 | |
| 55 | NEUTRON_AGENT_BINARY=${NEUTRON_AGENT_BINARY:-neutron-$NEUTRON_AGENT-agent} |
| 56 | NEUTRON_L3_BINARY=${NEUTRON_L3_BINARY:-neutron-l3-agent} |
| 57 | NEUTRON_META_BINARY=${NEUTRON_META_BINARY:-neutron-metadata-agent} |
| 58 | |
| 59 | # Public facing bits |
| 60 | if is_ssl_enabled_service "neutron" || is_service_enabled tls-proxy; then |
| 61 | NEUTRON_SERVICE_PROTOCOL="https" |
| 62 | fi |
| 63 | NEUTRON_SERVICE_HOST=${NEUTRON_SERVICE_HOST:-$SERVICE_HOST} |
| 64 | NEUTRON_SERVICE_PORT=${NEUTRON_SERVICE_PORT:-9696} |
| 65 | NEUTRON_SERVICE_PORT_INT=${NEUTRON_SERVICE_PORT_INT:-19696} |
| 66 | NEUTRON_SERVICE_PROTOCOL=${NEUTRON_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL} |
| 67 | |
| 68 | NEUTRON_AUTH_STRATEGY=${NEUTRON_AUTH_STRATEGY:-keystone} |
| 69 | NEUTRON_ROOTWRAP=$(get_rootwrap_location neutron) |
| 70 | NEUTRON_ROOTWRAP_CONF_FILE=$NEUTRON_CONF_DIR/rootwrap.conf |
| 71 | NEUTRON_ROOTWRAP_DAEMON_CMD="sudo $NEUTRON_ROOTWRAP-daemon $NEUTRON_ROOTWRAP_CONF_FILE" |
| 72 | |
YAMAMOTO Takashi | eede9dd | 2016-07-15 10:27:53 +0900 | [diff] [blame] | 73 | # Additional neutron api config files |
| 74 | declare -a _NEUTRON_SERVER_EXTRA_CONF_FILES_ABS |
| 75 | |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 76 | # Functions |
| 77 | # --------- |
| 78 | |
| 79 | # Test if any Neutron services are enabled |
| 80 | # is_neutron_enabled |
| 81 | function is_neutron_enabled { |
| 82 | [[ ,${ENABLED_SERVICES} =~ ,"neutron-" || ,${ENABLED_SERVICES} =~ ,"q-" ]] && return 0 |
| 83 | return 1 |
| 84 | } |
| 85 | |
| 86 | # Test if any Neutron services are enabled |
| 87 | # is_neutron_enabled |
| 88 | function is_neutron_legacy_enabled { |
| 89 | [[ ,${ENABLED_SERVICES} =~ ,"q-" ]] && return 0 |
| 90 | return 1 |
| 91 | } |
| 92 | |
YAMAMOTO Takashi | c74315e | 2016-07-21 17:49:43 +0900 | [diff] [blame] | 93 | if is_neutron_legacy_enabled; then |
| 94 | source $TOP_DIR/lib/neutron-legacy |
| 95 | fi |
| 96 | |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 97 | # cleanup_neutron() - Remove residual data files, anything left over from previous |
| 98 | # runs that a clean run would need to clean up |
| 99 | function cleanup_neutron_new { |
| 100 | source $TOP_DIR/lib/neutron_plugins/${NEUTRON_AGENT}_agent |
| 101 | if is_neutron_ovs_base_plugin; then |
| 102 | neutron_ovs_base_cleanup |
| 103 | fi |
| 104 | |
| 105 | if [[ $NEUTRON_AGENT == "linuxbridge" ]]; then |
| 106 | neutron_lb_cleanup |
| 107 | fi |
| 108 | # delete all namespaces created by neutron |
| 109 | for ns in $(sudo ip netns list | grep -o -E '(qdhcp|qrouter|qlbaas|fip|snat)-[0-9a-f-]*'); do |
| 110 | sudo ip netns delete ${ns} |
| 111 | done |
| 112 | } |
| 113 | |
| 114 | # configure_neutron() - Set config files, create data dirs, etc |
| 115 | function configure_neutron_new { |
| 116 | sudo install -d -o $STACK_USER $NEUTRON_CONF_DIR |
| 117 | |
| 118 | (cd $NEUTRON_DIR && exec ./tools/generate_config_file_samples.sh) |
| 119 | |
| 120 | cp $NEUTRON_DIR/etc/neutron.conf.sample $NEUTRON_CONF |
| 121 | |
| 122 | configure_neutron_rootwrap |
| 123 | |
YAMAMOTO Takashi | 4a55d2a | 2016-08-24 15:30:09 +0900 | [diff] [blame] | 124 | mkdir -p $NEUTRON_CORE_PLUGIN_CONF_PATH |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 125 | |
YAMAMOTO Takashi | 4a55d2a | 2016-08-24 15:30:09 +0900 | [diff] [blame] | 126 | cp $NEUTRON_DIR/etc/neutron/plugins/$NEUTRON_CORE_PLUGIN/$NEUTRON_CORE_PLUGIN_CONF_FILENAME.sample $NEUTRON_CORE_PLUGIN_CONF |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 127 | |
| 128 | iniset $NEUTRON_CONF database connection `database_connection_url neutron` |
| 129 | iniset $NEUTRON_CONF DEFAULT state_path $NEUTRON_STATE_PATH |
| 130 | iniset $NEUTRON_CONF oslo_concurrency lock_path $NEUTRON_STATE_PATH/lock |
| 131 | iniset $NEUTRON_CONF DEFAULT use_syslog $SYSLOG |
| 132 | |
Gary Kotton | d2ef615 | 2016-09-20 04:12:11 -0700 | [diff] [blame] | 133 | iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL |
Sean M. Collins | fbba3b9 | 2016-05-12 11:17:53 -0400 | [diff] [blame] | 134 | |
Sean M. Collins | 5394cc1 | 2016-05-11 15:03:38 -0400 | [diff] [blame] | 135 | iniset_rpc_backend neutron $NEUTRON_CONF |
| 136 | |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 137 | # Neutron API server & Neutron plugin |
| 138 | if is_service_enabled neutron-api; then |
| 139 | local policy_file=$NEUTRON_CONF_DIR/policy.json |
| 140 | cp $NEUTRON_DIR/etc/policy.json $policy_file |
| 141 | # Allow neutron user to administer neutron to match neutron account |
| 142 | sed -i 's/"context_is_admin": "role:admin"/"context_is_admin": "role:admin or user_name:neutron"/g' $policy_file |
| 143 | |
| 144 | cp $NEUTRON_DIR/etc/api-paste.ini $NEUTRON_CONF_DIR/api-paste.ini |
| 145 | |
YAMAMOTO Takashi | 4a55d2a | 2016-08-24 15:30:09 +0900 | [diff] [blame] | 146 | iniset $NEUTRON_CONF DEFAULT core_plugin $NEUTRON_CORE_PLUGIN |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 147 | |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 148 | iniset $NEUTRON_CONF DEFAULT policy_file $policy_file |
| 149 | iniset $NEUTRON_CONF DEFAULT allow_overlapping_ips True |
| 150 | |
| 151 | iniset $NEUTRON_CONF DEFAULT auth_strategy $NEUTRON_AUTH_STRATEGY |
| 152 | configure_auth_token_middleware $NEUTRON_CONF neutron $NEUTRON_AUTH_CACHE_DIR keystone_authtoken |
Ihar Hrachyshka | 0ce4ba9 | 2017-02-24 05:13:53 +0000 | [diff] [blame] | 153 | configure_auth_token_middleware $NEUTRON_CONF nova $NEUTRON_AUTH_CACHE_DIR nova |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 154 | |
| 155 | # Configure VXLAN |
| 156 | # TODO(sc68cal) not hardcode? |
YAMAMOTO Takashi | 4a55d2a | 2016-08-24 15:30:09 +0900 | [diff] [blame] | 157 | iniset $NEUTRON_CORE_PLUGIN_CONF ml2 tenant_network_types vxlan |
YAMAMOTO Takashi | 4a55d2a | 2016-08-24 15:30:09 +0900 | [diff] [blame] | 158 | iniset $NEUTRON_CORE_PLUGIN_CONF ml2 mechanism_drivers openvswitch,linuxbridge |
| 159 | iniset $NEUTRON_CORE_PLUGIN_CONF ml2_type_vxlan vni_ranges 1001:2000 |
Sean M. Collins | edcb7e5 | 2016-12-15 11:29:28 -0500 | [diff] [blame] | 160 | iniset $NEUTRON_CORE_PLUGIN_CONF ml2_type_flat flat_networks public |
Matt Riedemann | c9c9d31 | 2016-09-15 20:33:22 -0400 | [diff] [blame] | 161 | if [[ "$NEUTRON_PORT_SECURITY" = "True" ]]; then |
| 162 | iniset $NEUTRON_CORE_PLUGIN_CONF ml2 extension_drivers port_security |
| 163 | fi |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 164 | fi |
| 165 | |
| 166 | # Neutron OVS or LB agent |
| 167 | if is_service_enabled neutron-agent; then |
YAMAMOTO Takashi | 4a55d2a | 2016-08-24 15:30:09 +0900 | [diff] [blame] | 168 | iniset $NEUTRON_CORE_PLUGIN_CONF agent tunnel_types vxlan |
| 169 | iniset $NEUTRON_CORE_PLUGIN_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 170 | |
| 171 | # Configure the neutron agent |
| 172 | if [[ $NEUTRON_AGENT == "linuxbridge" ]]; then |
Sean M. Collins | edcb7e5 | 2016-12-15 11:29:28 -0500 | [diff] [blame] | 173 | iniset $NEUTRON_CORE_PLUGIN_CONF securitygroup firewall_driver iptables |
YAMAMOTO Takashi | 4a55d2a | 2016-08-24 15:30:09 +0900 | [diff] [blame] | 174 | iniset $NEUTRON_CORE_PLUGIN_CONF vxlan local_ip $HOST_IP |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 175 | else |
Sean M. Collins | edcb7e5 | 2016-12-15 11:29:28 -0500 | [diff] [blame] | 176 | iniset $NEUTRON_CORE_PLUGIN_CONF securitygroup firewall_driver iptables_hybrid |
YAMAMOTO Takashi | 4a55d2a | 2016-08-24 15:30:09 +0900 | [diff] [blame] | 177 | iniset $NEUTRON_CORE_PLUGIN_CONF ovs local_ip $HOST_IP |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 178 | fi |
Ihar Hrachyshka | b3a210f | 2016-09-29 13:26:30 +0000 | [diff] [blame] | 179 | |
Denis Buliga | 0bf75a4 | 2017-02-06 16:56:46 +0200 | [diff] [blame] | 180 | if ! running_in_container; then |
| 181 | enable_kernel_bridge_firewall |
| 182 | fi |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 183 | fi |
| 184 | |
| 185 | # DHCP Agent |
| 186 | if is_service_enabled neutron-dhcp; then |
| 187 | cp $NEUTRON_DIR/etc/dhcp_agent.ini.sample $NEUTRON_DHCP_CONF |
| 188 | |
Gary Kotton | d2ef615 | 2016-09-20 04:12:11 -0700 | [diff] [blame] | 189 | iniset $NEUTRON_DHCP_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL |
Sean Dague | 78801c1 | 2016-08-04 14:10:07 -0400 | [diff] [blame] | 190 | # make it so we have working DNS from guests |
| 191 | iniset $NEUTRON_DHCP_CONF DEFAULT dnsmasq_local_resolv True |
| 192 | |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 193 | iniset $NEUTRON_DHCP_CONF agent root_helper_daemon "$NEUTRON_ROOTWRAP_DAEMON_CMD" |
| 194 | iniset $NEUTRON_DHCP_CONF DEFAULT interface_driver $NEUTRON_AGENT |
| 195 | neutron_plugin_configure_dhcp_agent $NEUTRON_DHCP_CONF |
| 196 | fi |
| 197 | |
| 198 | if is_service_enabled neutron-l3; then |
| 199 | cp $NEUTRON_DIR/etc/l3_agent.ini.sample $NEUTRON_L3_CONF |
| 200 | iniset $NEUTRON_L3_CONF DEFAULT interface_driver $NEUTRON_AGENT |
YAMAMOTO Takashi | d9ec420 | 2016-07-21 16:14:52 +0900 | [diff] [blame] | 201 | neutron_service_plugin_class_add router |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 202 | iniset $NEUTRON_L3_CONF agent root_helper_daemon "$NEUTRON_ROOTWRAP_DAEMON_CMD" |
Gary Kotton | d2ef615 | 2016-09-20 04:12:11 -0700 | [diff] [blame] | 203 | iniset $NEUTRON_L3_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 204 | neutron_plugin_configure_l3_agent $NEUTRON_L3_CONF |
| 205 | fi |
| 206 | |
| 207 | # Metadata |
Sean M. Collins | 1cd2828 | 2016-05-11 15:07:19 -0400 | [diff] [blame] | 208 | if is_service_enabled neutron-metadata-agent; then |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 209 | cp $NEUTRON_DIR/etc/metadata_agent.ini.sample $NEUTRON_META_CONF |
| 210 | |
Gary Kotton | d2ef615 | 2016-09-20 04:12:11 -0700 | [diff] [blame] | 211 | iniset $NEUTRON_META_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 212 | iniset $NEUTRON_META_CONF DEFAULT nova_metadata_ip $SERVICE_HOST |
Armando Migliaccio | 06f2ea2 | 2017-02-02 16:47:00 -0800 | [diff] [blame] | 213 | iniset $NEUTRON_META_CONF DEFAULT metadata_workers $API_WORKERS |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 214 | iniset $NEUTRON_META_CONF agent root_helper_daemon "$NEUTRON_ROOTWRAP_DAEMON_CMD" |
| 215 | |
| 216 | # TODO(dtroyer): remove the v2.0 hard code below |
| 217 | iniset $NEUTRON_META_CONF DEFAULT auth_url $KEYSTONE_SERVICE_URI/v2.0 |
| 218 | configure_auth_token_middleware $NEUTRON_META_CONF neutron $NEUTRON_AUTH_CACHE_DIR DEFAULT |
| 219 | fi |
| 220 | |
| 221 | # Format logging |
| 222 | if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then |
| 223 | setup_colorized_logging $NEUTRON_CONF DEFAULT project_id |
| 224 | else |
| 225 | # Show user_name and project_name by default |
| 226 | iniset $NEUTRON_CONF DEFAULT logging_context_format_string "%(asctime)s.%(msecs)03d %(levelname)s %(name)s [%(request_id)s %(user_name)s %(project_name)s] %(instance)s%(message)s" |
| 227 | fi |
| 228 | |
| 229 | if is_service_enabled tls-proxy; then |
| 230 | # Set the service port for a proxy to take the original |
| 231 | iniset $NEUTRON_CONF DEFAULT bind_port "$NEUTRON_SERVICE_PORT_INT" |
| 232 | fi |
| 233 | |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 234 | if is_ssl_enabled_service "neutron"; then |
| 235 | ensure_certificates NEUTRON |
| 236 | |
| 237 | iniset $NEUTRON_CONF DEFAULT use_ssl True |
| 238 | iniset $NEUTRON_CONF DEFAULT ssl_cert_file "$NEUTRON_SSL_CERT" |
| 239 | iniset $NEUTRON_CONF DEFAULT ssl_key_file "$NEUTRON_SSL_KEY" |
| 240 | fi |
| 241 | |
Sean M. Collins | 8063fee | 2016-05-24 11:27:36 -0700 | [diff] [blame] | 242 | # Metering |
| 243 | if is_service_enabled neutron-metering; then |
Sean M. Collins | 60f394a | 2016-06-17 16:15:30 -0400 | [diff] [blame] | 244 | source $TOP_DIR/lib/neutron_plugins/services/metering |
Sean M. Collins | 8063fee | 2016-05-24 11:27:36 -0700 | [diff] [blame] | 245 | neutron_agent_metering_configure_common |
| 246 | neutron_agent_metering_configure_agent |
YAMAMOTO Takashi | d9ec420 | 2016-07-21 16:14:52 +0900 | [diff] [blame] | 247 | neutron_service_plugin_class_add metering |
Sean M. Collins | 8063fee | 2016-05-24 11:27:36 -0700 | [diff] [blame] | 248 | fi |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | # configure_neutron_rootwrap() - configure Neutron's rootwrap |
| 252 | function configure_neutron_rootwrap { |
| 253 | # Set the paths of certain binaries |
| 254 | neutron_rootwrap=$(get_rootwrap_location neutron) |
| 255 | |
| 256 | # Specify ``rootwrap.conf`` as first parameter to neutron-rootwrap |
| 257 | local rootwrap_sudoer_cmd="${neutron_rootwrap} $NEUTRON_CONF_DIR/rootwrap.conf" |
| 258 | |
| 259 | # Deploy new rootwrap filters files (owned by root). |
| 260 | # Wipe any existing rootwrap.d files first |
| 261 | if [[ -d $NEUTRON_CONF_DIR/rootwrap.d ]]; then |
| 262 | sudo rm -rf $NEUTRON_CONF_DIR/rootwrap.d |
| 263 | fi |
| 264 | |
| 265 | # Deploy filters to /etc/neutron/rootwrap.d |
| 266 | sudo install -d -o root -g root -m 755 $NEUTRON_CONF_DIR/rootwrap.d |
| 267 | sudo install -o root -g root -m 644 $NEUTRON_DIR/etc/neutron/rootwrap.d/*.filters $NEUTRON_CONF_DIR/rootwrap.d |
| 268 | |
| 269 | # Set up ``rootwrap.conf``, pointing to ``$NEUTRON_CONF_DIR/rootwrap.d`` |
| 270 | sudo install -o root -g root -m 644 $NEUTRON_DIR/etc/rootwrap.conf $NEUTRON_CONF_DIR |
| 271 | sudo sed -e "s:^filters_path=.*$:filters_path=$NEUTRON_CONF_DIR/rootwrap.d:" -i $NEUTRON_CONF_DIR/rootwrap.conf |
| 272 | |
| 273 | # Set up the rootwrap sudoers for Neutron |
| 274 | tempfile=`mktemp` |
| 275 | echo "$STACK_USER ALL=(root) NOPASSWD: $rootwrap_sudoer_cmd *" >$tempfile |
| 276 | chmod 0440 $tempfile |
| 277 | sudo chown root:root $tempfile |
| 278 | sudo mv $tempfile /etc/sudoers.d/neutron-rootwrap |
| 279 | } |
| 280 | |
| 281 | # Make Neutron-required changes to nova.conf |
| 282 | function configure_neutron_nova_new { |
| 283 | iniset $NOVA_CONF DEFAULT use_neutron True |
| 284 | iniset $NOVA_CONF neutron auth_type "password" |
Brant Knudson | c2c89e4 | 2017-02-23 20:15:47 -0600 | [diff] [blame^] | 285 | iniset $NOVA_CONF neutron auth_url "$KEYSTONE_SERVICE_URI/v3" |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 286 | iniset $NOVA_CONF neutron username neutron |
| 287 | iniset $NOVA_CONF neutron password "$SERVICE_PASSWORD" |
| 288 | iniset $NOVA_CONF neutron user_domain_name "Default" |
| 289 | iniset $NOVA_CONF neutron project_name "$SERVICE_TENANT_NAME" |
| 290 | iniset $NOVA_CONF neutron project_domain_name "Default" |
| 291 | iniset $NOVA_CONF neutron auth_strategy $NEUTRON_AUTH_STRATEGY |
| 292 | iniset $NOVA_CONF neutron region_name "$REGION_NAME" |
| 293 | iniset $NOVA_CONF neutron url $NEUTRON_SERVICE_PROTOCOL://$NEUTRON_SERVICE_HOST:$NEUTRON_SERVICE_PORT |
| 294 | |
| 295 | iniset $NOVA_CONF DEFAULT firewall_driver nova.virt.firewall.NoopFirewallDriver |
| 296 | |
Gary Kotton | 88f8558 | 2016-08-14 06:55:42 -0700 | [diff] [blame] | 297 | # optionally set options in nova_conf |
| 298 | neutron_plugin_create_nova_conf |
| 299 | |
Sean M. Collins | 1cd2828 | 2016-05-11 15:07:19 -0400 | [diff] [blame] | 300 | if is_service_enabled neutron-metadata-agent; then |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 301 | iniset $NOVA_CONF neutron service_metadata_proxy "True" |
| 302 | fi |
| 303 | |
| 304 | } |
| 305 | |
| 306 | # Tenant User Roles |
| 307 | # ------------------------------------------------------------------ |
| 308 | # service neutron admin # if enabled |
| 309 | |
| 310 | # create_neutron_accounts() - Create required service accounts |
| 311 | function create_neutron_accounts_new { |
| 312 | if [[ "$ENABLED_SERVICES" =~ "neutron-api" ]]; then |
| 313 | |
| 314 | create_service_user "neutron" |
| 315 | |
| 316 | neutron_service=$(get_or_create_service "neutron" \ |
| 317 | "network" "Neutron Service") |
| 318 | get_or_create_endpoint $neutron_service \ |
| 319 | "$REGION_NAME" \ |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 320 | "$NEUTRON_SERVICE_PROTOCOL://$NEUTRON_SERVICE_HOST:$NEUTRON_SERVICE_PORT/" |
| 321 | fi |
| 322 | } |
| 323 | |
| 324 | # create_neutron_cache_dir() - Part of the init_neutron() process |
| 325 | function create_neutron_cache_dir { |
| 326 | # Create cache dir |
| 327 | sudo install -d -o $STACK_USER $NEUTRON_AUTH_CACHE_DIR |
| 328 | rm -f $NEUTRON_AUTH_CACHE_DIR/* |
| 329 | } |
| 330 | |
| 331 | # init_neutron() - Initialize databases, etc. |
| 332 | function init_neutron_new { |
| 333 | |
| 334 | recreate_database neutron |
| 335 | |
| 336 | # Run Neutron db migrations |
Ihar Hrachyshka | 19f4b3f | 2017-02-23 20:44:18 +0000 | [diff] [blame] | 337 | $NEUTRON_BIN_DIR/neutron-db-manage upgrade heads |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 338 | |
| 339 | create_neutron_cache_dir |
| 340 | } |
| 341 | |
| 342 | # install_neutron() - Collect source and prepare |
| 343 | function install_neutron_new { |
| 344 | git_clone $NEUTRON_REPO $NEUTRON_DIR $NEUTRON_BRANCH |
| 345 | setup_develop $NEUTRON_DIR |
| 346 | |
| 347 | # Install neutron-lib from git so we make sure we're testing |
| 348 | # the latest code. |
| 349 | if use_library_from_git "neutron-lib"; then |
| 350 | git_clone_by_name "neutron-lib" |
| 351 | setup_dev_lib "neutron-lib" |
| 352 | fi |
| 353 | |
| 354 | # L3 service requires radvd |
| 355 | if is_service_enabled neutron-l3; then |
| 356 | install_package radvd |
| 357 | fi |
| 358 | |
| 359 | if is_service_enabled neutron-agent neutron-dhcp neutron-l3; then |
| 360 | #TODO(sc68cal) - kind of ugly |
| 361 | source $TOP_DIR/lib/neutron_plugins/${NEUTRON_AGENT}_agent |
| 362 | neutron_plugin_install_agent_packages |
| 363 | fi |
| 364 | |
| 365 | } |
| 366 | |
| 367 | # install_neutronclient() - Collect source and prepare |
| 368 | function install_neutronclient { |
| 369 | if use_library_from_git "python-neutronclient"; then |
| 370 | git_clone_by_name "python-neutronclient" |
| 371 | setup_dev_lib "python-neutronclient" |
| 372 | sudo install -D -m 0644 -o $STACK_USER {${GITDIR["python-neutronclient"]}/tools/,/etc/bash_completion.d/}neutron.bash_completion |
| 373 | fi |
| 374 | } |
| 375 | |
| 376 | # start_neutron_api() - Start the API process ahead of other things |
| 377 | function start_neutron_api { |
| 378 | local service_port=$NEUTRON_SERVICE_PORT |
| 379 | local service_protocol=$NEUTRON_SERVICE_PROTOCOL |
| 380 | if is_service_enabled tls-proxy; then |
| 381 | service_port=$NEUTRON_SERVICE_PORT_INT |
| 382 | service_protocol="http" |
| 383 | fi |
| 384 | |
YAMAMOTO Takashi | ed887d8 | 2017-02-22 14:21:33 -0500 | [diff] [blame] | 385 | local opts="" |
| 386 | opts+=" --config-file $NEUTRON_CONF" |
| 387 | opts+=" --config-file $NEUTRON_CORE_PLUGIN_CONF" |
YAMAMOTO Takashi | eede9dd | 2016-07-15 10:27:53 +0900 | [diff] [blame] | 388 | local cfg_file |
| 389 | for cfg_file in ${_NEUTRON_SERVER_EXTRA_CONF_FILES_ABS[@]}; do |
| 390 | opts+=" --config-file $cfg_file" |
| 391 | done |
| 392 | |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 393 | # Start the Neutron service |
| 394 | # TODO(sc68cal) Stop hard coding this |
YAMAMOTO Takashi | ed887d8 | 2017-02-22 14:21:33 -0500 | [diff] [blame] | 395 | run_process neutron-api "$NEUTRON_BIN_DIR/neutron-server $opts" |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 396 | |
| 397 | if is_ssl_enabled_service "neutron"; then |
| 398 | ssl_ca="--ca-certificate=${SSL_BUNDLE_FILE}" |
| 399 | local testcmd="wget ${ssl_ca} --no-proxy -q -O- $service_protocol://$NEUTRON_SERVICE_HOST:$service_port" |
| 400 | test_with_retry "$testcmd" "Neutron did not start" $SERVICE_TIMEOUT |
| 401 | else |
| 402 | if ! wait_for_service $SERVICE_TIMEOUT $service_protocol://$NEUTRON_SERVICE_HOST:$service_port; then |
| 403 | die $LINENO "neutron-api did not start" |
| 404 | fi |
| 405 | fi |
| 406 | |
| 407 | |
| 408 | # Start proxy if enabled |
| 409 | if is_service_enabled tls-proxy; then |
Gregory Haynes | 4b49e40 | 2016-08-31 18:19:51 -0700 | [diff] [blame] | 410 | start_tls_proxy neutron '*' $NEUTRON_SERVICE_PORT $NEUTRON_SERVICE_HOST $NEUTRON_SERVICE_PORT_INT |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 411 | fi |
| 412 | } |
| 413 | |
| 414 | # start_neutron() - Start running processes, including screen |
| 415 | function start_neutron_new { |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 416 | # Start up the neutron agents if enabled |
| 417 | # TODO(sc68cal) Make this pluggable so different DevStack plugins for different Neutron plugins |
| 418 | # can resolve the $NEUTRON_AGENT_BINARY |
| 419 | if is_service_enabled neutron-agent; then |
Ihar Hrachyshka | 19f4b3f | 2017-02-23 20:44:18 +0000 | [diff] [blame] | 420 | # TODO(ihrachys) stop loading ml2_conf.ini into agents, instead load agent specific files |
| 421 | run_process neutron-agent "$NEUTRON_BIN_DIR/$NEUTRON_AGENT_BINARY --config-file $NEUTRON_CONF --config-file $NEUTRON_CORE_PLUGIN_CONF" |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 422 | fi |
| 423 | if is_service_enabled neutron-dhcp; then |
| 424 | neutron_plugin_configure_dhcp_agent $NEUTRON_DHCP_CONF |
Ihar Hrachyshka | 19f4b3f | 2017-02-23 20:44:18 +0000 | [diff] [blame] | 425 | run_process neutron-dhcp "$NEUTRON_BIN_DIR/$NEUTRON_DHCP_BINARY --config-file $NEUTRON_CONF --config-file $NEUTRON_DHCP_CONF" |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 426 | fi |
| 427 | if is_service_enabled neutron-l3; then |
Ihar Hrachyshka | 19f4b3f | 2017-02-23 20:44:18 +0000 | [diff] [blame] | 428 | run_process neutron-l3 "$NEUTRON_BIN_DIR/$NEUTRON_L3_BINARY --config-file $NEUTRON_CONF --config-file $NEUTRON_L3_CONF" |
YAMAMOTO Takashi | c07170a | 2016-07-20 19:44:05 +0900 | [diff] [blame] | 429 | fi |
YAMAMOTO Takashi | 07edde1 | 2016-10-19 19:21:00 +0000 | [diff] [blame] | 430 | if is_service_enabled neutron-api; then |
| 431 | # XXX(sc68cal) - Here's where plugins can wire up their own networks instead |
| 432 | # of the code in lib/neutron_plugins/services/l3 |
| 433 | if type -p neutron_plugin_create_initial_networks > /dev/null; then |
| 434 | neutron_plugin_create_initial_networks |
| 435 | else |
| 436 | # XXX(sc68cal) Load up the built in Neutron networking code and build a topology |
| 437 | source $TOP_DIR/lib/neutron_plugins/services/l3 |
| 438 | # Create the networks using servic |
| 439 | create_neutron_initial_network |
| 440 | fi |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 441 | fi |
Sean M. Collins | 1cd2828 | 2016-05-11 15:07:19 -0400 | [diff] [blame] | 442 | if is_service_enabled neutron-metadata-agent; then |
Ihar Hrachyshka | 19f4b3f | 2017-02-23 20:44:18 +0000 | [diff] [blame] | 443 | run_process neutron-metadata-agent "$NEUTRON_BIN_DIR/$NEUTRON_META_BINARY --config-file $NEUTRON_CONF --config-file $NEUTRON_META_CONF" |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 444 | fi |
Sean M. Collins | 8063fee | 2016-05-24 11:27:36 -0700 | [diff] [blame] | 445 | |
| 446 | if is_service_enabled neutron-metering; then |
| 447 | run_process neutron-metering "$AGENT_METERING_BINARY --config-file $NEUTRON_CONF --config-file $METERING_AGENT_CONF_FILENAME" |
| 448 | fi |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | # stop_neutron() - Stop running processes (non-screen) |
| 452 | function stop_neutron_new { |
| 453 | for serv in neutron-api neutron-agent neutron-l3; do |
| 454 | stop_process $serv |
| 455 | done |
| 456 | |
| 457 | if is_service_enabled neutron-dhcp; then |
| 458 | stop_process neutron-dhcp |
| 459 | pid=$(ps aux | awk '/[d]nsmasq.+interface=(tap|ns-)/ { print $2 }') |
| 460 | [ ! -z "$pid" ] && sudo kill -9 $pid |
| 461 | fi |
| 462 | |
Sean M. Collins | 1cd2828 | 2016-05-11 15:07:19 -0400 | [diff] [blame] | 463 | if is_service_enabled neutron-metadata-agent; then |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 464 | sudo pkill -9 -f neutron-ns-metadata-proxy || : |
Sean M. Collins | 1cd2828 | 2016-05-11 15:07:19 -0400 | [diff] [blame] | 465 | stop_process neutron-metadata-agent |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 466 | fi |
| 467 | } |
| 468 | |
YAMAMOTO Takashi | d9ec420 | 2016-07-21 16:14:52 +0900 | [diff] [blame] | 469 | # neutron_service_plugin_class_add() - add service plugin class |
| 470 | function neutron_service_plugin_class_add_new { |
| 471 | local service_plugin_class=$1 |
| 472 | local plugins="" |
| 473 | |
| 474 | plugins=$(iniget $NEUTRON_CONF DEFAULT service_plugins) |
YAMAMOTO Takashi | 84e45c9 | 2017-02-22 14:25:14 -0500 | [diff] [blame] | 475 | if [ $plugins ]; then |
| 476 | plugins+="," |
| 477 | fi |
| 478 | plugins+="${service_plugin_class}" |
YAMAMOTO Takashi | d9ec420 | 2016-07-21 16:14:52 +0900 | [diff] [blame] | 479 | iniset $NEUTRON_CONF DEFAULT service_plugins $plugins |
| 480 | } |
| 481 | |
YAMAMOTO Takashi | eede9dd | 2016-07-15 10:27:53 +0900 | [diff] [blame] | 482 | function neutron_server_config_add_new { |
| 483 | _NEUTRON_SERVER_EXTRA_CONF_FILES_ABS+=($1) |
| 484 | } |
| 485 | |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 486 | # Dispatch functions |
| 487 | # These are needed for compatibility between the old and new implementations |
| 488 | # where there are function name overlaps. These will be removed when |
| 489 | # neutron-legacy is removed. |
| 490 | # TODO(sc68cal) Remove when neutron-legacy is no more. |
| 491 | function cleanup_neutron { |
| 492 | if is_neutron_legacy_enabled; then |
| 493 | # Call back to old function |
| 494 | cleanup_mutnauq "$@" |
| 495 | else |
| 496 | cleanup_neutron_new "$@" |
| 497 | fi |
| 498 | } |
| 499 | |
| 500 | function configure_neutron { |
| 501 | if is_neutron_legacy_enabled; then |
| 502 | # Call back to old function |
| 503 | configure_mutnauq "$@" |
| 504 | else |
| 505 | configure_neutron_new "$@" |
| 506 | fi |
| 507 | } |
| 508 | |
| 509 | function configure_neutron_nova { |
| 510 | if is_neutron_legacy_enabled; then |
| 511 | # Call back to old function |
| 512 | create_nova_conf_neutron "$@" |
| 513 | else |
| 514 | configure_neutron_nova_new "$@" |
| 515 | fi |
| 516 | } |
| 517 | |
| 518 | function create_neutron_accounts { |
| 519 | if is_neutron_legacy_enabled; then |
| 520 | # Call back to old function |
| 521 | create_mutnauq_accounts "$@" |
| 522 | else |
| 523 | create_neutron_accounts_new "$@" |
| 524 | fi |
| 525 | } |
| 526 | |
| 527 | function init_neutron { |
| 528 | if is_neutron_legacy_enabled; then |
| 529 | # Call back to old function |
| 530 | init_mutnauq "$@" |
| 531 | else |
| 532 | init_neutron_new "$@" |
| 533 | fi |
| 534 | } |
| 535 | |
| 536 | function install_neutron { |
| 537 | if is_neutron_legacy_enabled; then |
| 538 | # Call back to old function |
| 539 | install_mutnauq "$@" |
| 540 | else |
| 541 | install_neutron_new "$@" |
| 542 | fi |
| 543 | } |
| 544 | |
YAMAMOTO Takashi | d9ec420 | 2016-07-21 16:14:52 +0900 | [diff] [blame] | 545 | function neutron_service_plugin_class_add { |
| 546 | if is_neutron_legacy_enabled; then |
| 547 | # Call back to old function |
| 548 | _neutron_service_plugin_class_add "$@" |
| 549 | else |
| 550 | neutron_service_plugin_class_add_new "$@" |
| 551 | fi |
| 552 | } |
| 553 | |
YAMAMOTO Takashi | c74315e | 2016-07-21 17:49:43 +0900 | [diff] [blame] | 554 | function install_neutron_agent_packages { |
| 555 | if is_neutron_legacy_enabled; then |
| 556 | # Call back to old function |
| 557 | install_neutron_agent_packages_mutnauq "$@" |
| 558 | else |
| 559 | : |
| 560 | fi |
| 561 | } |
| 562 | |
YAMAMOTO Takashi | eede9dd | 2016-07-15 10:27:53 +0900 | [diff] [blame] | 563 | function neutron_server_config_add { |
| 564 | if is_neutron_legacy_enabled; then |
| 565 | # Call back to old function |
| 566 | mutnauq_server_config_add "$@" |
| 567 | else |
| 568 | neutron_server_config_add_new "$@" |
| 569 | fi |
| 570 | } |
| 571 | |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 572 | function start_neutron { |
| 573 | if is_neutron_legacy_enabled; then |
| 574 | # Call back to old function |
| 575 | start_mutnauq_l2_agent "$@" |
| 576 | start_mutnauq_other_agents "$@" |
| 577 | else |
| 578 | start_neutron_new "$@" |
| 579 | fi |
| 580 | } |
| 581 | |
| 582 | function stop_neutron { |
| 583 | if is_neutron_legacy_enabled; then |
| 584 | # Call back to old function |
| 585 | stop_mutnauq "$@" |
| 586 | else |
| 587 | stop_neutron_new "$@" |
| 588 | fi |
| 589 | } |
| 590 | |
| 591 | # Restore xtrace |
| 592 | $XTRACE |