System for quickly installing an OpenStack cloud from upstream git for testing and development.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

neutron 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  1. #!/bin/bash
  2. #
  3. # lib/neutron
  4. # Install and start **Neutron** network services
  5. # Dependencies:
  6. #
  7. # ``functions`` file
  8. # ``DEST`` must be defined
  9. # ``stack.sh`` calls the entry points in this order:
  10. #
  11. # - is_XXXX_enabled
  12. # - install_XXXX
  13. # - configure_XXXX
  14. # - init_XXXX
  15. # - start_XXXX
  16. # - stop_XXXX
  17. # - cleanup_XXXX
  18. # Save trace setting
  19. XTRACE=$(set +o | grep xtrace)
  20. set +o xtrace
  21. # Defaults
  22. # --------
  23. # Set up default directories
  24. GITDIR["python-neutronclient"]=$DEST/python-neutronclient
  25. # NEUTRON_DEPLOY_MOD_WSGI defines how neutron is deployed, allowed values:
  26. # - False (default) : Run neutron under Eventlet
  27. # - True : Run neutron under uwsgi
  28. # TODO(annp): Switching to uwsgi in next cycle if things turn out to be stable
  29. # enough
  30. NEUTRON_DEPLOY_MOD_WSGI=$(trueorfalse False NEUTRON_DEPLOY_MOD_WSGI)
  31. NEUTRON_AGENT=${NEUTRON_AGENT:-openvswitch}
  32. NEUTRON_DIR=$DEST/neutron
  33. NEUTRON_DISTRIBUTED_ROUTING=$(trueorfalse False NEUTRON_DISTRIBUTED_ROUTING)
  34. # Distributed Virtual Router (DVR) configuration
  35. # Can be:
  36. # - ``legacy`` - No DVR functionality
  37. # - ``dvr_snat`` - Controller or single node DVR
  38. # - ``dvr`` - Compute node in multi-node DVR
  39. # - ``dvr_no_external`` - Compute node in multi-node DVR, no external network
  40. #
  41. # Default is 'dvr_snat' since it can handle both DVR and legacy routers
  42. NEUTRON_DVR_MODE=${NEUTRON_DVR_MODE:-dvr_snat}
  43. NEUTRON_BIN_DIR=$(get_python_exec_prefix)
  44. NEUTRON_DHCP_BINARY="neutron-dhcp-agent"
  45. NEUTRON_CONF_DIR=/etc/neutron
  46. NEUTRON_CONF=$NEUTRON_CONF_DIR/neutron.conf
  47. NEUTRON_META_CONF=$NEUTRON_CONF_DIR/metadata_agent.ini
  48. NEUTRON_META_DATA_HOST=${NEUTRON_META_DATA_HOST:-$(ipv6_unquote $SERVICE_HOST)}
  49. NEUTRON_DHCP_CONF=$NEUTRON_CONF_DIR/dhcp_agent.ini
  50. NEUTRON_L3_CONF=$NEUTRON_CONF_DIR/l3_agent.ini
  51. NEUTRON_AGENT_CONF=$NEUTRON_CONF_DIR/
  52. NEUTRON_CREATE_INITIAL_NETWORKS=${NEUTRON_CREATE_INITIAL_NETWORKS:-True}
  53. NEUTRON_STATE_PATH=${NEUTRON_STATE_PATH:=$DATA_DIR/neutron}
  54. NEUTRON_UWSGI_CONF=$NEUTRON_CONF_DIR/neutron-api-uwsgi.ini
  55. # By default, use the ML2 plugin
  56. NEUTRON_CORE_PLUGIN=${NEUTRON_CORE_PLUGIN:-ml2}
  57. NEUTRON_CORE_PLUGIN_CONF_FILENAME=${NEUTRON_CORE_PLUGIN_CONF_FILENAME:-ml2_conf.ini}
  58. NEUTRON_CORE_PLUGIN_CONF_PATH=$NEUTRON_CONF_DIR/plugins/$NEUTRON_CORE_PLUGIN
  59. NEUTRON_CORE_PLUGIN_CONF=$NEUTRON_CORE_PLUGIN_CONF_PATH/$NEUTRON_CORE_PLUGIN_CONF_FILENAME
  60. NEUTRON_METERING_AGENT_CONF_FILENAME=${NEUTRON_METERING_AGENT_CONF_FILENAME:-metering_agent.ini}
  61. NEUTRON_METERING_AGENT_CONF=$NEUTRON_CONF_DIR/$NEUTRON_METERING_AGENT_CONF_FILENAME
  62. NEUTRON_AGENT_BINARY=${NEUTRON_AGENT_BINARY:-neutron-$NEUTRON_AGENT-agent}
  63. NEUTRON_L3_BINARY=${NEUTRON_L3_BINARY:-neutron-l3-agent}
  64. NEUTRON_META_BINARY=${NEUTRON_META_BINARY:-neutron-metadata-agent}
  65. NEUTRON_METERING_BINARY=${NEUTRON_METERING_BINARY:-neutron-metering-agent}
  66. # Public facing bits
  67. if is_service_enabled tls-proxy; then
  68. NEUTRON_SERVICE_PROTOCOL="https"
  69. fi
  70. NEUTRON_SERVICE_HOST=${NEUTRON_SERVICE_HOST:-$SERVICE_HOST}
  71. NEUTRON_SERVICE_PORT=${NEUTRON_SERVICE_PORT:-9696}
  72. NEUTRON_SERVICE_PORT_INT=${NEUTRON_SERVICE_PORT_INT:-19696}
  73. NEUTRON_SERVICE_PROTOCOL=${NEUTRON_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL}
  74. NEUTRON_AUTH_STRATEGY=${NEUTRON_AUTH_STRATEGY:-keystone}
  75. NEUTRON_ROOTWRAP=$(get_rootwrap_location neutron)
  76. NEUTRON_ROOTWRAP_CONF_FILE=$NEUTRON_CONF_DIR/rootwrap.conf
  77. NEUTRON_ROOTWRAP_CMD="$NEUTRON_ROOTWRAP $NEUTRON_ROOTWRAP_CONF_FILE"
  78. NEUTRON_ROOTWRAP_DAEMON_CMD="$NEUTRON_ROOTWRAP-daemon $NEUTRON_ROOTWRAP_CONF_FILE"
  79. # This is needed because _neutron_ovs_base_configure_l3_agent uses it to create
  80. # an external network bridge
  81. PUBLIC_BRIDGE=${PUBLIC_BRIDGE:-br-ex}
  82. PUBLIC_BRIDGE_MTU=${PUBLIC_BRIDGE_MTU:-1500}
  83. # Network type - default vxlan, however enables vlan based jobs to override
  84. # using the legacy environment variable as well as a new variable in greater
  85. # alignment with the naming scheme of this plugin.
  86. NEUTRON_TENANT_NETWORK_TYPE=${NEUTRON_TENANT_NETWORK_TYPE:-vxlan}
  87. NEUTRON_TENANT_VLAN_RANGE=${NEUTRON_TENANT_VLAN_RANGE:-${TENANT_VLAN_RANGE:-100:150}}
  88. # Physical network for VLAN network usage.
  89. NEUTRON_PHYSICAL_NETWORK=${NEUTRON_PHYSICAL_NETWORK:-}
  90. # Additional neutron api config files
  91. declare -a -g _NEUTRON_SERVER_EXTRA_CONF_FILES_ABS
  92. # Functions
  93. # ---------
  94. # Test if any Neutron services are enabled
  95. # is_neutron_enabled
  96. function is_neutron_enabled {
  97. [[ ,${DISABLED_SERVICES} =~ ,"neutron" ]] && return 1
  98. [[ ,${ENABLED_SERVICES} =~ ,"neutron-" || ,${ENABLED_SERVICES} =~ ,"q-" ]] && return 0
  99. return 1
  100. }
  101. # Test if any Neutron services are enabled
  102. # is_neutron_enabled
  103. function is_neutron_legacy_enabled {
  104. # first we need to remove all "neutron-" from DISABLED_SERVICES list
  105. disabled_services_copy=$(echo $DISABLED_SERVICES | sed 's/neutron-//g')
  106. [[ ,${disabled_services_copy} =~ ,"neutron" ]] && return 1
  107. [[ ,${ENABLED_SERVICES} =~ ,"q-" ]] && return 0
  108. return 1
  109. }
  110. if is_neutron_legacy_enabled; then
  111. source $TOP_DIR/lib/neutron-legacy
  112. fi
  113. # cleanup_neutron() - Remove residual data files, anything left over from previous
  114. # runs that a clean run would need to clean up
  115. function cleanup_neutron_new {
  116. source $TOP_DIR/lib/neutron_plugins/${NEUTRON_AGENT}_agent
  117. if is_neutron_ovs_base_plugin; then
  118. neutron_ovs_base_cleanup
  119. fi
  120. if [[ $NEUTRON_AGENT == "linuxbridge" ]]; then
  121. neutron_lb_cleanup
  122. fi
  123. # delete all namespaces created by neutron
  124. for ns in $(sudo ip netns list | grep -o -E '(qdhcp|qrouter|qlbaas|fip|snat)-[0-9a-f-]*'); do
  125. sudo ip netns delete ${ns}
  126. done
  127. }
  128. # configure_root_helper_options() - Configure agent rootwrap helper options
  129. function configure_root_helper_options {
  130. local conffile=$1
  131. iniset $conffile agent root_helper "sudo $NEUTRON_ROOTWRAP_CMD"
  132. iniset $conffile agent root_helper_daemon "sudo $NEUTRON_ROOTWRAP_DAEMON_CMD"
  133. }
  134. # configure_neutron() - Set config files, create data dirs, etc
  135. function configure_neutron_new {
  136. sudo install -d -o $STACK_USER $NEUTRON_CONF_DIR
  137. (cd $NEUTRON_DIR && exec ./tools/generate_config_file_samples.sh)
  138. cp $NEUTRON_DIR/etc/neutron.conf.sample $NEUTRON_CONF
  139. configure_neutron_rootwrap
  140. mkdir -p $NEUTRON_CORE_PLUGIN_CONF_PATH
  141. # NOTE(yamamoto): A decomposed plugin should prepare the config file in
  142. # its devstack plugin.
  143. if [ -f $NEUTRON_DIR/etc/neutron/plugins/$NEUTRON_CORE_PLUGIN/$NEUTRON_CORE_PLUGIN_CONF_FILENAME.sample ]; then
  144. cp $NEUTRON_DIR/etc/neutron/plugins/$NEUTRON_CORE_PLUGIN/$NEUTRON_CORE_PLUGIN_CONF_FILENAME.sample $NEUTRON_CORE_PLUGIN_CONF
  145. fi
  146. iniset $NEUTRON_CONF database connection `database_connection_url neutron`
  147. iniset $NEUTRON_CONF DEFAULT state_path $NEUTRON_STATE_PATH
  148. iniset $NEUTRON_CONF oslo_concurrency lock_path $NEUTRON_STATE_PATH/lock
  149. iniset $NEUTRON_CONF DEFAULT use_syslog $SYSLOG
  150. iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
  151. iniset_rpc_backend neutron $NEUTRON_CONF
  152. # Neutron API server & Neutron plugin
  153. if is_service_enabled neutron-api; then
  154. local policy_file=$NEUTRON_CONF_DIR/policy.json
  155. # Allow neutron user to administer neutron to match neutron account
  156. # NOTE(amotoki): This is required for nova works correctly with neutron.
  157. if [ -f $NEUTRON_DIR/etc/policy.json ]; then
  158. cp $NEUTRON_DIR/etc/policy.json $policy_file
  159. sed -i 's/"context_is_admin": "role:admin"/"context_is_admin": "role:admin or user_name:neutron"/g' $policy_file
  160. else
  161. echo '{"context_is_admin": "role:admin or user_name:neutron"}' > $policy_file
  162. fi
  163. cp $NEUTRON_DIR/etc/api-paste.ini $NEUTRON_CONF_DIR/api-paste.ini
  164. iniset $NEUTRON_CONF DEFAULT core_plugin $NEUTRON_CORE_PLUGIN
  165. iniset $NEUTRON_CONF DEFAULT policy_file $policy_file
  166. iniset $NEUTRON_CONF DEFAULT allow_overlapping_ips True
  167. iniset $NEUTRON_CONF DEFAULT router_distributed $NEUTRON_DISTRIBUTED_ROUTING
  168. iniset $NEUTRON_CONF DEFAULT auth_strategy $NEUTRON_AUTH_STRATEGY
  169. configure_keystone_authtoken_middleware $NEUTRON_CONF neutron
  170. configure_keystone_authtoken_middleware $NEUTRON_CONF nova nova
  171. # Configure tenant network type
  172. iniset $NEUTRON_CORE_PLUGIN_CONF ml2 tenant_network_types $NEUTRON_TENANT_NETWORK_TYPE
  173. local mech_drivers="openvswitch"
  174. if [[ "$NEUTRON_DISTRIBUTED_ROUTING" = "True" ]]; then
  175. mech_drivers+=",l2population"
  176. else
  177. mech_drivers+=",linuxbridge"
  178. fi
  179. iniset $NEUTRON_CORE_PLUGIN_CONF ml2 mechanism_drivers $mech_drivers
  180. iniset $NEUTRON_CORE_PLUGIN_CONF ml2_type_vxlan vni_ranges 1001:2000
  181. iniset $NEUTRON_CORE_PLUGIN_CONF ml2_type_flat flat_networks $PUBLIC_NETWORK_NAME
  182. if [[ "$NEUTRON_TENANT_NETWORK_TYPE" =~ "vlan" ]] && [[ "$NEUTRON_PHYSICAL_NETWORK" != "" ]]; then
  183. iniset $NEUTRON_CORE_PLUGIN_CONF ml2_type_vlan network_vlan_ranges ${NEUTRON_PHYSICAL_NETWORK}:${NEUTRON_TENANT_VLAN_RANGE}
  184. fi
  185. if [[ "$NEUTRON_PORT_SECURITY" = "True" ]]; then
  186. neutron_ml2_extension_driver_add port_security
  187. fi
  188. fi
  189. # Neutron OVS or LB agent
  190. if is_service_enabled neutron-agent; then
  191. iniset $NEUTRON_CORE_PLUGIN_CONF agent tunnel_types vxlan
  192. iniset $NEUTRON_CORE_PLUGIN_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
  193. configure_root_helper_options $NEUTRON_CORE_PLUGIN_CONF
  194. # Configure the neutron agent
  195. if [[ $NEUTRON_AGENT == "linuxbridge" ]]; then
  196. iniset $NEUTRON_CORE_PLUGIN_CONF securitygroup firewall_driver iptables
  197. iniset $NEUTRON_CORE_PLUGIN_CONF vxlan local_ip $HOST_IP
  198. elif [[ $NEUTRON_AGENT == "openvswitch" ]]; then
  199. iniset $NEUTRON_CORE_PLUGIN_CONF securitygroup firewall_driver openvswitch
  200. iniset $NEUTRON_CORE_PLUGIN_CONF ovs local_ip $HOST_IP
  201. if [[ "$NEUTRON_DISTRIBUTED_ROUTING" = "True" ]]; then
  202. iniset $NEUTRON_CORE_PLUGIN_CONF agent l2_population True
  203. iniset $NEUTRON_CORE_PLUGIN_CONF agent enable_distributed_routing True
  204. iniset $NEUTRON_CORE_PLUGIN_CONF agent arp_responder True
  205. fi
  206. fi
  207. if ! running_in_container; then
  208. enable_kernel_bridge_firewall
  209. fi
  210. fi
  211. # DHCP Agent
  212. if is_service_enabled neutron-dhcp; then
  213. cp $NEUTRON_DIR/etc/dhcp_agent.ini.sample $NEUTRON_DHCP_CONF
  214. iniset $NEUTRON_DHCP_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
  215. # make it so we have working DNS from guests
  216. iniset $NEUTRON_DHCP_CONF DEFAULT dnsmasq_local_resolv True
  217. configure_root_helper_options $NEUTRON_DHCP_CONF
  218. iniset $NEUTRON_DHCP_CONF DEFAULT interface_driver $NEUTRON_AGENT
  219. neutron_plugin_configure_dhcp_agent $NEUTRON_DHCP_CONF
  220. fi
  221. if is_service_enabled neutron-l3; then
  222. cp $NEUTRON_DIR/etc/l3_agent.ini.sample $NEUTRON_L3_CONF
  223. iniset $NEUTRON_L3_CONF DEFAULT interface_driver $NEUTRON_AGENT
  224. neutron_service_plugin_class_add router
  225. configure_root_helper_options $NEUTRON_L3_CONF
  226. iniset $NEUTRON_L3_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
  227. neutron_plugin_configure_l3_agent $NEUTRON_L3_CONF
  228. # Configure the neutron agent to serve external network ports
  229. if [[ $NEUTRON_AGENT == "linuxbridge" ]]; then
  230. iniset $NEUTRON_CORE_PLUGIN_CONF linux_bridge bridge_mappings "$PUBLIC_NETWORK_NAME:$PUBLIC_BRIDGE"
  231. else
  232. iniset $NEUTRON_CORE_PLUGIN_CONF ovs bridge_mappings "$PUBLIC_NETWORK_NAME:$PUBLIC_BRIDGE"
  233. fi
  234. if [[ "$NEUTRON_DISTRIBUTED_ROUTING" = "True" ]]; then
  235. iniset $NEUTRON_L3_CONF DEFAULT agent_mode $NEUTRON_DVR_MODE
  236. fi
  237. fi
  238. # Metadata
  239. if is_service_enabled neutron-metadata-agent; then
  240. cp $NEUTRON_DIR/etc/metadata_agent.ini.sample $NEUTRON_META_CONF
  241. iniset $NEUTRON_META_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
  242. iniset $NEUTRON_META_CONF DEFAULT nova_metadata_host $NEUTRON_META_DATA_HOST
  243. iniset $NEUTRON_META_CONF DEFAULT metadata_workers $API_WORKERS
  244. # TODO(ihrachys) do we really need to set rootwrap for metadata agent?
  245. configure_root_helper_options $NEUTRON_META_CONF
  246. # TODO(dtroyer): remove the v2.0 hard code below
  247. iniset $NEUTRON_META_CONF DEFAULT auth_url $KEYSTONE_SERVICE_URI
  248. configure_keystone_authtoken_middleware $NEUTRON_META_CONF neutron DEFAULT
  249. fi
  250. # Format logging
  251. setup_logging $NEUTRON_CONF
  252. if is_service_enabled tls-proxy && [ "$NEUTRON_DEPLOY_MOD_WSGI" == "False" ]; then
  253. # Set the service port for a proxy to take the original
  254. iniset $NEUTRON_CONF DEFAULT bind_port "$NEUTRON_SERVICE_PORT_INT"
  255. iniset $NEUTRON_CONF oslo_middleware enable_proxy_headers_parsing True
  256. fi
  257. # Metering
  258. if is_service_enabled neutron-metering; then
  259. cp $NEUTRON_DIR/etc/metering_agent.ini.sample $NEUTRON_METERING_AGENT_CONF
  260. neutron_service_plugin_class_add metering
  261. fi
  262. }
  263. # configure_neutron_rootwrap() - configure Neutron's rootwrap
  264. function configure_neutron_rootwrap {
  265. # Deploy new rootwrap filters files (owned by root).
  266. # Wipe any existing rootwrap.d files first
  267. if [[ -d $NEUTRON_CONF_DIR/rootwrap.d ]]; then
  268. sudo rm -rf $NEUTRON_CONF_DIR/rootwrap.d
  269. fi
  270. # Deploy filters to /etc/neutron/rootwrap.d
  271. sudo install -d -o root -g root -m 755 $NEUTRON_CONF_DIR/rootwrap.d
  272. sudo install -o root -g root -m 644 $NEUTRON_DIR/etc/neutron/rootwrap.d/*.filters $NEUTRON_CONF_DIR/rootwrap.d
  273. # Set up ``rootwrap.conf``, pointing to ``$NEUTRON_CONF_DIR/rootwrap.d``
  274. sudo install -o root -g root -m 644 $NEUTRON_DIR/etc/rootwrap.conf $NEUTRON_CONF_DIR
  275. sudo sed -e "s:^filters_path=.*$:filters_path=$NEUTRON_CONF_DIR/rootwrap.d:" -i $NEUTRON_CONF_DIR/rootwrap.conf
  276. # Set up the rootwrap sudoers for Neutron
  277. tempfile=`mktemp`
  278. echo "$STACK_USER ALL=(root) NOPASSWD: $NEUTRON_ROOTWRAP_CMD *" >$tempfile
  279. echo "$STACK_USER ALL=(root) NOPASSWD: $NEUTRON_ROOTWRAP_DAEMON_CMD" >>$tempfile
  280. chmod 0440 $tempfile
  281. sudo chown root:root $tempfile
  282. sudo mv $tempfile /etc/sudoers.d/neutron-rootwrap
  283. }
  284. # Make Neutron-required changes to nova.conf
  285. # Takes a single optional argument which is the config file to update,
  286. # if not passed $NOVA_CONF is used.
  287. function configure_neutron_nova_new {
  288. local conf=${1:-$NOVA_CONF}
  289. iniset $conf DEFAULT use_neutron True
  290. iniset $conf neutron auth_type "password"
  291. iniset $conf neutron auth_url "$KEYSTONE_SERVICE_URI"
  292. iniset $conf neutron username neutron
  293. iniset $conf neutron password "$SERVICE_PASSWORD"
  294. iniset $conf neutron user_domain_name "Default"
  295. iniset $conf neutron project_name "$SERVICE_TENANT_NAME"
  296. iniset $conf neutron project_domain_name "Default"
  297. iniset $conf neutron auth_strategy $NEUTRON_AUTH_STRATEGY
  298. iniset $conf neutron region_name "$REGION_NAME"
  299. iniset $conf DEFAULT firewall_driver nova.virt.firewall.NoopFirewallDriver
  300. # optionally set options in nova_conf
  301. neutron_plugin_create_nova_conf $conf
  302. if is_service_enabled neutron-metadata-agent; then
  303. iniset $conf neutron service_metadata_proxy "True"
  304. fi
  305. }
  306. # Tenant User Roles
  307. # ------------------------------------------------------------------
  308. # service neutron admin # if enabled
  309. # create_neutron_accounts() - Create required service accounts
  310. function create_neutron_accounts_new {
  311. local neutron_url
  312. if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
  313. neutron_url=$NEUTRON_SERVICE_PROTOCOL://$NEUTRON_SERVICE_HOST/networking/
  314. else
  315. neutron_url=$NEUTRON_SERVICE_PROTOCOL://$NEUTRON_SERVICE_HOST:$NEUTRON_SERVICE_PORT/
  316. fi
  317. if [[ "$ENABLED_SERVICES" =~ "neutron-api" ]]; then
  318. create_service_user "neutron"
  319. neutron_service=$(get_or_create_service "neutron" \
  320. "network" "Neutron Service")
  321. get_or_create_endpoint $neutron_service \
  322. "$REGION_NAME" "$neutron_url"
  323. fi
  324. }
  325. # init_neutron() - Initialize databases, etc.
  326. function init_neutron_new {
  327. recreate_database neutron
  328. time_start "dbsync"
  329. # Run Neutron db migrations
  330. $NEUTRON_BIN_DIR/neutron-db-manage upgrade heads
  331. time_stop "dbsync"
  332. }
  333. # install_neutron() - Collect source and prepare
  334. function install_neutron_new {
  335. git_clone $NEUTRON_REPO $NEUTRON_DIR $NEUTRON_BRANCH
  336. setup_develop $NEUTRON_DIR
  337. # Install neutron-lib from git so we make sure we're testing
  338. # the latest code.
  339. if use_library_from_git "neutron-lib"; then
  340. git_clone_by_name "neutron-lib"
  341. setup_dev_lib "neutron-lib"
  342. fi
  343. # L3 service requires radvd
  344. if is_service_enabled neutron-l3; then
  345. install_package radvd
  346. fi
  347. if is_service_enabled neutron-agent neutron-dhcp neutron-l3; then
  348. #TODO(sc68cal) - kind of ugly
  349. source $TOP_DIR/lib/neutron_plugins/${NEUTRON_AGENT}_agent
  350. neutron_plugin_install_agent_packages
  351. fi
  352. }
  353. # install_neutronclient() - Collect source and prepare
  354. function install_neutronclient {
  355. if use_library_from_git "python-neutronclient"; then
  356. git_clone_by_name "python-neutronclient"
  357. setup_dev_lib "python-neutronclient"
  358. sudo install -D -m 0644 -o $STACK_USER {${GITDIR["python-neutronclient"]}/tools/,/etc/bash_completion.d/}neutron.bash_completion
  359. fi
  360. }
  361. # start_neutron_api() - Start the API process ahead of other things
  362. function start_neutron_api {
  363. local service_port=$NEUTRON_SERVICE_PORT
  364. local service_protocol=$NEUTRON_SERVICE_PROTOCOL
  365. local neutron_url
  366. if is_service_enabled tls-proxy; then
  367. service_port=$NEUTRON_SERVICE_PORT_INT
  368. service_protocol="http"
  369. fi
  370. local opts=""
  371. opts+=" --config-file $NEUTRON_CONF"
  372. opts+=" --config-file $NEUTRON_CORE_PLUGIN_CONF"
  373. local cfg_file
  374. for cfg_file in ${_NEUTRON_SERVER_EXTRA_CONF_FILES_ABS[@]}; do
  375. opts+=" --config-file $cfg_file"
  376. done
  377. if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
  378. run_process neutron-api "$NEUTRON_BIN_DIR/uwsgi --procname-prefix neutron-api --ini $NEUTRON_UWSGI_CONF"
  379. neutron_url=$service_protocol://$NEUTRON_SERVICE_HOST/networking/
  380. enable_service neutron-rpc-server
  381. run_process neutron-rpc-server "$NEUTRON_BIN_DIR/neutron-rpc-server $opts"
  382. else
  383. # Start the Neutron service
  384. # TODO(sc68cal) Stop hard coding this
  385. run_process neutron-api "$NEUTRON_BIN_DIR/neutron-server $opts"
  386. neutron_url=$service_protocol://$NEUTRON_SERVICE_HOST:$service_port
  387. # Start proxy if enabled
  388. if is_service_enabled tls-proxy; then
  389. start_tls_proxy neutron '*' $NEUTRON_SERVICE_PORT $NEUTRON_SERVICE_HOST $NEUTRON_SERVICE_PORT_INT
  390. fi
  391. fi
  392. if ! wait_for_service $SERVICE_TIMEOUT $neutron_url; then
  393. die $LINENO "neutron-api did not start"
  394. fi
  395. }
  396. # start_neutron() - Start running processes
  397. function start_neutron_new {
  398. # Start up the neutron agents if enabled
  399. # TODO(sc68cal) Make this pluggable so different DevStack plugins for different Neutron plugins
  400. # can resolve the $NEUTRON_AGENT_BINARY
  401. if is_service_enabled neutron-agent; then
  402. # TODO(ihrachys) stop loading ml2_conf.ini into agents, instead load agent specific files
  403. run_process neutron-agent "$NEUTRON_BIN_DIR/$NEUTRON_AGENT_BINARY --config-file $NEUTRON_CONF --config-file $NEUTRON_CORE_PLUGIN_CONF"
  404. fi
  405. if is_service_enabled neutron-dhcp; then
  406. neutron_plugin_configure_dhcp_agent $NEUTRON_DHCP_CONF
  407. run_process neutron-dhcp "$NEUTRON_BIN_DIR/$NEUTRON_DHCP_BINARY --config-file $NEUTRON_CONF --config-file $NEUTRON_DHCP_CONF"
  408. fi
  409. if is_service_enabled neutron-l3; then
  410. run_process neutron-l3 "$NEUTRON_BIN_DIR/$NEUTRON_L3_BINARY --config-file $NEUTRON_CONF --config-file $NEUTRON_L3_CONF"
  411. fi
  412. if is_service_enabled neutron-api && [[ "$NEUTRON_CREATE_INITIAL_NETWORKS" == "True" ]]; then
  413. # XXX(sc68cal) - Here's where plugins can wire up their own networks instead
  414. # of the code in lib/neutron_plugins/services/l3
  415. if type -p neutron_plugin_create_initial_networks > /dev/null; then
  416. neutron_plugin_create_initial_networks
  417. else
  418. # XXX(sc68cal) Load up the built in Neutron networking code and build a topology
  419. source $TOP_DIR/lib/neutron_plugins/services/l3
  420. # Create the networks using servic
  421. create_neutron_initial_network
  422. fi
  423. fi
  424. if is_service_enabled neutron-metadata-agent; then
  425. run_process neutron-metadata-agent "$NEUTRON_BIN_DIR/$NEUTRON_META_BINARY --config-file $NEUTRON_CONF --config-file $NEUTRON_META_CONF"
  426. fi
  427. if is_service_enabled neutron-metering; then
  428. run_process neutron-metering "$NEUTRON_BIN_DIR/$NEUTRON_METERING_BINARY --config-file $NEUTRON_CONF --config-file $NEUTRON_METERING_AGENT_CONF"
  429. fi
  430. }
  431. # stop_neutron() - Stop running processes
  432. function stop_neutron_new {
  433. for serv in neutron-api neutron-agent neutron-l3; do
  434. stop_process $serv
  435. done
  436. if is_service_enabled neutron-rpc-server; then
  437. stop_process neutron-rpc-server
  438. fi
  439. if is_service_enabled neutron-dhcp; then
  440. stop_process neutron-dhcp
  441. pid=$(ps aux | awk '/[d]nsmasq.+interface=(tap|ns-)/ { print $2 }')
  442. [ ! -z "$pid" ] && sudo kill -9 $pid
  443. fi
  444. if is_service_enabled neutron-metadata-agent; then
  445. sudo pkill -9 -f neutron-ns-metadata-proxy || :
  446. stop_process neutron-metadata-agent
  447. fi
  448. }
  449. # neutron_service_plugin_class_add() - add service plugin class
  450. function neutron_service_plugin_class_add_new {
  451. local service_plugin_class=$1
  452. local plugins=""
  453. plugins=$(iniget $NEUTRON_CONF DEFAULT service_plugins)
  454. if [ $plugins ]; then
  455. plugins+=","
  456. fi
  457. plugins+="${service_plugin_class}"
  458. iniset $NEUTRON_CONF DEFAULT service_plugins $plugins
  459. }
  460. function _neutron_ml2_extension_driver_add {
  461. local driver=$1
  462. local drivers=""
  463. drivers=$(iniget $NEUTRON_CORE_PLUGIN_CONF ml2 extension_drivers)
  464. if [ $drivers ]; then
  465. drivers+=","
  466. fi
  467. drivers+="${driver}"
  468. iniset $NEUTRON_CORE_PLUGIN_CONF ml2 extension_drivers $drivers
  469. }
  470. function neutron_server_config_add_new {
  471. _NEUTRON_SERVER_EXTRA_CONF_FILES_ABS+=($1)
  472. }
  473. # neutron_deploy_rootwrap_filters() - deploy rootwrap filters
  474. function neutron_deploy_rootwrap_filters_new {
  475. local srcdir=$1
  476. sudo install -d -o root -g root -m 755 $NEUTRON_CONF_DIR/rootwrap.d
  477. sudo install -o root -g root -m 644 $srcdir/etc/neutron/rootwrap.d/*.filters $NEUTRON_CONF_DIR/rootwrap.d
  478. }
  479. # Dispatch functions
  480. # These are needed for compatibility between the old and new implementations
  481. # where there are function name overlaps. These will be removed when
  482. # neutron-legacy is removed.
  483. # TODO(sc68cal) Remove when neutron-legacy is no more.
  484. function cleanup_neutron {
  485. if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
  486. stop_process neutron-api
  487. stop_process neutron-rpc-server
  488. remove_uwsgi_config "$NEUTRON_UWSGI_CONF" "$NEUTRON_BIN_DIR/neutron-api"
  489. sudo rm -f $(apache_site_config_for neutron-api)
  490. fi
  491. if is_neutron_legacy_enabled; then
  492. # Call back to old function
  493. cleanup_mutnauq "$@"
  494. else
  495. cleanup_neutron_new "$@"
  496. fi
  497. }
  498. function configure_neutron {
  499. if is_neutron_legacy_enabled; then
  500. # Call back to old function
  501. configure_mutnauq "$@"
  502. else
  503. configure_neutron_new "$@"
  504. fi
  505. if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
  506. write_uwsgi_config "$NEUTRON_UWSGI_CONF" "$NEUTRON_BIN_DIR/neutron-api" "/networking"
  507. fi
  508. }
  509. function configure_neutron_nova {
  510. if is_neutron_legacy_enabled; then
  511. # Call back to old function
  512. create_nova_conf_neutron $NOVA_CONF
  513. if [[ "${CELLSV2_SETUP}" == "superconductor" ]]; then
  514. for i in $(seq 1 $NOVA_NUM_CELLS); do
  515. local conf
  516. conf=$(conductor_conf $i)
  517. create_nova_conf_neutron $conf
  518. done
  519. fi
  520. else
  521. configure_neutron_nova_new $NOVA_CONF
  522. if [[ "${CELLSV2_SETUP}" == "superconductor" ]]; then
  523. for i in $(seq 1 $NOVA_NUM_CELLS); do
  524. local conf
  525. conf=$(conductor_conf $i)
  526. configure_neutron_nova_new $conf
  527. done
  528. fi
  529. fi
  530. }
  531. function create_neutron_accounts {
  532. if is_neutron_legacy_enabled; then
  533. # Call back to old function
  534. create_mutnauq_accounts "$@"
  535. else
  536. create_neutron_accounts_new "$@"
  537. fi
  538. }
  539. function init_neutron {
  540. if is_neutron_legacy_enabled; then
  541. # Call back to old function
  542. init_mutnauq "$@"
  543. else
  544. init_neutron_new "$@"
  545. fi
  546. }
  547. function install_neutron {
  548. if is_neutron_legacy_enabled; then
  549. # Call back to old function
  550. install_mutnauq "$@"
  551. else
  552. install_neutron_new "$@"
  553. fi
  554. }
  555. function neutron_service_plugin_class_add {
  556. if is_neutron_legacy_enabled; then
  557. # Call back to old function
  558. _neutron_service_plugin_class_add "$@"
  559. else
  560. neutron_service_plugin_class_add_new "$@"
  561. fi
  562. }
  563. function neutron_ml2_extension_driver_add {
  564. if is_neutron_legacy_enabled; then
  565. # Call back to old function
  566. _neutron_ml2_extension_driver_add_old "$@"
  567. else
  568. _neutron_ml2_extension_driver_add "$@"
  569. fi
  570. }
  571. function install_neutron_agent_packages {
  572. if is_neutron_legacy_enabled; then
  573. # Call back to old function
  574. install_neutron_agent_packages_mutnauq "$@"
  575. else
  576. :
  577. fi
  578. }
  579. function neutron_server_config_add {
  580. if is_neutron_legacy_enabled; then
  581. # Call back to old function
  582. mutnauq_server_config_add "$@"
  583. else
  584. neutron_server_config_add_new "$@"
  585. fi
  586. }
  587. function start_neutron {
  588. if is_neutron_legacy_enabled; then
  589. # Call back to old function
  590. start_mutnauq_l2_agent "$@"
  591. start_mutnauq_other_agents "$@"
  592. else
  593. start_neutron_new "$@"
  594. fi
  595. }
  596. function stop_neutron {
  597. if is_neutron_legacy_enabled; then
  598. # Call back to old function
  599. stop_mutnauq "$@"
  600. else
  601. stop_neutron_new "$@"
  602. fi
  603. }
  604. function neutron_deploy_rootwrap_filters {
  605. if is_neutron_legacy_enabled; then
  606. # Call back to old function
  607. _neutron_deploy_rootwrap_filters "$@"
  608. else
  609. neutron_deploy_rootwrap_filters_new "$@"
  610. fi
  611. }
  612. # Restore xtrace
  613. $XTRACE