Skip to content

Commit

Permalink
IPv6: ntp.conf requires netmask in non CIDR format
Browse files Browse the repository at this point in the history
The ntp.conf used in crowbar wont work with IPv6 as the netmask
in the ntp conf file need to be in the full form not CIDR.

This patch adds a new method, cidr_to_subnet to the Barclamp library's
Network class. Which is then used to send the correct string to the
ntp.conf.erb template.

Allowing the crowbar nodes being booted via the sleshammer discovery
image to sync with the admin node.
  • Loading branch information
matthewoliver authored and nicolasbock committed Jul 2, 2019
1 parent f83ff7b commit a8e9b8e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
24 changes: 24 additions & 0 deletions chef/cookbooks/barclamp/libraries/barclamp_library.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,30 @@ def interface_list
@interface_list
end

def cidr_to_netmask
if @ip_version == "6"
range = 128
else
range = 32
end

cidr = Integer(@netmask) rescue nil
if cidr && !(1..range).cover?(cidr)
Chef::Log.error("Invalid CIDR netmask '#{cidr}' > '#{range}'")
return @netmask
end

if cidr
if @ip_version == "6"
IPAddr.new('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff').mask(cidr).to_s
else
IPAddr.new('255.255.255.255').mask(cidr).to_s
end
else
@netmask
end
end

protected

def resolve_interface_info
Expand Down
2 changes: 1 addition & 1 deletion chef/cookbooks/ntp/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
variables(ntp_servers: ntp_servers,
admin_interface: local_admin_address,
admin_subnet: admin_net.subnet,
admin_netmask: admin_net.netmask,
admin_netmask: admin_net.cidr_to_netmask(),
is_server: is_server,
listen_interfaces: listen_network_addresses || [],
fudgevalue: 10,
Expand Down

0 comments on commit a8e9b8e

Please sign in to comment.