furnish-ip 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +7 -0
- data/Gemfile +2 -0
- data/Rakefile +2 -1
- data/furnish-ip.gemspec +2 -2
- data/lib/furnish/ip.rb +21 -3
- data/lib/furnish/ip/version.rb +1 -1
- data/test/test_ip_lib.rb +26 -1
- metadata +8 -8
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
* 0.0.3 (03/25/2013)
|
2
|
+
* Several fixes around the encoding of IP addresses -- fixes Ruby 2.0.0-p0
|
3
|
+
issues.
|
4
|
+
* Furnish::IP#allocate and Furnish::IP#allocated? exist to assist with direct
|
5
|
+
allocations.
|
6
|
+
* Documentation is generated with RDoc 4
|
7
|
+
* Depend on Furnish 0.0.4
|
1
8
|
* 0.0.2 (03/20/2013)
|
2
9
|
* Migration to and exploitation of furnish 0.0.2
|
3
10
|
* 0.0.1 (03/20/2013)
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -10,7 +10,8 @@ end
|
|
10
10
|
|
11
11
|
RDoc::Task.new do |rdoc|
|
12
12
|
rdoc.title = "Generic IP allocator for the Furnish provisioning system"
|
13
|
-
rdoc.
|
13
|
+
rdoc.main = "README.md"
|
14
|
+
rdoc.rdoc_files.include("README.md", "lib/**/*.rb")
|
14
15
|
rdoc.rdoc_files -= ["lib/furnish/ip/version.rb"]
|
15
16
|
if ENV["RDOC_COVER"]
|
16
17
|
rdoc.options << "-C"
|
data/furnish-ip.gemspec
CHANGED
@@ -17,14 +17,14 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
18
|
gem.require_paths = ["lib"]
|
19
19
|
|
20
|
-
gem.add_dependency 'furnish', '~> 0.0.
|
20
|
+
gem.add_dependency 'furnish', '~> 0.0.4'
|
21
21
|
gem.add_dependency 'palsy', '~> 0.0.2'
|
22
22
|
|
23
23
|
gem.add_development_dependency 'rake'
|
24
24
|
gem.add_development_dependency 'minitest', '~> 4.5.0'
|
25
25
|
gem.add_development_dependency 'guard-minitest'
|
26
26
|
gem.add_development_dependency 'guard-rake'
|
27
|
-
gem.add_development_dependency 'rdoc'
|
27
|
+
gem.add_development_dependency 'rdoc', '~> 4'
|
28
28
|
gem.add_development_dependency 'rb-fsevent'
|
29
29
|
gem.add_development_dependency 'simplecov'
|
30
30
|
end
|
data/lib/furnish/ip.rb
CHANGED
@@ -46,6 +46,23 @@ module Furnish # :nodoc:
|
|
46
46
|
@groups = Palsy::Map.new('furnish_ip_groups', name)
|
47
47
|
end
|
48
48
|
|
49
|
+
#
|
50
|
+
# Allocates an IP without putting it in a group. Useful for placeholders.
|
51
|
+
#
|
52
|
+
# Makes no attempt to check if something's allocated already.
|
53
|
+
#
|
54
|
+
|
55
|
+
def allocate(ip)
|
56
|
+
allocated.add(ip.encode("UTF-8"))
|
57
|
+
end
|
58
|
+
|
59
|
+
#
|
60
|
+
# Predicate to determine whether or not an IP is already allocated.
|
61
|
+
#
|
62
|
+
def allocated?(ip)
|
63
|
+
allocated.include?(ip.encode("UTF-8"))
|
64
|
+
end
|
65
|
+
|
49
66
|
#
|
50
67
|
# Determine, based on allocations already made, what the next available
|
51
68
|
# un-used IP is. Will raise ArgumentError if #new is not provided with an
|
@@ -63,7 +80,7 @@ module Furnish # :nodoc:
|
|
63
80
|
net = subnet
|
64
81
|
|
65
82
|
subnet_range.count.times do
|
66
|
-
this_ip = net.to_s
|
83
|
+
this_ip = net.to_s.encode("UTF-8")
|
67
84
|
|
68
85
|
return this_ip unless allocated.include?(this_ip)
|
69
86
|
|
@@ -93,8 +110,9 @@ module Furnish # :nodoc:
|
|
93
110
|
group = group_ips(name)
|
94
111
|
|
95
112
|
ips.each do |ip|
|
96
|
-
|
97
|
-
|
113
|
+
utf8_ip = ip.encode("UTF-8")
|
114
|
+
allocated.add(utf8_ip)
|
115
|
+
group.add(utf8_ip)
|
98
116
|
end
|
99
117
|
|
100
118
|
groups[name] = group
|
data/lib/furnish/ip/version.rb
CHANGED
data/test/test_ip_lib.rb
CHANGED
@@ -19,7 +19,7 @@ class TestIPLib < Furnish::TestCase
|
|
19
19
|
assert_equal("127.0.0.0", ip.unused_ip, "picks the next available ip")
|
20
20
|
assert_equal("127.0.0.0", ip.unused_ip, "has no side effects -- returns the same IP on the second call")
|
21
21
|
|
22
|
-
ip.
|
22
|
+
ip.allocate("127.0.0.0") # add something to get it to choose the next thing.
|
23
23
|
|
24
24
|
assert_equal("127.0.0.1", ip.unused_ip, "picks the next unavailable ip")
|
25
25
|
|
@@ -27,6 +27,31 @@ class TestIPLib < Furnish::TestCase
|
|
27
27
|
assert_raises(ArgumentError, "Furnish::IP#unused_ip requires an IPAddr object to work") { ip.unused_ip }
|
28
28
|
end
|
29
29
|
|
30
|
+
def test_encoding
|
31
|
+
ip = Furnish::IP.new(IPAddr.new("127.0.0.1/24"))
|
32
|
+
|
33
|
+
%w[ASCII-8BIT UTF-8].each_with_index do |enc, i|
|
34
|
+
ip.allocate("127.0.0.#{i}".encode(enc))
|
35
|
+
assert(ip.allocated?("127.0.0.#{i}".encode(enc)), "127.0.0.#{i} is allocated with a string with encoding #{enc}")
|
36
|
+
end
|
37
|
+
|
38
|
+
ip.allocate("127.0.0.42".encode("ASCII-8BIT"))
|
39
|
+
assert(ip.allocated?("127.0.0.42".encode("UTF-8")), "127.0.0.42 was allocated encoding-agnostic")
|
40
|
+
|
41
|
+
ip.assign_group_ips("foo", "127.0.0.23".encode("ASCII-8BIT"))
|
42
|
+
assert_equal("UTF-8", ip.group_ips("foo").first.encoding.to_s, "encoding always comes back UTF-8")
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_allocated
|
46
|
+
ip = Furnish::IP.new(IPAddr.new("127.0.0.1/24"))
|
47
|
+
ip.allocate("127.0.0.0")
|
48
|
+
assert(ip.allocated?("127.0.0.0"), "127.0.0.0 is allocated")
|
49
|
+
|
50
|
+
ip.assign_group_ips("foo", "127.0.0.1")
|
51
|
+
|
52
|
+
assert(ip.allocated?("127.0.0.1"), "127.0.0.1 is allocated by way of a group")
|
53
|
+
end
|
54
|
+
|
30
55
|
def test_cycle_detection
|
31
56
|
ip = Furnish::IP.new(IPAddr.new("127.0.0.1/31"))
|
32
57
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: furnish-ip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03-
|
12
|
+
date: 2013-03-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: furnish
|
@@ -18,7 +18,7 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 0.0.
|
21
|
+
version: 0.0.4
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 0.0.
|
29
|
+
version: 0.0.4
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: palsy
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -112,17 +112,17 @@ dependencies:
|
|
112
112
|
requirement: !ruby/object:Gem::Requirement
|
113
113
|
none: false
|
114
114
|
requirements:
|
115
|
-
- -
|
115
|
+
- - ~>
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
117
|
+
version: '4'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
none: false
|
122
122
|
requirements:
|
123
|
-
- -
|
123
|
+
- - ~>
|
124
124
|
- !ruby/object:Gem::Version
|
125
|
-
version: '
|
125
|
+
version: '4'
|
126
126
|
- !ruby/object:Gem::Dependency
|
127
127
|
name: rb-fsevent
|
128
128
|
requirement: !ruby/object:Gem::Requirement
|