File: mysql_server_id.rb

package info (click to toggle)
puppet-module-puppetlabs-mysql 15.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 968 kB
  • sloc: ruby: 1,648; sh: 43; makefile: 5
file content (22 lines) | stat: -rw-r--r-- 591 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# frozen_string_literal: true

def mysql_id_get
  # Convert the existing mac to an integer
  macval = Facter.value(:macaddress).delete(':').to_i(16)

  # Valid range is from 1 - 4294967295 for replication hosts.
  # We can not guarantee a fully unique value, this reduces the
  # full mac value down to into that number space.
  #
  # The -1/+1 ensures that we keep above 1 if we get unlucky
  # enough to hit a mac address that evenly divides.
  (macval % (4_294_967_295 - 1)) + 1
end

Facter.add('mysql_server_id') do
  setcode do
    mysql_id_get
  rescue StandardError
    nil
  end
end