facter_ipaddress_primary 1.0.1 → 1.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 96264df46f91df9533bb598918bb1240971b33c0
4
- data.tar.gz: 0a8cbf5a31d761b4fe9341a39f2644578fd4a3a0
3
+ metadata.gz: 4ddf2db0ab603b4cc7e33564caf84e4acd6ce833
4
+ data.tar.gz: 1e3d6f222a45cb90fa1a85fba15c339af9154ab2
5
5
  SHA512:
6
- metadata.gz: 409aea4ed9e4629af7da449d118b2bb551d9529666c91ad0e5dfdf4d0df986e62b2b2112133cf4b3fbf15a0a0d77bf73a5c4caf731ee38b2986d23f21fb6d8d4
7
- data.tar.gz: d9a83e4f1493939ce137ef7024086b3b51e33966411280abb62de46e4ab9cb09f58be5193b89adc4701f239eccce138a895fd1646dee3594021276695b31137c
6
+ metadata.gz: 9893cc558a72b03bac062d8d05ce84f99a86fde41ed7dd1111598ce83be1522aea1d9a4754c89221d434dc134fa6cf0c2ca65dc55a8408417d31ed72da80cfc3
7
+ data.tar.gz: edec7b776463fb90eec64c5006b0b1b21899b8b196faea827005082460c4f6ceba1c63b83e41d53f61b718eeeb79fe8dea9ef1e428bf361c8bf707d3db37f291
@@ -4,7 +4,7 @@ Gem::Specification.new do |spec|
4
4
  spec.files = `git ls-files -z`.split("\x0")
5
5
  spec.executables = ['ipaddress_primary_path']
6
6
  spec.summary = 'facter ipaddress_primary fact giving a more reliable selection for main NIC'
7
- spec.version = '1.0.1'
7
+ spec.version = '1.1.0'
8
8
  spec.authors = ['Andrew Smith']
9
9
  spec.email = ['andrew.smith at moneysupermarket.com']
10
10
  spec.description = 'Determines more reliably primary/default NIC in multiple'\
@@ -7,10 +7,22 @@ class AdjacentNicTool
7
7
  AWS_INSTANCE_METADATA_ADDRESS = '169.254.169.254'.freeze
8
8
 
9
9
  # The main NIC determined adjacent to the meta address
10
- def self.default_nic
10
+ def self.default_nic_address
11
11
  adjacent_local(AWS_INSTANCE_METADATA_ADDRESS)
12
12
  end
13
13
 
14
+ def self.nic_translation
15
+ nictable = Socket.getifaddrs.map do |nic|
16
+ next unless nic.addr.ipv4?
17
+ [nic.addr.ip_address, nic.name]
18
+ end
19
+ Hash[nictable.compact]
20
+ end
21
+
22
+ def self.default_nic
23
+ nic_translation[default_nic_address]
24
+ end
25
+
14
26
  # Find closest NIC address to target if we have multiple NICs
15
27
  # (reliable local NIC determination)
16
28
  # Note: UDP Sockets do NOT send anything on connect
@@ -28,6 +40,13 @@ end
28
40
  Facter.add(:ipaddress_primary) do
29
41
  confine kernel: %w[Linux FreeBSD OpenBSD SunOS HP-UX Darwin GNU/kFreeBSD]
30
42
  setcode do
31
- AdjacentNicTool.default_nic
43
+ AdjacentNicTool.default_nic_address
32
44
  end
33
45
  end
46
+
47
+ Facter.add(:primary_nic) do
48
+ confine kernel: %w[Linux FreeBSD OpenBSD SunOS HP-UX Darwin GNU/kFreeBSD]
49
+ setcode do
50
+ AdjacentNicTool.default_nic
51
+ end
52
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: facter_ipaddress_primary
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Smith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-16 00:00:00.000000000 Z
11
+ date: 2018-04-23 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Determines more reliably primary/default NIC in multiple NIC scenarios
14
14
  email: