facter_ipaddress_primary 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/bin/ipaddress_primary_path +2 -0
- data/bin/ipaddress_primary_path.rb +10 -0
- data/facter_ipaddress_primary.gemspec +15 -0
- data/lib/facter/ipaddress_primary.rb +33 -0
- data/readme.md +25 -0
- metadata +64 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d45d079e786ade6a760604afaacbd4fa1ae2a772
|
4
|
+
data.tar.gz: 7f9242b93dbc6b15f357d9e67b76eb2069b9704e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: abd5e66f9b5e0953c2b1e756190c23d3c153926bb77924bb13d8ffcea21750304075af127f379c814c1b10cb088ce751bf8acb118ca773b06c3742f90a12fdab
|
7
|
+
data.tar.gz: 6286f080bff66f435d32aa4c06c0bb94ac9b6959327269cd89fdfeca997342b9ec88e8d67e275b3fac683fbd0cc08054565829b52eb84755d6fe1483e14a299a
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# FACTERLIB return/wrapper
|
2
|
+
path = File.expand_path('../../lib/facter', __FILE__)
|
3
|
+
# Exec?
|
4
|
+
unless ARGV.empty?
|
5
|
+
env = ENV.to_hash
|
6
|
+
env['FACTERLIB'] = [env['FACTERLIB'], path].compact.join(':')
|
7
|
+
Process.exec(env, *ARGV)
|
8
|
+
end
|
9
|
+
# Simple return if not used to call facter
|
10
|
+
puts path
|
@@ -0,0 +1,15 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
raise 'RubyGems 2.0 or newer is required.' unless spec.respond_to?(:metadata)
|
3
|
+
spec.name = File.basename(__FILE__, '.*')
|
4
|
+
spec.files = `git ls-files -z`.split("\x0")
|
5
|
+
spec.executables = ['ipaddress_primary_path']
|
6
|
+
spec.summary = 'ipaddress_primary fact for facter gem'
|
7
|
+
spec.version = '1.0.0'
|
8
|
+
spec.authors = ['Andrew Smith']
|
9
|
+
spec.email = ['andrew.smith at moneysupermarket.com']
|
10
|
+
spec.description = 'Determines more reliably primary/default NIC in multiple'\
|
11
|
+
' NIC scenarios'
|
12
|
+
spec.homepage = 'https://github.com/MSMFG/rubygem_facter_ipaddress_primary'
|
13
|
+
spec.license = 'Apache-2.0'
|
14
|
+
spec.add_dependency('facter', '~>2')
|
15
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# ipaddress_primary.rb
|
2
|
+
require 'socket'
|
3
|
+
|
4
|
+
# Determine closest NICs to target addresses and provide a default NIC
|
5
|
+
class AdjacentNicTool
|
6
|
+
# As good as any address for adjacent NIC address test
|
7
|
+
AWS_INSTANCE_METADATA_ADDRESS = '169.254.169.254'.freeze
|
8
|
+
|
9
|
+
# The main NIC determined adjacent to the meta address
|
10
|
+
def self.default_nic
|
11
|
+
adjacent_local(AWS_INSTANCE_METADATA_ADDRESS)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Find closest NIC address to target if we have multiple NICs
|
15
|
+
# (reliable local NIC determination)
|
16
|
+
# Note: UDP Sockets do NOT send anything on connect
|
17
|
+
# but DO work out what source address will be
|
18
|
+
# used so the port number is irrelevant to this
|
19
|
+
# mechanism.
|
20
|
+
def self.adjacent_local(addr)
|
21
|
+
dummy_sock = UDPSocket.new
|
22
|
+
dummy_sock.connect(addr, 1)
|
23
|
+
_fam, _port, _name, addr = dummy_sock.addr
|
24
|
+
addr
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
Facter.add(:ipaddress_primary) do
|
29
|
+
confine kernel: %w[Linux FreeBSD OpenBSD SunOS HP-UX Darwin GNU/kFreeBSD]
|
30
|
+
setcode do
|
31
|
+
AdjacentNicTool.default_nic
|
32
|
+
end
|
33
|
+
end
|
data/readme.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# facter_ipaddress_primary
|
2
|
+
|
3
|
+
A custom fact for facter that reliably determines the primary NIC based upon the NIC chosen adjacent to the default gateway by using UDP sockets.
|
4
|
+
|
5
|
+
Since facter lacks the ability to locate custom facts within gems a wrapper/handler can be used to manage the FACTERLIB environment for you.
|
6
|
+
|
7
|
+
Usage:
|
8
|
+
|
9
|
+
```
|
10
|
+
$ # Appends to FACTERLIB environment variable and execs the specified program
|
11
|
+
$ ipaddress_primary_path facter | grep ipaddress
|
12
|
+
ipaddress => 10.11.90.148
|
13
|
+
ipaddress_en0 => 10.11.90.148
|
14
|
+
ipaddress_en5 => 10.10.27.133
|
15
|
+
ipaddress_lo0 => 127.0.0.1
|
16
|
+
ipaddress_primary => 10.10.27.133
|
17
|
+
lib => /usr/local/lib/ruby/gems/2.1.0/gems/facter_ipaddress_primary-1.0.0.pre/lib/facter
|
18
|
+
|
19
|
+
$ # No arguments returns the path where the library resides..
|
20
|
+
$ ipaddress_primary_path
|
21
|
+
/usr/local/lib/ruby/gems/2.1.0/gems/facter_ipaddress_primary-1.0.0.pre/lib/facter
|
22
|
+
|
23
|
+
# And this can alternatively be used to add to the path in a script if you prefer that approach
|
24
|
+
export FACTERLIB="${FACTERLIB}:`ipaddress_primary_path`"
|
25
|
+
```
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: facter_ipaddress_primary
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrew Smith
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-01-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: facter
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2'
|
27
|
+
description: Determines more reliably primary/default NIC in multiple NIC scenarios
|
28
|
+
email:
|
29
|
+
- andrew.smith at moneysupermarket.com
|
30
|
+
executables:
|
31
|
+
- ipaddress_primary_path
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- bin/ipaddress_primary_path
|
36
|
+
- bin/ipaddress_primary_path.rb
|
37
|
+
- facter_ipaddress_primary.gemspec
|
38
|
+
- lib/facter/ipaddress_primary.rb
|
39
|
+
- readme.md
|
40
|
+
homepage: https://github.com/MSMFG/rubygem_facter_ipaddress_primary
|
41
|
+
licenses:
|
42
|
+
- Apache-2.0
|
43
|
+
metadata: {}
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 2.2.5
|
61
|
+
signing_key:
|
62
|
+
specification_version: 4
|
63
|
+
summary: ipaddress_primary fact for facter gem
|
64
|
+
test_files: []
|