Chef Cookbook - OpenStack DNS
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.

common.rb 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. # encoding: UTF-8
  2. #
  3. # Cookbook Name:: openstack-dns
  4. # Recipe:: common
  5. #
  6. # Copyright 2017, x-ion Gmbh
  7. #
  8. # Licensed under the Apache License, Version 2.0 (the "License");
  9. # you may not use this file except in compliance with the License.
  10. # You may obtain a copy of the License at
  11. #
  12. # http://www.apache.org/licenses/LICENSE-2.0
  13. #
  14. # Unless required by applicable law or agreed to in writing, software
  15. # distributed under the License is distributed on an "AS IS" BASIS,
  16. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. # See the License for the specific language governing permissions and
  18. # limitations under the License.
  19. #
  20. class ::Chef::Recipe
  21. include ::Openstack
  22. end
  23. if node['openstack']['dns']['syslog']['use']
  24. include_recipe 'openstack-common::logging'
  25. end
  26. platform_options = node['openstack']['dns']['platform']
  27. platform_options['designate_packages'].each do |pkg|
  28. package pkg do
  29. options platform_options['package_overrides']
  30. action :upgrade
  31. end
  32. end
  33. db_type = node['openstack']['db']['dns']['service_type']
  34. node['openstack']['db']['python_packages'][db_type].each do |pkg|
  35. package pkg do
  36. action :upgrade
  37. end
  38. end
  39. if node['openstack']['mq']['service_type'] == 'rabbit'
  40. node.default['openstack']['dns']['conf_secrets']['DEFAULT']['transport_url'] = rabbit_transport_url 'dns'
  41. # Note(jh): Workaround for https://bugs.launchpad.net/designate/+bug/1673403
  42. # Stolen from rabbit_transport_url() in openstack-common/libraries/endpoints.rb
  43. mq_user = node['openstack']['mq']['dns']['rabbit']['userid']
  44. node.default['openstack']['dns']['conf_secrets']['oslo_messaging_rabbit']['rabbit_userid'] = mq_user
  45. node.default['openstack']['dns']['conf_secrets']['oslo_messaging_rabbit']['rabbit_password'] = get_password 'user', mq_user
  46. node.default['openstack']['dns']['conf_secrets']['oslo_messaging_rabbit']['rabbit_virtual_host'] = node['openstack']['mq']['vhost']
  47. mq_port = node['openstack']['endpoints']['mq']['port']
  48. url = ''
  49. if node['openstack']['mq']['cluster']
  50. node['openstack']['mq']['servers'].each do |server|
  51. url += "#{server}:#{mq_port}"
  52. url += ',' unless node['openstack']['mq']['servers'].last == server
  53. end
  54. else
  55. bind_mq_address = bind_address node['openstack']['bind_service']['mq']
  56. url += "#{bind_mq_address}:#{mq_port}"
  57. end
  58. node.default['openstack']['dns']['conf_secrets']['oslo_messaging_rabbit']['rabbit_hosts'] = url
  59. end
  60. db_user = node['openstack']['db']['dns']['username']
  61. db_pass = get_password 'db', 'designate'
  62. public_identity_endpoint = identity_uri_transform(public_endpoint('identity'))
  63. identity_endpoint = internal_endpoint 'identity'
  64. bind_services = node['openstack']['bind_service']['all']
  65. api_bind = bind_services['dns-api']
  66. auth_url = auth_uri_transform identity_endpoint.to_s, node['openstack']['dns']['api']['auth']['version']
  67. # define attributes that are needed in designate.conf
  68. node.default['openstack']['dns']['conf'].tap do |conf|
  69. conf['service:api']['api_host'] = bind_address api_bind
  70. conf['service:api']['api_port'] = api_bind['port']
  71. conf['keystone_authtoken']['auth_uri'] = public_identity_endpoint
  72. conf['keystone_authtoken']['auth_url'] = auth_url
  73. end
  74. # define secrets that are needed in designate.conf
  75. node.default['openstack']['dns']['conf_secrets'].tap do |conf_secrets|
  76. conf_secrets['storage:sqlalchemy']['connection'] =
  77. db_uri('dns', db_user, db_pass)
  78. conf_secrets['keystone_authtoken']['password'] =
  79. get_password 'service', 'openstack-dns'
  80. end
  81. # merge all config options and secrets to be used in designate.conf
  82. designate_conf_options = merge_config_options 'dns'
  83. directory '/etc/designate' do
  84. owner node['openstack']['dns']['user']
  85. group node['openstack']['dns']['group']
  86. mode 00750
  87. action :create
  88. end
  89. template '/etc/designate/designate.conf' do
  90. source 'openstack-service.conf.erb'
  91. cookbook 'openstack-common'
  92. owner node['openstack']['dns']['user']
  93. group node['openstack']['dns']['group']
  94. mode 00640
  95. variables(
  96. service_config: designate_conf_options
  97. )
  98. end
  99. # delete all secrets saved in the attribute
  100. # node['openstack']['dns']['conf_secrets'] after creating the config file
  101. ruby_block "delete all attributes in node['openstack']['dns']['conf_secrets']" do
  102. block do
  103. node.rm(:openstack, :dns, :conf_secrets)
  104. end
  105. end
  106. rndc_secret = get_password 'token', 'designate_rndc'
  107. template '/etc/designate/rndc.key' do
  108. source 'rndc.key.erb'
  109. owner node['openstack']['dns']['user']
  110. group node['openstack']['dns']['group']
  111. mode 00440
  112. variables(
  113. secret: rndc_secret
  114. )
  115. end
  116. pool_config = node['openstack']['dns']['pool']
  117. template '/etc/designate/pools.yaml' do
  118. source 'pools.yaml.erb'
  119. owner node['openstack']['dns']['user']
  120. group node['openstack']['dns']['group']
  121. mode 00644
  122. variables(
  123. banner: node['openstack']['dns']['custom_template_banner'],
  124. bind_host: pool_config['bind_host'],
  125. masters: pool_config['masters'],
  126. ns_address: pool_config['ns_address'],
  127. ns_hostname: pool_config['ns_hostname']
  128. )
  129. end
  130. execute 'designate-manage database sync' do
  131. user node['openstack']['dns']['user']
  132. group node['openstack']['dns']['group']
  133. command 'designate-manage database sync'
  134. action :run
  135. end
  136. execute 'designate-manage pool update' do
  137. user node['openstack']['dns']['user']
  138. group node['openstack']['dns']['group']
  139. command 'designate-manage pool update'
  140. action :nothing
  141. subscribes :run, 'template[/etc/designate/pools.yaml]'
  142. end