Skip to content

Added server_id fact #686

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,14 @@ The name of the MySQL plugin to manage.

The library file name.

###Facts

####`mysql_server_id`

Generates a unique id, based on the node's MAC address, which can be used as
`server_id`. This fact will *always* return `0` on all nodes which only have
loopback interfaces. Given those nodes' connnectivity that's probably okay.

##Limitations

This module has been tested on:
Expand Down
9 changes: 9 additions & 0 deletions lib/facter/mysql_server_id.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def get_mysql_id
Facter.value(:macaddress).split(':').inject(0) { |total,value| (total << 4) + value.hex }
end

Facter.add("mysql_server_id") do
setcode do
get_mysql_id
end
end
27 changes: 27 additions & 0 deletions spec/unit/facter/mysql_server_id_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require "spec_helper"

describe Facter::Util::Fact do
before {
Facter.clear
}

describe "mysql_server_id" do
context "igalic's laptop" do
before :each do
Facter.fact(:macaddress).stubs(:value).returns('3c:97:0e:69:fb:e1')
end
it do
Facter.fact(:mysql_server_id).value.to_s.should == '72898961'
end
end

context "node with lo only" do
before :each do
Facter.fact(:macaddress).stubs(:value).returns('00:00:00:00:00:00')
end
it do
Facter.fact(:mysql_server_id).value.to_s.should == '0'
end
end
end
end