ohai 0.6.12.rc.4 → 0.6.12.rc.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ohai/plugins/linux/network.rb +21 -0
- data/lib/ohai/plugins/network.rb +7 -0
- data/lib/ohai/version.rb +1 -1
- data/spec/ohai/plugins/linux/network_spec.rb +60 -2
- metadata +2 -47
@@ -196,6 +196,27 @@ if File.exist?("/sbin/ip")
|
|
196
196
|
end
|
197
197
|
end
|
198
198
|
|
199
|
+
popen4("ip route show scope link") do |pid, stdin, stdout, stderr|
|
200
|
+
stdin.close
|
201
|
+
stdout.each do |line|
|
202
|
+
if line =~ /^([^\s]+)\s+dev\s+([^\s]+).*\s+src\s+([^\s]+)\b/
|
203
|
+
tmp_route_cidr = $1
|
204
|
+
tmp_int = $2
|
205
|
+
tmp_source_addr = $3
|
206
|
+
unless iface[tmp_int]
|
207
|
+
Ohai::Log.debug("Skipping previously unseen interface from 'ip route show scope link': #{tmp_int}")
|
208
|
+
next
|
209
|
+
end
|
210
|
+
iface[tmp_int][:routes] = Mash.new unless iface[tmp_int][:routes]
|
211
|
+
iface[tmp_int][:routes][tmp_route_cidr] = Mash.new( :scope => "Link", :src => tmp_source_addr )
|
212
|
+
if (network[:default_interface] == tmp_int ) && (IPAddr.new(tmp_route_cidr).include? network[:default_gateway])
|
213
|
+
ipaddress tmp_source_addr
|
214
|
+
macaddress iface[tmp_int][:addresses].select{|k,v| v["family"]=="lladdr"}.first.first
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
199
220
|
else
|
200
221
|
|
201
222
|
begin
|
data/lib/ohai/plugins/network.rb
CHANGED
@@ -25,9 +25,16 @@ network[:interfaces] = Mash.new unless network[:interfaces]
|
|
25
25
|
counters Mash.new unless counters
|
26
26
|
counters[:network] = Mash.new unless counters[:network]
|
27
27
|
|
28
|
+
ipaddress nil
|
29
|
+
macaddress nil
|
30
|
+
|
28
31
|
require_plugin "hostname"
|
29
32
|
require_plugin "#{os}::network"
|
30
33
|
|
34
|
+
# ipaddress and macaddress can be set from the #{os}::network plugin
|
35
|
+
# both ipaddress and macaddress have to be set in that case
|
36
|
+
return unless ipaddress.nil? or macaddress.nil?
|
37
|
+
|
31
38
|
def find_ip_and_mac(addresses, match = nil)
|
32
39
|
ip = nil; mac = nil
|
33
40
|
addresses.keys.each do |addr|
|
data/lib/ohai/version.rb
CHANGED
@@ -176,11 +176,20 @@ NEIGHBOR_SHOW
|
|
176
176
|
default via 10.116.201.1 dev eth0
|
177
177
|
IP_ROUTE
|
178
178
|
|
179
|
+
linux_ip_route_scope_link = <<-IP_ROUTE_SCOPE
|
180
|
+
10.116.201.0/24 dev eth0 proto kernel src 10.116.201.76
|
181
|
+
192.168.5.0/24 dev eth0 proto kernel src 192.168.5.1
|
182
|
+
192.168.212.0/24 dev foo:veth0@eth0 proto kernel src 192.168.212.2
|
183
|
+
172.16.151.0/24 dev eth0 proto kernel src 172.16.151.100
|
184
|
+
192.168.0.0/24 dev eth0 proto kernel src 192.168.0.2
|
185
|
+
IP_ROUTE_SCOPE
|
186
|
+
|
179
187
|
@stdin_ifconfig = StringIO.new
|
180
188
|
@stdin_arp = StringIO.new
|
181
189
|
@stdin_ipaddr = StringIO.new
|
182
190
|
@stdin_iplink = StringIO.new
|
183
191
|
@stdin_ipneighbor = StringIO.new
|
192
|
+
@stdin_ip_route_scope_link = StringIO.new
|
184
193
|
|
185
194
|
@ifconfig_lines = linux_ifconfig.split("\n")
|
186
195
|
@route_lines = linux_route_n.split("\n")
|
@@ -189,6 +198,7 @@ IP_ROUTE
|
|
189
198
|
@iplink_lines = linux_ip_link_s_d.split("\n")
|
190
199
|
@ipneighbor_lines = linux_ip_neighbor_show.split("\n")
|
191
200
|
@iproute_lines = linux_ip_route_show_exact
|
201
|
+
@ip_route_scope_link_lines = linux_ip_route_scope_link.split("\n")
|
192
202
|
|
193
203
|
@ohai = Ohai::System.new
|
194
204
|
@ohai.stub!(:require_plugin).and_return(true)
|
@@ -209,6 +219,7 @@ IP_ROUTE
|
|
209
219
|
@ohai.stub!(:popen4).with("ip neighbor show").and_yield(nil, @stdin_ipneighbor, @ipneighbor_lines, nil)
|
210
220
|
@ohai.stub!(:popen4).with("ip addr").and_yield(nil, @stdin_ipaddr, @ipaddr_lines, nil)
|
211
221
|
@ohai.stub!(:popen4).with("ip -d -s link").and_yield(nil, @stdin_iplink, @iplink_lines, nil)
|
222
|
+
@ohai.stub!(:popen4).with("ip route show scope link").and_yield(nil, @stdin_ip_route_scope_link, @ip_route_scope_link_lines, nil)
|
212
223
|
@ohai._require_plugin("network")
|
213
224
|
@ohai._require_plugin("linux::network")
|
214
225
|
end
|
@@ -313,6 +324,7 @@ IP_ROUTE
|
|
313
324
|
@ohai.stub!(:popen4).with("ip neighbor show").and_yield(nil, @stdin_ipneighbor, @ipneighbor_lines, nil)
|
314
325
|
@ohai.stub!(:popen4).with("ip addr").and_yield(nil, @stdin_ipaddr, @ipaddr_lines, nil)
|
315
326
|
@ohai.stub!(:popen4).with("ip -d -s link").and_yield(nil, @stdin_iplink, @iplink_lines, nil)
|
327
|
+
@ohai.stub!(:popen4).with("ip route show scope link").and_yield(nil, @stdin_ip_route_scope_link, @ip_route_scope_link_lines, nil)
|
316
328
|
@ohai._require_plugin("network")
|
317
329
|
@ohai._require_plugin("linux::network")
|
318
330
|
end
|
@@ -421,31 +433,77 @@ ROUTE_N
|
|
421
433
|
@ohai.stub!(:popen4).with("ip neighbor show").and_yield(nil, @stdin_ipneighbor, @ipneighbor_lines, nil)
|
422
434
|
@ohai.stub!(:popen4).with("ip addr").and_yield(nil, @stdin_ipaddr, @ipaddr_lines, nil)
|
423
435
|
@ohai.stub!(:popen4).with("ip -d -s link").and_yield(nil, @stdin_iplink, @iplink_lines, nil)
|
424
|
-
@ohai.
|
425
|
-
@ohai._require_plugin("linux::network")
|
436
|
+
@ohai.stub!(:popen4).with("ip route show scope link").and_yield(nil, @stdin_ip_route_scope_link, @ip_route_scope_link_lines, nil)
|
426
437
|
end
|
427
438
|
|
428
439
|
it "detects the ipv4 addresses of an ethernet interface with a crazy name" do
|
440
|
+
@ohai._require_plugin("network")
|
441
|
+
@ohai._require_plugin("linux::network")
|
429
442
|
@ohai['network']['interfaces']['foo:veth0@eth0']['addresses'].keys.should include('192.168.212.2')
|
430
443
|
@ohai['network']['interfaces']['foo:veth0@eth0']['addresses']['192.168.212.2']['netmask'].should == '255.255.255.0'
|
431
444
|
@ohai['network']['interfaces']['foo:veth0@eth0']['addresses']['192.168.212.2']['family'].should == 'inet'
|
432
445
|
end
|
433
446
|
|
434
447
|
it "generates a fake interface for ip aliases for backward compatibility" do
|
448
|
+
@ohai._require_plugin("network")
|
449
|
+
@ohai._require_plugin("linux::network")
|
435
450
|
@ohai['network']['interfaces']['eth0:5']['addresses'].keys.should include('192.168.5.1')
|
436
451
|
@ohai['network']['interfaces']['eth0:5']['addresses']['192.168.5.1']['netmask'].should == '255.255.255.0'
|
437
452
|
@ohai['network']['interfaces']['eth0:5']['addresses']['192.168.5.1']['family'].should == 'inet'
|
438
453
|
end
|
439
454
|
|
440
455
|
it "adds the vlan information of an interface" do
|
456
|
+
@ohai._require_plugin("network")
|
457
|
+
@ohai._require_plugin("linux::network")
|
441
458
|
@ohai['network']['interfaces']['eth0.11']['vlan']['id'].should == '11'
|
442
459
|
@ohai['network']['interfaces']['eth0.11']['vlan']['flags'].should == [ 'REORDER_HDR' ]
|
443
460
|
end
|
444
461
|
|
445
462
|
it "adds the state of an interface" do
|
463
|
+
@ohai._require_plugin("network")
|
464
|
+
@ohai._require_plugin("linux::network")
|
446
465
|
@ohai['network']['interfaces']['eth0.11']['state'].should == 'up'
|
447
466
|
end
|
448
467
|
|
468
|
+
it "adds link level routes" do
|
469
|
+
@ohai._require_plugin("network")
|
470
|
+
@ohai._require_plugin("linux::network")
|
471
|
+
@ohai['network']['interfaces']['eth0']['routes']['10.116.201.0/24'].should == Mash.new( :scope => "Link", :src => "10.116.201.76" )
|
472
|
+
@ohai['network']['interfaces']['foo:veth0@eth0']['routes']['192.168.212.0/24'].should == Mash.new( :scope => "Link", :src => "192.168.212.2" )
|
473
|
+
end
|
474
|
+
|
475
|
+
describe "checking for the source address to reach the default gateway" do
|
476
|
+
it "sets ipaddress" do
|
477
|
+
@ohai._require_plugin("network")
|
478
|
+
@ohai._require_plugin("linux::network")
|
479
|
+
@ohai['ipaddress'].should == "10.116.201.76"
|
480
|
+
end
|
481
|
+
|
482
|
+
it "sets macaddress" do
|
483
|
+
@ohai._require_plugin("network")
|
484
|
+
@ohai._require_plugin("linux::network")
|
485
|
+
@ohai['macaddress'].should == "12:31:3D:02:BE:A2"
|
486
|
+
end
|
487
|
+
end
|
488
|
+
|
489
|
+
# This should never happen in the real world.
|
490
|
+
describe "when encountering a surprise interface" do
|
491
|
+
before do
|
492
|
+
linux_ip_route_scope_link = <<-IP_ROUTE_SCOPE
|
493
|
+
192.168.122.0/24 dev virbr0 proto kernel src 192.168.122.1
|
494
|
+
IP_ROUTE_SCOPE
|
495
|
+
@ip_route_scope_link_lines = linux_ip_route_scope_link.split("\n")
|
496
|
+
@ohai.stub!(:popen4).with("ip route show scope link").and_yield(nil, @stdin_ip_route_scope_link, @ip_route_scope_link_lines, nil)
|
497
|
+
end
|
498
|
+
|
499
|
+
it "logs a message and skips previously unseen interfaces in 'ip route show scope link'" do
|
500
|
+
Ohai::Log.should_receive(:debug).with("Skipping previously unseen interface from 'ip route show scope link': virbr0").once
|
501
|
+
Ohai::Log.should_receive(:debug).any_number_of_times # Catches the 'Loading plugin network' type messages
|
502
|
+
@ohai._require_plugin("network")
|
503
|
+
@ohai._require_plugin("linux::network")
|
504
|
+
end
|
505
|
+
end
|
449
506
|
end
|
507
|
+
|
450
508
|
end
|
451
509
|
|
metadata
CHANGED
@@ -1,15 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ohai
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 15424029
|
5
4
|
prerelease: 7
|
6
|
-
|
7
|
-
- 0
|
8
|
-
- 6
|
9
|
-
- 12
|
10
|
-
- rc
|
11
|
-
- 4
|
12
|
-
version: 0.6.12.rc.4
|
5
|
+
version: 0.6.12.rc.5
|
13
6
|
platform: ruby
|
14
7
|
authors:
|
15
8
|
- Adam Jacob
|
@@ -17,7 +10,7 @@ autorequire:
|
|
17
10
|
bindir: bin
|
18
11
|
cert_chain: []
|
19
12
|
|
20
|
-
date: 2012-03-
|
13
|
+
date: 2012-03-15 00:00:00 Z
|
21
14
|
dependencies:
|
22
15
|
- !ruby/object:Gem::Dependency
|
23
16
|
name: systemu
|
@@ -27,9 +20,6 @@ dependencies:
|
|
27
20
|
requirements:
|
28
21
|
- - ">="
|
29
22
|
- !ruby/object:Gem::Version
|
30
|
-
hash: 3
|
31
|
-
segments:
|
32
|
-
- 0
|
33
23
|
version: "0"
|
34
24
|
type: :runtime
|
35
25
|
version_requirements: *id001
|
@@ -41,9 +31,6 @@ dependencies:
|
|
41
31
|
requirements:
|
42
32
|
- - ">="
|
43
33
|
- !ruby/object:Gem::Version
|
44
|
-
hash: 3
|
45
|
-
segments:
|
46
|
-
- 0
|
47
34
|
version: "0"
|
48
35
|
type: :runtime
|
49
36
|
version_requirements: *id002
|
@@ -55,9 +42,6 @@ dependencies:
|
|
55
42
|
requirements:
|
56
43
|
- - ">="
|
57
44
|
- !ruby/object:Gem::Version
|
58
|
-
hash: 3
|
59
|
-
segments:
|
60
|
-
- 0
|
61
45
|
version: "0"
|
62
46
|
type: :runtime
|
63
47
|
version_requirements: *id003
|
@@ -69,9 +53,6 @@ dependencies:
|
|
69
53
|
requirements:
|
70
54
|
- - ">="
|
71
55
|
- !ruby/object:Gem::Version
|
72
|
-
hash: 3
|
73
|
-
segments:
|
74
|
-
- 0
|
75
56
|
version: "0"
|
76
57
|
type: :runtime
|
77
58
|
version_requirements: *id004
|
@@ -83,9 +64,6 @@ dependencies:
|
|
83
64
|
requirements:
|
84
65
|
- - ">="
|
85
66
|
- !ruby/object:Gem::Version
|
86
|
-
hash: 3
|
87
|
-
segments:
|
88
|
-
- 0
|
89
67
|
version: "0"
|
90
68
|
type: :runtime
|
91
69
|
version_requirements: *id005
|
@@ -97,9 +75,6 @@ dependencies:
|
|
97
75
|
requirements:
|
98
76
|
- - ">="
|
99
77
|
- !ruby/object:Gem::Version
|
100
|
-
hash: 3
|
101
|
-
segments:
|
102
|
-
- 0
|
103
78
|
version: "0"
|
104
79
|
type: :runtime
|
105
80
|
version_requirements: *id006
|
@@ -111,9 +86,6 @@ dependencies:
|
|
111
86
|
requirements:
|
112
87
|
- - ">="
|
113
88
|
- !ruby/object:Gem::Version
|
114
|
-
hash: 3
|
115
|
-
segments:
|
116
|
-
- 0
|
117
89
|
version: "0"
|
118
90
|
type: :development
|
119
91
|
version_requirements: *id007
|
@@ -125,9 +97,6 @@ dependencies:
|
|
125
97
|
requirements:
|
126
98
|
- - ">="
|
127
99
|
- !ruby/object:Gem::Version
|
128
|
-
hash: 3
|
129
|
-
segments:
|
130
|
-
- 0
|
131
100
|
version: "0"
|
132
101
|
type: :development
|
133
102
|
version_requirements: *id008
|
@@ -139,9 +108,6 @@ dependencies:
|
|
139
108
|
requirements:
|
140
109
|
- - ">="
|
141
110
|
- !ruby/object:Gem::Version
|
142
|
-
hash: 3
|
143
|
-
segments:
|
144
|
-
- 0
|
145
111
|
version: "0"
|
146
112
|
type: :development
|
147
113
|
version_requirements: *id009
|
@@ -153,9 +119,6 @@ dependencies:
|
|
153
119
|
requirements:
|
154
120
|
- - ">="
|
155
121
|
- !ruby/object:Gem::Version
|
156
|
-
hash: 3
|
157
|
-
segments:
|
158
|
-
- 0
|
159
122
|
version: "0"
|
160
123
|
type: :development
|
161
124
|
version_requirements: *id010
|
@@ -386,20 +349,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
386
349
|
requirements:
|
387
350
|
- - ">="
|
388
351
|
- !ruby/object:Gem::Version
|
389
|
-
hash: 3
|
390
|
-
segments:
|
391
|
-
- 0
|
392
352
|
version: "0"
|
393
353
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
394
354
|
none: false
|
395
355
|
requirements:
|
396
356
|
- - ">"
|
397
357
|
- !ruby/object:Gem::Version
|
398
|
-
hash: 25
|
399
|
-
segments:
|
400
|
-
- 1
|
401
|
-
- 3
|
402
|
-
- 1
|
403
358
|
version: 1.3.1
|
404
359
|
requirements: []
|
405
360
|
|