network.pp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. # == Class: nova::network
  2. #
  3. # Manages nova-network.
  4. #
  5. # An OpenStack deployment that includes compute and networking will use either
  6. # nova-network or Neutron. Neutron is newer and nova-network is the legacy
  7. # networking support built directly into Nova. However, nova-network is still
  8. # fully supported, is not feature frozen, and is not yet officially deprecated.
  9. #
  10. # === Parameters:
  11. #
  12. # [*private_interface*]
  13. # (optional) Interface used by private network.
  14. # Defaults to undef
  15. #
  16. # [*fixed_range*]
  17. # (optional) Fixed private network range.
  18. # Defaults to '10.0.0.0/8'
  19. #
  20. # [*public_interface*]
  21. # (optional) Interface used to connect vms to public network.
  22. # Defaults to undef
  23. #
  24. # [*num_networks*]
  25. # (optional) Number of networks that fixed range network should be
  26. # split into.
  27. # Defaults to 1
  28. #
  29. # [*network_size*]
  30. # (optional) Number of addresses in each private subnet.
  31. # Defaults to 255
  32. #
  33. # [*floating_range*]
  34. # (optional) Range of floating ip addresses to create.
  35. # Defaults to false
  36. #
  37. # [*enabled*]
  38. # (optional) Whether the network service should be enabled.
  39. # Defaults to true
  40. #
  41. # [*network_manager*]
  42. # (optional) The type of network manager to use.
  43. # Defaults to 'nova.network.manager.FlatDHCPManager'
  44. #
  45. # [*config_overrides*]
  46. # (optional) Additional parameters to pass to the network manager class
  47. # Defaults to {}
  48. #
  49. # [*create_networks*]
  50. # (optional) Whether actual nova networks should be created using
  51. # the fixed and floating ranges provided.
  52. # Defaults to true
  53. #
  54. # [*ensure_package*]
  55. # (optional) The state of the nova network package
  56. # Defaults to 'present'
  57. #
  58. # [*install_service*]
  59. # (optional) Whether to install and enable the service
  60. # Defaults to true
  61. #
  62. # [*allowed_start*]
  63. # (optional) Start of allowed addresses for instances
  64. # Defaults to undef
  65. #
  66. # [*allowed_end*]
  67. # (optional) End of allowed addresses for instances
  68. # Defaults to undef
  69. #
  70. # [*dns1*]
  71. # (optional) First DNS server
  72. # Defaults to undef
  73. #
  74. # [*dns2*]
  75. # (optional) Second DNS server
  76. # Defaults to undef
  77. #
  78. # [*multi_host*]
  79. # (optional) Default value for multi_host in networks.
  80. # Also, if set, some rpc network calls will be sent directly to host.
  81. # Defaults to false.
  82. #
  83. # [*auto_assign_floating_ip*]
  84. # (optional) Autoassigning floating IP to VM
  85. # Defaults to false.
  86. #
  87. class nova::network(
  88. $private_interface = undef,
  89. $fixed_range = '10.0.0.0/8',
  90. $public_interface = undef,
  91. $num_networks = 1,
  92. $network_size = 255,
  93. $floating_range = false,
  94. $enabled = true,
  95. $network_manager = 'nova.network.manager.FlatDHCPManager',
  96. $config_overrides = {},
  97. $create_networks = true,
  98. $ensure_package = 'present',
  99. $install_service = true,
  100. $allowed_start = undef,
  101. $allowed_end = undef,
  102. $dns1 = undef,
  103. $dns2 = undef,
  104. $multi_host = false,
  105. $auto_assign_floating_ip = false,
  106. ) {
  107. include ::nova::deps
  108. include ::nova::params
  109. warning('nova-network is deprecated in Newton and will be removed in the future.')
  110. # forward all ipv4 traffic
  111. # this is required for the vms to pass through the gateways
  112. # public interface
  113. Exec {
  114. path => $::path
  115. }
  116. ensure_resource('sysctl::value', 'net.ipv4.ip_forward', { value => '1' })
  117. if $floating_range {
  118. nova_config {
  119. 'DEFAULT/floating_range': value => $floating_range;
  120. 'DEFAULT/auto_assign_floating_ip': value => $auto_assign_floating_ip;
  121. }
  122. }
  123. nova_config {
  124. 'DEFAULT/multi_host': value => $multi_host;
  125. }
  126. if has_key($config_overrides, 'vlan_start') {
  127. $vlan_start = $config_overrides['vlan_start']
  128. } else {
  129. $vlan_start = undef
  130. }
  131. if $install_service {
  132. nova::generic_service { 'network':
  133. enabled => $enabled,
  134. package_name => $::nova::params::network_package_name,
  135. service_name => $::nova::params::network_service_name,
  136. ensure_package => $ensure_package,
  137. before => Exec['networking-refresh']
  138. }
  139. # because nova_network provider uses nova client, so it assumes
  140. # that nova-network service is running already
  141. Service<| title == 'nova-network' |> -> Nova_network<| |>
  142. if $create_networks {
  143. if $enabled {
  144. nova::manage::network { 'nova-vm-net':
  145. network => $fixed_range,
  146. num_networks => $num_networks,
  147. network_size => $network_size,
  148. vlan_start => $vlan_start,
  149. allowed_start => $allowed_start,
  150. allowed_end => $allowed_end,
  151. dns1 => $dns1,
  152. dns2 => $dns2,
  153. }
  154. if $floating_range {
  155. nova::manage::floating { 'nova-vm-floating':
  156. network => $floating_range,
  157. }
  158. }
  159. } else {
  160. warning('Can not create networks, when nova-network service is disabled.')
  161. }
  162. }
  163. }
  164. case $network_manager {
  165. 'nova.network.manager.FlatDHCPManager': {
  166. # I am not proud of this
  167. $parameters = { fixed_range => $fixed_range,
  168. public_interface => $public_interface,
  169. flat_interface => $private_interface
  170. }
  171. $resource_parameters = merge($config_overrides, $parameters)
  172. $flatdhcp_resource = {'nova::network::flatdhcp' => $resource_parameters }
  173. create_resources('class', $flatdhcp_resource)
  174. }
  175. 'nova.network.manager.FlatManager': {
  176. $parameters = { fixed_range => $fixed_range,
  177. public_interface => $public_interface,
  178. flat_interface => $private_interface
  179. }
  180. $resource_parameters = merge($config_overrides, $parameters)
  181. $flat_resource = {'nova::network::flat' => $resource_parameters }
  182. create_resources('class', $flat_resource)
  183. }
  184. 'nova.network.manager.VlanManager': {
  185. $parameters = { fixed_range => $fixed_range,
  186. public_interface => $public_interface,
  187. vlan_interface => $private_interface
  188. }
  189. $resource_parameters = merge($config_overrides, $parameters)
  190. $vlan_resource = { 'nova::network::vlan' => $resource_parameters }
  191. create_resources('class', $vlan_resource)
  192. }
  193. default: {
  194. fail("Unsupported network manager: ${nova::network_manager} The supported network managers are \
  195. nova.network.manager.FlatManager, nova.network.FlatDHCPManager and nova.network.manager.VlanManager")
  196. }
  197. }
  198. }