pingable_ipam_plugin 0.0.3 → 0.0.4

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
  SHA256:
3
- metadata.gz: 98f252592af66182ea5caa67ee7e6277b0d6c9a93a746b28c2f949cc13019176
4
- data.tar.gz: f5e007d453bd182a85d3e20bf0441c5276ae9365d9267fe9c8541d2fa187d731
3
+ metadata.gz: aeceeb843ba71802fb376e640611a2cbfeb6930ca5d5ed53322d5ff1443b522b
4
+ data.tar.gz: c1f5ab6782c6284e681d504b3c2ba59117f607dc97113227c5569f318d15f7cc
5
5
  SHA512:
6
- metadata.gz: 001c810cfc73df2a3a3cf0d767b63c5e13f1b53d29d536d13248ee045ec26cf804474c7e71f903f70814d9143ddd431182d5b362b7a1317744ed336984f09542
7
- data.tar.gz: 648e49b2f2884c8bdce12f7bb79b6df125f2d8c32d7cc4bb8c4ea272b063f712c9e881593b51974a35d8bcd178f9742447c3752908a3dd9602c35872156ca26e
6
+ metadata.gz: 183012661a3052bc4d8377c3e5b1776bd7cd9105e517e7abd77d95caf464517f397c3c885c01373011c8d98a33e835620e595c730f0ca0e5653d283f40685ff5
7
+ data.tar.gz: a8eb59ddf63772f174ce842bef1da3fcc6d365894489d4c392f776093a50ac09e78feac5cc162b4310646c82e1f97278e5ecb75d00193fff6738d3fe1b252faa
@@ -7,8 +7,8 @@ module IPAM
7
7
  @generator ||= Random.new(mac ? mac.delete(':').to_i(16) : Random.new_seed)
8
8
  end
9
9
 
10
- def random_ip
11
- IPAddr.new(generator.rand(subnet_range.first.to_i..subnet_range.last.to_i), subnet.family)
10
+ def random_ip(range)
11
+ IPAddr.new(generator.rand(range.first.to_i..range.last.to_i), subnet.family)
12
12
  end
13
13
 
14
14
  def tcp_pingable?(ip)
@@ -32,30 +32,16 @@ module IPAM
32
32
  # Whether or not Errno::ECONNREFUSED is considered a successful ping
33
33
  @service_check = true
34
34
  @timeout = 1
35
- @exception = nil
36
35
  bool = false
37
- tcp = nil
38
36
 
39
37
  begin
40
- Timeout.timeout(@timeout) do
41
- begin
42
- tcp = TCPSocket.new(ip, port)
43
- rescue Errno::ECONNREFUSED => err
44
- if @service_check
45
- bool = true
46
- else
47
- @exception = err
48
- end
49
- rescue Exception => err
50
- @exception = err
51
- else
52
- bool = true
53
- end
38
+ bool = Socket.tcp(ip, port, connect_timeout: @timeout) { true }
39
+ rescue Errno::ECONNREFUSED
40
+ if @service_check
41
+ bool = true
54
42
  end
55
- rescue Timeout::Error => err
56
- @exception = err
57
- ensure
58
- tcp.close if tcp
43
+ rescue Exception
44
+ bool = false
59
45
  end
60
46
 
61
47
  if bool
@@ -87,13 +73,18 @@ module IPAM
87
73
 
88
74
  def suggest_ip
89
75
  iterations = 0
76
+ # Remove IPs already excluded or known.
77
+ range = subnet_range.to_a - excluded_ips.to_a
78
+ range -= subnet.known_ips.to_a
79
+
90
80
  loop do
91
81
  # next random IP from the sequence generated by MAC seed
92
- candidate = random_ip
82
+ candidate = random_ip(range)
93
83
  iterations += 1
94
84
  break if iterations >= MAX_ITERATIONS
95
85
  # try to match it
96
86
  ip = candidate.to_s
87
+ # Check again if something has been changed.
97
88
  if !excluded_ips.include?(ip) && !subnet.known_ips.include?(ip)
98
89
  logger.debug "Searching for free IP - pinging #{ip}."
99
90
  if tcp_pingable?(ip) || icmp_pingable?(ip)
@@ -1,3 +1,3 @@
1
1
  module PingableIpamPlugin
2
- VERSION = '0.0.3'.freeze
2
+ VERSION = '0.0.4'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pingable_ipam_plugin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Parshin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-20 00:00:00.000000000 Z
11
+ date: 2020-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop