OpenStack DNS As A Service (Designate)
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.

plugin.sh 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. # Install and start **Designate** service in Devstack
  2. # Save trace setting
  3. XTRACE=$(set +o | grep xtrace)
  4. set +o xtrace
  5. # Get backend configuration
  6. # -------------------------
  7. if is_service_enabled designate && [[ -r $DESIGNATE_PLUGINS/backend-$DESIGNATE_BACKEND_DRIVER ]]; then
  8. # Load plugin
  9. source $DESIGNATE_PLUGINS/backend-$DESIGNATE_BACKEND_DRIVER
  10. fi
  11. # Helper Functions
  12. # ----------------
  13. function setup_colorized_logging_designate {
  14. local conf_file=$1
  15. local conf_section=$2
  16. local project_var=${3:-"project_name"}
  17. local user_var=${4:-"user_name"}
  18. setup_colorized_logging $conf_file $conf_section $project_var $user_var
  19. # Override the logging_context_format_string value chosen by
  20. # setup_colorized_logging.
  21. iniset $conf_file $conf_section logging_context_format_string "%(asctime)s.%(msecs)03d %(color)s%(levelname)s %(name)s [%(request_id)s %(user_identity)s%(color)s] %(instance)s%(color)s%(message)s"
  22. }
  23. # DevStack Plugin
  24. # ---------------
  25. # cleanup_designate - Remove residual data files, anything left over from previous
  26. # runs that a clean run would need to clean up
  27. function cleanup_designate {
  28. sudo rm -rf $DESIGNATE_STATE_PATH $DESIGNATE_AUTH_CACHE_DIR
  29. cleanup_designate_backend
  30. }
  31. # configure_designate - Set config files, create data dirs, etc
  32. function configure_designate {
  33. [ ! -d $DESIGNATE_CONF_DIR ] && sudo mkdir -m 755 -p $DESIGNATE_CONF_DIR
  34. sudo chown $STACK_USER $DESIGNATE_CONF_DIR
  35. [ ! -d $DESIGNATE_LOG_DIR ] && sudo mkdir -m 755 -p $DESIGNATE_LOG_DIR
  36. sudo chown $STACK_USER $DESIGNATE_LOG_DIR
  37. # (Re)create ``designate.conf``
  38. rm -f $DESIGNATE_CONF
  39. # General Configuration
  40. iniset_rpc_backend designate $DESIGNATE_CONF DEFAULT
  41. iniset $DESIGNATE_CONF DEFAULT rpc_response_timeout 5
  42. iniset $DESIGNATE_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
  43. iniset $DESIGNATE_CONF DEFAULT verbose True
  44. iniset $DESIGNATE_CONF DEFAULT state_path $DESIGNATE_STATE_PATH
  45. iniset $DESIGNATE_CONF DEFAULT root-helper sudo designate-rootwrap $DESIGNATE_ROOTWRAP_CONF
  46. iniset $DESIGNATE_CONF storage:sqlalchemy connection `database_connection_url designate`
  47. # Quota Configuration
  48. iniset $DESIGNATE_CONF DEFAULT quota_zones $DESIGNATE_QUOTA_ZONES
  49. iniset $DESIGNATE_CONF DEFAULT quota_zone_recordsets $DESIGNATE_QUOTA_ZONE_RECORDSETS
  50. iniset $DESIGNATE_CONF DEFAULT quota_zone_records $DESIGNATE_QUOTA_ZONE_RECORDS
  51. iniset $DESIGNATE_CONF DEFAULT quota_recordset_records $DESIGNATE_QUOTA_RECORDSET_RECORDS
  52. iniset $DESIGNATE_CONF DEFAULT quota_api_export_size $DESIGNATE_QUOTA_API_EXPORT_SIZE
  53. # Coordination Configuration
  54. if [[ -n "$DESIGNATE_COORDINATION_URL" ]]; then
  55. iniset $DESIGNATE_CONF coordination backend_url $DESIGNATE_COORDINATION_URL
  56. fi
  57. # Install the policy file for the API server
  58. cp $DESIGNATE_DIR/etc/designate/policy.json $DESIGNATE_CONF_DIR/policy.json
  59. iniset $DESIGNATE_CONF DEFAULT policy_file $DESIGNATE_CONF_DIR/policy.json
  60. # Pool Manager Configuration
  61. iniset $DESIGNATE_CONF service:pool_manager pool_id $DESIGNATE_POOL_ID
  62. iniset $DESIGNATE_CONF service:pool_manager cache_driver $DESIGNATE_POOL_MANAGER_CACHE_DRIVER
  63. iniset $DESIGNATE_CONF service:pool_manager periodic_recovery_interval $DESIGNATE_PERIODIC_RECOVERY_INTERVAL
  64. iniset $DESIGNATE_CONF service:pool_manager periodic_sync_interval $DESIGNATE_PERIODIC_SYNC_INTERVAL
  65. # Pool Manager Cache
  66. if [ "$DESIGNATE_POOL_MANAGER_CACHE_DRIVER" == "sqlalchemy" ]; then
  67. iniset $DESIGNATE_CONF pool_manager_cache:sqlalchemy connection `database_connection_url designate_pool_manager`
  68. fi
  69. # API Configuration
  70. sudo cp $DESIGNATE_DIR/etc/designate/api-paste.ini $DESIGNATE_APIPASTE_CONF
  71. iniset $DESIGNATE_CONF service:api enabled_extensions_v1 $DESIGNATE_ENABLED_EXTENSIONS_V1
  72. iniset $DESIGNATE_CONF service:api enabled_extensions_v2 $DESIGNATE_ENABLED_EXTENSIONS_V2
  73. iniset $DESIGNATE_CONF service:api enabled_extensions_admin $DESIGNATE_ENABLED_EXTENSIONS_ADMIN
  74. iniset $DESIGNATE_CONF service:api api_base_uri $DESIGNATE_SERVICE_PROTOCOL://$DESIGNATE_SERVICE_HOST:$DESIGNATE_SERVICE_PORT/
  75. iniset $DESIGNATE_CONF service:api enable_api_v1 $DESIGNATE_ENABLE_API_V1
  76. iniset $DESIGNATE_CONF service:api enable_api_v2 $DESIGNATE_ENABLE_API_V2
  77. iniset $DESIGNATE_CONF service:api enable_api_admin $DESIGNATE_ENABLE_API_ADMIN
  78. # mDNS Configuration
  79. iniset $DESIGNATE_CONF service:mdns listen ${DESIGNATE_SERVICE_HOST}:${DESIGNATE_SERVICE_PORT_MDNS}
  80. # Set up Notifications/Ceilometer Integration
  81. iniset $DESIGNATE_CONF DEFAULT notification_driver "$DESIGNATE_NOTIFICATION_DRIVER"
  82. iniset $DESIGNATE_CONF DEFAULT notification_topics "$DESIGNATE_NOTIFICATION_TOPICS"
  83. # Root Wrap
  84. sudo cp $DESIGNATE_DIR/etc/designate/rootwrap.conf.sample $DESIGNATE_ROOTWRAP_CONF
  85. iniset $DESIGNATE_ROOTWRAP_CONF DEFAULT filters_path $DESIGNATE_DIR/etc/designate/rootwrap.d root-helper
  86. # Oslo Concurrency
  87. iniset $DESIGNATE_CONF oslo_concurrency lock_path "$DESIGNATE_STATE_PATH"
  88. # Set up the rootwrap sudoers for designate
  89. local rootwrap_sudoer_cmd="$DESIGNATE_BIN_DIR/designate-rootwrap $DESIGNATE_ROOTWRAP_CONF *"
  90. local tempfile=`mktemp`
  91. echo "$STACK_USER ALL=(root) NOPASSWD: $rootwrap_sudoer_cmd" >$tempfile
  92. chmod 0440 $tempfile
  93. sudo chown root:root $tempfile
  94. sudo mv $tempfile /etc/sudoers.d/designate-rootwrap
  95. # TLS Proxy Configuration
  96. if is_service_enabled tls-proxy; then
  97. # Set the service port for a proxy to take the original
  98. iniset $DESIGNATE_CONF service:api listen ${DESIGNATE_SERVICE_HOST}:${DESIGNATE_SERVICE_PORT_INT}
  99. else
  100. iniset $DESIGNATE_CONF service:api listen ${DESIGNATE_SERVICE_HOST}:${DESIGNATE_SERVICE_PORT}
  101. fi
  102. # Setup the Keystone Integration
  103. if is_service_enabled key; then
  104. iniset $DESIGNATE_CONF service:api auth_strategy keystone
  105. configure_auth_token_middleware $DESIGNATE_CONF designate $DESIGNATE_AUTH_CACHE_DIR
  106. fi
  107. # Logging Configuration
  108. if [ "$SYSLOG" != "False" ]; then
  109. iniset $DESIGNATE_CONF DEFAULT use_syslog True
  110. fi
  111. # Format logging
  112. if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
  113. setup_colorized_logging_designate $DESIGNATE_CONF DEFAULT "tenant" "user"
  114. fi
  115. # Backend Plugin Configuation
  116. configure_designate_backend
  117. }
  118. function configure_designatedashboard {
  119. # Compile message catalogs
  120. if [ -d ${DESIGNATEDASHBOARD_DIR}/designatedashboard/locale ]; then
  121. (cd ${DESIGNATEDASHBOARD_DIR}/designatedashboard; DJANGO_SETTINGS_MODULE=openstack_dashboard.settings ../manage.py compilemessages)
  122. fi
  123. }
  124. # Configure the needed tempest options
  125. function configure_designate_tempest() {
  126. if is_service_enabled tempest; then
  127. # Tell tempest we're available
  128. iniset $TEMPEST_CONFIG service_available designate True
  129. # Tell tempest which APIs are available
  130. iniset $TEMPEST_CONFIG dns_feature_enabled api_v1 $DESIGNATE_ENABLE_API_V1
  131. iniset $TEMPEST_CONFIG dns_feature_enabled api_v2 $DESIGNATE_ENABLE_API_V2
  132. iniset $TEMPEST_CONFIG dns_feature_enabled api_admin $DESIGNATE_ENABLE_API_ADMIN
  133. iniset $TEMPEST_CONFIG dns_feature_enabled api_v2_root_recordsets True
  134. # Tell tempest where are nameservers are.
  135. nameservers=$DESIGNATE_SERVICE_HOST:$DESIGNATE_SERVICE_PORT_DNS
  136. # TODO(kiall): Remove hardcoded list of plugins
  137. case $DESIGNATE_BACKEND_DRIVER in
  138. bind9|powerdns)
  139. nameservers="$DESIGNATE_SERVICE_HOST:$DESIGNATE_SERVICE_PORT_DNS"
  140. ;;
  141. akamai)
  142. nameservers="$DESIGNATE_AKAMAI_NAMESERVERS"
  143. ;;
  144. dynect)
  145. nameservers="$DESIGNATE_DYNECT_NAMESERVERS"
  146. ;;
  147. esac
  148. if [ ! -z "$DESIGNATE_NAMESERVERS" ]; then
  149. nameservers=$DESIGNATE_NAMESERVERS
  150. fi
  151. iniset $TEMPEST_CONFIG designate nameservers $nameservers
  152. fi
  153. }
  154. # create_designate_accounts - Set up common required designate accounts
  155. # Tenant User Roles
  156. # ------------------------------------------------------------------
  157. # service designate admin # if enabled
  158. function create_designate_accounts {
  159. if is_service_enabled designate-api; then
  160. create_service_user "designate"
  161. if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
  162. get_or_create_service "designate" "dns" "Designate DNS Service"
  163. get_or_create_endpoint "dns" \
  164. "$REGION_NAME" \
  165. "$DESIGNATE_SERVICE_PROTOCOL://$DESIGNATE_SERVICE_HOST:$DESIGNATE_SERVICE_PORT/" \
  166. "$DESIGNATE_SERVICE_PROTOCOL://$DESIGNATE_SERVICE_HOST:$DESIGNATE_SERVICE_PORT/" \
  167. "$DESIGNATE_SERVICE_PROTOCOL://$DESIGNATE_SERVICE_HOST:$DESIGNATE_SERVICE_PORT/"
  168. fi
  169. fi
  170. }
  171. # create_designate_pool_configuration - Create Pool Configuration
  172. function create_designate_pool_configuration {
  173. # Sync Pools Config
  174. designate-manage pool update --file $DESIGNATE_CONF_DIR/pools.yaml
  175. # Allow Backends to do backend specific tasks
  176. if function_exists create_designate_pool_configuration_backend; then
  177. create_designate_pool_configuration_backend
  178. fi
  179. }
  180. # init_designate - Initialize etc.
  181. function init_designate {
  182. # Create cache dir
  183. sudo mkdir -p $DESIGNATE_AUTH_CACHE_DIR
  184. sudo chown $STACK_USER $DESIGNATE_AUTH_CACHE_DIR
  185. rm -f $DESIGNATE_AUTH_CACHE_DIR/*
  186. # Some Designate Backends require mdns be bound to port 53, make that
  187. # doable.
  188. sudo setcap 'cap_net_bind_service=+ep' $(readlink -f /usr/bin/python)
  189. # (Re)create designate database
  190. recreate_database designate utf8
  191. # Init and migrate designate database
  192. designate-manage database sync
  193. if [ "$DESIGNATE_POOL_MANAGER_CACHE_DRIVER" == "sqlalchemy" ]; then
  194. # (Re)create designate_pool_manager cache
  195. recreate_database designate_pool_manager utf8
  196. # Init and migrate designate pool-manager-cache
  197. designate-manage pool-manager-cache sync
  198. fi
  199. init_designate_backend
  200. }
  201. # install_designate - Collect source and prepare
  202. function install_designate {
  203. install_package libcap2-bin
  204. if is_fedora; then
  205. # This package provides `dig`
  206. install_package bind-utils
  207. fi
  208. git_clone $DESIGNATE_REPO $DESIGNATE_DIR $DESIGNATE_BRANCH
  209. setup_develop $DESIGNATE_DIR
  210. install_designate_backend
  211. }
  212. # install_designateclient - Collect source and prepare
  213. function install_designateclient {
  214. if use_library_from_git "python-designateclient"; then
  215. git_clone_by_name "python-designateclient"
  216. setup_dev_lib "python-designateclient"
  217. else
  218. pip_install_gr "python-designateclient"
  219. fi
  220. }
  221. # install_designatedashboard - Collect source and prepare
  222. function install_designatedashboard {
  223. git_clone $DESIGNATEDASHBOARD_REPO $DESIGNATEDASHBOARD_DIR $DESIGNATEDASHBOARD_BRANCH
  224. setup_develop $DESIGNATEDASHBOARD_DIR
  225. ln -fs $DESIGNATEDASHBOARD_DIR/designatedashboard/enabled/_1710_project_dns_panel_group.py $HORIZON_DIR/openstack_dashboard/local/enabled/_1710_project_dns_panel_group.py
  226. ln -fs $DESIGNATEDASHBOARD_DIR/designatedashboard/enabled/_1720_project_dns_panel.py $HORIZON_DIR/openstack_dashboard/local/enabled/_1720_project_dns_panel.py
  227. }
  228. # install_designatetempest - Collect source and prepare
  229. function install_designatetempest {
  230. git_clone_by_name "designate-tempest-plugin"
  231. setup_dev_lib "designate-tempest-plugin"
  232. }
  233. # start_designate - Start running processes, including screen
  234. function start_designate {
  235. start_designate_backend
  236. run_process designate-central "$DESIGNATE_BIN_DIR/designate-central --config-file $DESIGNATE_CONF"
  237. run_process designate-api "$DESIGNATE_BIN_DIR/designate-api --config-file $DESIGNATE_CONF"
  238. run_process designate-pool-manager "$DESIGNATE_BIN_DIR/designate-pool-manager --config-file $DESIGNATE_CONF"
  239. run_process designate-zone-manager "$DESIGNATE_BIN_DIR/designate-zone-manager --config-file $DESIGNATE_CONF"
  240. run_process designate-mdns "$DESIGNATE_BIN_DIR/designate-mdns --config-file $DESIGNATE_CONF"
  241. run_process designate-agent "$DESIGNATE_BIN_DIR/designate-agent --config-file $DESIGNATE_CONF"
  242. run_process designate-sink "$DESIGNATE_BIN_DIR/designate-sink --config-file $DESIGNATE_CONF"
  243. # Start proxies if enabled
  244. if is_service_enabled designate-api && is_service_enabled tls-proxy; then
  245. start_tls_proxy '*' $DESIGNATE_SERVICE_PORT $DESIGNATE_SERVICE_HOST $DESIGNATE_SERVICE_PORT_INT &
  246. fi
  247. if ! timeout $SERVICE_TIMEOUT sh -c "while ! wget --no-proxy -q -O- $DESIGNATE_SERVICE_PROTOCOL://$DESIGNATE_SERVICE_HOST:$DESIGNATE_SERVICE_PORT; do sleep 1; done"; then
  248. die $LINENO "Designate did not start"
  249. fi
  250. }
  251. # stop_designate - Stop running processes
  252. function stop_designate {
  253. # Kill the designate screen windows
  254. stop_process designate-central
  255. stop_process designate-api
  256. stop_process designate-pool-manager
  257. stop_process designate-zone-manager
  258. stop_process designate-mdns
  259. stop_process designate-agent
  260. stop_process designate-sink
  261. stop_designate_backend
  262. }
  263. # This is the main for plugin.sh
  264. if is_service_enabled designate; then
  265. # Sanify check for agent backend
  266. # ------------------------------
  267. if ! is_service_enabled designate-agent && [ "$DESIGNATE_BACKEND_DRIVER" == "agent" ]; then
  268. die $LINENO "To use the agent backend, you must enable the designate-agent service"
  269. fi
  270. if [[ "$1" == "stack" && "$2" == "install" ]]; then
  271. echo_summary "Installing Designate client"
  272. install_designateclient
  273. echo_summary "Installing Designate"
  274. install_designate
  275. if is_service_enabled horizon; then
  276. echo_summary "Installing Designate dashboard"
  277. install_designatedashboard
  278. fi
  279. if is_service_enabled tempest; then
  280. echo_summary "Installing Designate Tempest Plugin"
  281. install_designatetempest
  282. fi
  283. elif [[ "$1" == "stack" && "$2" == "post-config" ]]; then
  284. echo_summary "Configuring Designate"
  285. configure_designate
  286. if is_service_enabled horizon; then
  287. echo_summary "Configuring Designate dashboard"
  288. configure_designatedashboard
  289. fi
  290. if is_service_enabled key; then
  291. echo_summary "Creating Designate Keystone accounts"
  292. create_designate_accounts
  293. fi
  294. elif [[ "$1" == "stack" && "$2" == "extra" ]]; then
  295. echo_summary "Initializing Designate"
  296. init_designate
  297. echo_summary "Configuring Tempest options for Designate"
  298. configure_designate_tempest
  299. echo_summary "Starting Designate"
  300. start_designate
  301. echo_summary "Creating Pool Configuration"
  302. create_designate_pool_configuration
  303. fi
  304. if [[ "$1" == "unstack" ]]; then
  305. stop_designate
  306. fi
  307. if [[ "$1" == "clean" ]]; then
  308. echo_summary "Cleaning Designate"
  309. cleanup_designate
  310. fi
  311. fi
  312. # Restore xtrace
  313. $XTRACE