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.

backend-pdns4 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. # Configure the powerdns backend
  2. # Enable with:
  3. # DESIGNATE_BACKEND_DRIVER=powerdns
  4. # Dependencies:
  5. # ``functions`` file
  6. # ``designate`` configuration
  7. # install_designate_backend - install any external requirements
  8. # configure_designate_backend - make configuration changes, including those to other services
  9. # init_designate_backend - initialize databases, etc.
  10. # start_designate_backend - start any external services
  11. # stop_designate_backend - stop any external services
  12. # cleanup_designate_backend - remove transient data and cache
  13. # Save trace setting
  14. DP_PDNS_XTRACE=$(set +o | grep xtrace)
  15. set +o xtrace
  16. # Defaults
  17. # --------
  18. if is_fedora; then
  19. POWERDNS_CFG_DIR=/etc/pdns
  20. else
  21. POWERDNS_CFG_DIR=/etc/powerdns
  22. fi
  23. # Entry Points
  24. # ------------
  25. # install_designate_backend - install any external requirements
  26. function install_designate_backend {
  27. if is_ubuntu; then
  28. GetOSVersion
  29. if [ "$os_CODENAME" = "trusty" ]; then
  30. sudo tee /etc/apt/sources.list.d/pdns.list > /dev/null <<EOF
  31. deb [arch=amd64] http://repo.powerdns.com/ubuntu trusty-auth-40 main
  32. EOF
  33. sudo tee /etc/apt/preferences.d/pdns > /dev/null <<EOF
  34. Package: pdns-*
  35. Pin: origin repo.powerdns.com
  36. Pin-Priority: 600
  37. EOF
  38. curl https://repo.powerdns.com/FD380FBB-pub.asc | sudo apt-key add - &&
  39. sudo apt-get update
  40. elif [ "$os_CODENAME" = "xenial" ]; then
  41. echo "Use PDNS4 from apt repo"
  42. else
  43. die $LINENO "PDNS4 backend only supports trusty or xenial"
  44. fi
  45. PDNS=pdns-server
  46. else
  47. die $LINENO "PDNS4 Backend plugin backend only supports Ubuntu"
  48. fi
  49. if is_service_enabled mysql; then
  50. PDNS+=" pdns-backend-mysql"
  51. else
  52. die $LINENO "PDNS4 backend only supports MySQL"
  53. fi
  54. install_package $PDNS
  55. sudo rm -rf $POWERDNS_CFG_DIR/pdns.d
  56. }
  57. # configure_designate_backend - make configuration changes, including those to other services
  58. function configure_designate_backend {
  59. # Generate Designate pool.yaml file
  60. sudo tee $DESIGNATE_CONF_DIR/pools.yaml > /dev/null <<EOF
  61. ---
  62. - name: default
  63. description: DevStack PowerDNS Pool
  64. attributes: {}
  65. ns_records:
  66. - hostname: $DESIGNATE_DEFAULT_NS_RECORD
  67. priority: 1
  68. nameservers:
  69. - host: $DESIGNATE_SERVICE_HOST
  70. port: $DESIGNATE_SERVICE_PORT_DNS
  71. targets:
  72. - type: pdns4
  73. description: PowerDNS Database Cluster
  74. masters:
  75. - host: $DESIGNATE_SERVICE_HOST
  76. port: $DESIGNATE_SERVICE_PORT_MDNS
  77. options:
  78. host: $DESIGNATE_SERVICE_HOST
  79. port: $DESIGNATE_SERVICE_PORT_DNS
  80. api_endpoint: http://$DESIGNATE_SERVICE_HOST:8081
  81. api_token: changeme
  82. EOF
  83. # Generate PowerDNS pdns.conf file
  84. sudo tee $POWERDNS_CFG_DIR/pdns.conf > /dev/null <<EOF
  85. # General Config
  86. setgid=pdns
  87. setuid=pdns
  88. config-dir=$POWERDNS_CFG_DIR
  89. socket-dir=/var/run
  90. guardian=yes
  91. daemon=yes
  92. disable-axfr=no
  93. local-address=$DESIGNATE_SERVICE_HOST
  94. local-port=$DESIGNATE_SERVICE_PORT_DNS
  95. master=no
  96. slave=yes
  97. cache-ttl=0
  98. query-cache-ttl=0
  99. negquery-cache-ttl=0
  100. out-of-zone-additional-processing=no
  101. webserver=yes
  102. webserver-address=$DESIGNATE_SERVICE_HOST
  103. api=yes
  104. api-key=changeme
  105. EOF
  106. if is_service_enabled mysql; then
  107. sudo tee -a $POWERDNS_CFG_DIR/pdns.conf > /dev/null <<EOF
  108. # Launch gmysql backend
  109. launch=gmysql
  110. # gmysql parameters
  111. gmysql-host=$DATABASE_HOST
  112. gmysql-user=$DATABASE_USER
  113. gmysql-password=$DATABASE_PASSWORD
  114. gmysql-dbname=designate_pdns
  115. gmysql-dnssec=yes
  116. EOF
  117. else
  118. die $LINENO "PDNS4 backend only supports MySQL"
  119. fi
  120. restart_service pdns
  121. }
  122. # init_designate_backend - initialize databases, etc.
  123. function init_designate_backend {
  124. # Stop pdns so that the migration succeeds, if not you get a error
  125. # that the schema is still in use.
  126. if is_service_enabled postgresql; then
  127. stop_designate_backend
  128. fi
  129. # (Re)create designate_pdns database
  130. recreate_database designate_pdns utf8
  131. if is_service_enabled mysql; then
  132. sudo mysql -u root designate_pdns < $DESIGNATE_PLUGINS/backend-pdns4-mysql-db.sql
  133. else
  134. die $LINENO "PDNS4 backend only supports MySQL"
  135. fi
  136. }
  137. # create_designate_pool_configuration_backend - Perform post-pool config tasks
  138. function create_designate_pool_configuration_backend {
  139. # Init and migrate designate_pdns database
  140. :
  141. }
  142. # start_designate_backend - start any external services
  143. function start_designate_backend {
  144. start_service pdns
  145. }
  146. # stop_designate_backend - stop any external services
  147. function stop_designate_backend {
  148. stop_service pdns
  149. }
  150. # cleanup_designate_backend - remove transient data and cache
  151. function cleanup_designate_backend {
  152. :
  153. }
  154. # Restore xtrace
  155. $DP_PDNS_XTRACE