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 +4 -4
- data/app/services/ipam/ping_random_db.rb +14 -23
- data/lib/pingable_ipam_plugin/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aeceeb843ba71802fb376e640611a2cbfeb6930ca5d5ed53322d5ff1443b522b
|
4
|
+
data.tar.gz: c1f5ab6782c6284e681d504b3c2ba59117f607dc97113227c5569f318d15f7cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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(
|
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
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
56
|
-
|
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)
|
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.
|
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-
|
11
|
+
date: 2020-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|