ohai 6.24.2 → 7.0.0.rc.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ohai.rb +1 -1
- data/lib/ohai/application.rb +5 -12
- data/lib/ohai/common/dmi.rb +126 -0
- data/lib/ohai/config.rb +9 -9
- data/lib/ohai/{plugins/darwin/hostname.rb → dsl.rb} +7 -7
- data/lib/ohai/dsl/plugin.rb +186 -0
- data/lib/ohai/dsl/plugin/versionvi.rb +62 -0
- data/lib/ohai/dsl/plugin/versionvii.rb +106 -0
- data/lib/ohai/exception.rb +11 -2
- data/lib/ohai/hints.rb +48 -0
- data/lib/ohai/loader.rb +205 -0
- data/lib/ohai/mixin/command.rb +14 -18
- data/lib/ohai/mixin/constant_helper.rb +53 -0
- data/lib/ohai/mixin/gce_metadata.rb +0 -2
- data/lib/ohai/{plugins/freebsd/uptime.rb → mixin/network_constants.rb} +15 -13
- data/lib/ohai/mixin/os.rb +59 -0
- data/lib/ohai/mixin/seconds_to_human.rb +48 -0
- data/lib/ohai/plugins/aix/cpu.rb +26 -22
- data/lib/ohai/plugins/aix/filesystem.rb +47 -48
- data/lib/ohai/plugins/aix/kernel.rb +11 -7
- data/lib/ohai/plugins/aix/memory.rb +8 -4
- data/lib/ohai/plugins/aix/network.rb +73 -82
- data/lib/ohai/plugins/aix/platform.rb +9 -6
- data/lib/ohai/plugins/aix/uptime.rb +14 -12
- data/lib/ohai/plugins/azure.rb +33 -11
- data/lib/ohai/plugins/c.rb +103 -78
- data/lib/ohai/plugins/chef.rb +20 -8
- data/lib/ohai/plugins/cloud.rb +234 -230
- data/lib/ohai/plugins/command.rb +6 -2
- data/lib/ohai/plugins/darwin/cpu.rb +10 -4
- data/lib/ohai/plugins/darwin/filesystem.rb +32 -32
- data/lib/ohai/plugins/darwin/network.rb +157 -154
- data/lib/ohai/plugins/darwin/platform.rb +18 -16
- data/lib/ohai/plugins/darwin/system_profiler.rb +49 -46
- data/lib/ohai/plugins/dmi.rb +102 -102
- data/lib/ohai/plugins/ec2.rb +30 -28
- data/lib/ohai/plugins/erlang.rb +19 -16
- data/lib/ohai/plugins/eucalyptus.rb +37 -36
- data/lib/ohai/plugins/freebsd/cpu.rb +34 -29
- data/lib/ohai/plugins/freebsd/filesystem.rb +32 -32
- data/lib/ohai/plugins/freebsd/memory.rb +35 -25
- data/lib/ohai/plugins/freebsd/network.rb +94 -89
- data/lib/ohai/plugins/freebsd/platform.rb +10 -4
- data/lib/ohai/plugins/freebsd/virtualization.rb +62 -61
- data/lib/ohai/plugins/gce.rb +30 -36
- data/lib/ohai/plugins/groovy.rb +14 -11
- data/lib/ohai/plugins/hostname.rb +132 -10
- data/lib/ohai/plugins/ip_scopes.rb +31 -16
- data/lib/ohai/plugins/java.rb +45 -21
- data/lib/ohai/plugins/kernel.rb +186 -19
- data/lib/ohai/plugins/keys.rb +6 -2
- data/lib/ohai/plugins/languages.rb +6 -2
- data/lib/ohai/plugins/linode.rb +38 -30
- data/lib/ohai/plugins/linux/block_device.rb +19 -15
- data/lib/ohai/plugins/linux/cpu.rb +42 -38
- data/lib/ohai/plugins/linux/filesystem.rb +70 -130
- data/lib/ohai/plugins/linux/lsb.rb +35 -35
- data/lib/ohai/plugins/linux/memory.rb +65 -61
- data/lib/ohai/plugins/linux/network.rb +343 -362
- data/lib/ohai/plugins/linux/platform.rb +90 -88
- data/lib/ohai/plugins/linux/virtualization.rb +95 -90
- data/lib/ohai/plugins/lua.rb +14 -10
- data/lib/ohai/plugins/mono.rb +17 -13
- data/lib/ohai/plugins/netbsd/cpu.rb +25 -23
- data/lib/ohai/plugins/netbsd/filesystem.rb +32 -32
- data/lib/ohai/plugins/netbsd/memory.rb +59 -59
- data/lib/ohai/plugins/netbsd/network.rb +92 -88
- data/lib/ohai/plugins/netbsd/platform.rb +10 -3
- data/lib/ohai/plugins/netbsd/virtualization.rb +41 -38
- data/lib/ohai/plugins/network.rb +131 -130
- data/lib/ohai/plugins/network_listeners.rb +26 -22
- data/lib/ohai/plugins/nodejs.rb +14 -10
- data/lib/ohai/plugins/ohai.rb +11 -6
- data/lib/ohai/plugins/ohai_time.rb +6 -2
- data/lib/ohai/plugins/openbsd/cpu.rb +20 -15
- data/lib/ohai/plugins/openbsd/filesystem.rb +32 -32
- data/lib/ohai/plugins/openbsd/memory.rb +59 -59
- data/lib/ohai/plugins/openbsd/network.rb +92 -88
- data/lib/ohai/plugins/openbsd/platform.rb +10 -4
- data/lib/ohai/plugins/openbsd/virtualization.rb +41 -39
- data/lib/ohai/plugins/openstack.rb +23 -21
- data/lib/ohai/plugins/os.rb +8 -32
- data/lib/ohai/plugins/passwd.rb +27 -22
- data/lib/ohai/plugins/perl.rb +21 -16
- data/lib/ohai/plugins/php.rb +15 -12
- data/lib/ohai/plugins/platform.rb +9 -9
- data/lib/ohai/plugins/{linux/kernel.rb → ps.rb} +13 -12
- data/lib/ohai/plugins/python.rb +16 -12
- data/lib/ohai/plugins/rackspace.rb +82 -77
- data/lib/ohai/plugins/root_group.rb +13 -9
- data/lib/ohai/plugins/ruby.rb +50 -48
- data/lib/ohai/plugins/sigar/cpu.rb +21 -17
- data/lib/ohai/plugins/sigar/filesystem.rb +26 -23
- data/lib/ohai/plugins/sigar/memory.rb +17 -14
- data/lib/ohai/plugins/sigar/network.rb +133 -67
- data/lib/ohai/plugins/sigar/network_route.rb +33 -28
- data/lib/ohai/plugins/sigar/platform.rb +10 -6
- data/lib/ohai/plugins/solaris2/cpu.rb +41 -33
- data/lib/ohai/plugins/solaris2/dmi.rb +146 -146
- data/lib/ohai/plugins/solaris2/filesystem.rb +74 -77
- data/lib/ohai/plugins/{aix/hostname.rb → solaris2/memory.rb} +7 -4
- data/lib/ohai/plugins/solaris2/network.rb +91 -86
- data/lib/ohai/plugins/solaris2/platform.rb +40 -36
- data/lib/ohai/plugins/solaris2/virtualization.rb +54 -59
- data/lib/ohai/plugins/solaris2/zpools.rb +38 -38
- data/lib/ohai/plugins/ssh_host_key.rb +49 -45
- data/lib/ohai/plugins/uptime.rb +87 -25
- data/lib/ohai/plugins/virtualization.rb +59 -55
- data/lib/ohai/plugins/windows/cpu.rb +44 -40
- data/lib/ohai/plugins/windows/filesystem.rb +28 -22
- data/lib/ohai/plugins/windows/network.rb +88 -79
- data/lib/ohai/plugins/windows/platform.rb +10 -3
- data/lib/ohai/provides_map.rb +184 -0
- data/lib/ohai/runner.rb +109 -0
- data/lib/ohai/system.rb +103 -184
- data/lib/ohai/version.rb +4 -3
- data/spec/data/plugins/___lib64___libc.so.6.output +135 -0
- data/spec/data/plugins/___lib___libc.so.6.output +135 -0
- data/spec/data/plugins/cc.output +135 -0
- data/spec/data/plugins/cl.output +135 -0
- data/spec/data/plugins/devenv.com.output +135 -0
- data/spec/data/plugins/env.output +71 -0
- data/spec/data/plugins/erl.output +144 -0
- data/spec/data/plugins/gcc.output +135 -0
- data/spec/data/plugins/groovy.output +159 -0
- data/spec/data/plugins/java.output +143 -0
- data/spec/data/plugins/lua.output +143 -0
- data/spec/data/plugins/messages.rb +8 -0
- data/spec/data/plugins/node.output +143 -0
- data/spec/data/plugins/perl.output +143 -0
- data/spec/data/plugins/php.output +143 -0
- data/spec/data/plugins/python.output +143 -0
- data/spec/data/plugins/uname.output +71 -0
- data/spec/data/plugins/v6message.rb +2 -0
- data/spec/data/plugins/v7message.rb +7 -0
- data/spec/data/plugins/what.output +135 -0
- data/spec/data/plugins/xlc.output +135 -0
- data/spec/spec_helper.rb +52 -18
- data/spec/support/integration_helper.rb +44 -0
- data/spec/unit/dsl/plugin_spec.rb +298 -0
- data/spec/unit/hints_spec.rb +65 -0
- data/spec/unit/loader_spec.rb +226 -0
- data/spec/unit/mixin/ec2_metadata_spec.rb +9 -9
- data/spec/unit/plugins/aix/cpu_spec.rb +17 -18
- data/spec/unit/plugins/aix/filesystem_spec.rb +20 -18
- data/spec/unit/plugins/aix/hostname_spec.rb +8 -4
- data/spec/unit/plugins/aix/kernel_spec.rb +13 -12
- data/spec/unit/plugins/aix/network_spec.rb +66 -45
- data/spec/unit/plugins/aix/platform_spec.rb +11 -10
- data/spec/unit/plugins/aix/uptime_spec.rb +7 -8
- data/spec/unit/plugins/azure_spec.rb +20 -21
- data/spec/unit/plugins/c_spec.rb +88 -87
- data/spec/unit/plugins/chef_spec.rb +5 -6
- data/spec/unit/plugins/cloud_spec.rb +81 -82
- data/spec/unit/plugins/darwin/cpu_spec.rb +8 -9
- data/spec/unit/plugins/darwin/hostname_spec.rb +23 -11
- data/spec/unit/plugins/darwin/kernel_spec.rb +39 -16
- data/spec/unit/plugins/darwin/network_spec.rb +375 -378
- data/spec/unit/plugins/darwin/platform_spec.rb +23 -50
- data/spec/unit/plugins/darwin/system_profiler_spec.rb +7 -8
- data/spec/unit/plugins/dmi_spec.rb +7 -12
- data/spec/unit/plugins/ec2_spec.rb +70 -59
- data/spec/unit/plugins/erlang_spec.rb +18 -20
- data/spec/unit/plugins/eucalyptus_spec.rb +37 -33
- data/spec/unit/plugins/fail_spec.rb +276 -23
- data/spec/unit/plugins/freebsd/hostname_spec.rb +11 -9
- data/spec/unit/plugins/freebsd/kernel_spec.rb +8 -8
- data/spec/unit/plugins/freebsd/platform_spec.rb +9 -10
- data/spec/unit/plugins/freebsd/virtualization_spec.rb +32 -32
- data/spec/unit/plugins/gce_spec.rb +19 -25
- data/spec/unit/plugins/groovy_spec.rb +10 -16
- data/spec/unit/plugins/hostname_spec.rb +45 -20
- data/spec/unit/plugins/ip_scopes_spec.rb +97 -0
- data/spec/unit/plugins/java_spec.rb +145 -99
- data/spec/unit/plugins/kernel_spec.rb +51 -15
- data/spec/unit/plugins/linode_spec.rb +31 -29
- data/spec/unit/plugins/linux/cpu_spec.rb +42 -43
- data/spec/unit/plugins/linux/filesystem_spec.rb +143 -324
- data/spec/unit/plugins/linux/hostname_spec.rb +16 -23
- data/spec/unit/plugins/linux/kernel_spec.rb +22 -8
- data/spec/unit/plugins/linux/lsb_spec.rb +54 -56
- data/spec/unit/plugins/linux/network_spec.rb +196 -238
- data/spec/unit/plugins/linux/platform_spec.rb +186 -205
- data/spec/unit/plugins/linux/uptime_spec.rb +13 -25
- data/spec/unit/plugins/linux/virtualization_spec.rb +149 -129
- data/spec/unit/plugins/lua_spec.rb +12 -15
- data/spec/unit/plugins/mono_spec.rb +10 -15
- data/spec/unit/plugins/netbsd/hostname_spec.rb +17 -7
- data/spec/unit/plugins/netbsd/kernel_spec.rb +8 -8
- data/spec/unit/plugins/netbsd/platform_spec.rb +8 -10
- data/spec/unit/plugins/network_spec.rb +358 -235
- data/spec/unit/plugins/nodejs_spec.rb +13 -15
- data/spec/unit/plugins/ohai_spec.rb +3 -4
- data/spec/unit/plugins/ohai_time_spec.rb +8 -9
- data/spec/unit/plugins/openbsd/hostname_spec.rb +21 -11
- data/spec/unit/plugins/openbsd/kernel_spec.rb +8 -8
- data/spec/unit/plugins/openbsd/platform_spec.rb +6 -12
- data/spec/unit/plugins/openstack_spec.rb +214 -0
- data/spec/unit/plugins/os_spec.rb +13 -16
- data/spec/unit/plugins/passwd_spec.rb +12 -13
- data/spec/unit/plugins/perl_spec.rb +20 -44
- data/spec/unit/plugins/php_spec.rb +20 -15
- data/spec/unit/plugins/platform_spec.rb +24 -29
- data/spec/unit/plugins/python_spec.rb +13 -17
- data/spec/unit/plugins/rackspace_spec.rb +90 -57
- data/spec/unit/plugins/root_group_spec.rb +17 -19
- data/spec/unit/plugins/ruby_spec.rb +15 -16
- data/spec/unit/plugins/sigar/network_route_spec.rb +12 -13
- data/spec/unit/plugins/solaris2/cpu_spec.rb +82 -0
- data/spec/unit/plugins/solaris2/hostname_spec.rb +12 -13
- data/spec/unit/plugins/solaris2/kernel_spec.rb +11 -15
- data/{lib/ohai/plugins/openbsd/uptime.rb → spec/unit/plugins/solaris2/memory_spec.rb} +10 -12
- data/spec/unit/plugins/solaris2/network_spec.rb +44 -20
- data/spec/unit/plugins/solaris2/platform_spec.rb +13 -22
- data/spec/unit/plugins/solaris2/virtualization_spec.rb +37 -45
- data/spec/unit/plugins/ssh_host_keys_spec.rb +11 -15
- data/spec/unit/provides_map_spec.rb +208 -0
- data/spec/unit/runner_spec.rb +488 -0
- data/spec/unit/system_spec.rb +639 -104
- metadata +151 -87
- checksums.yaml +0 -7
- data/lib/ohai/mixin/from_file.rb +0 -36
- data/lib/ohai/plugins/aix/ps.rb +0 -23
- data/lib/ohai/plugins/darwin/kernel.rb +0 -37
- data/lib/ohai/plugins/darwin/ps.rb +0 -23
- data/lib/ohai/plugins/darwin/uptime.rb +0 -32
- data/lib/ohai/plugins/dmi_common.rb +0 -121
- data/lib/ohai/plugins/freebsd/hostname.rb +0 -22
- data/lib/ohai/plugins/freebsd/kernel.rb +0 -37
- data/lib/ohai/plugins/freebsd/ps.rb +0 -24
- data/lib/ohai/plugins/hpux/cpu.rb +0 -19
- data/lib/ohai/plugins/hpux/filesystem.rb +0 -19
- data/lib/ohai/plugins/hpux/hostname.rb +0 -19
- data/lib/ohai/plugins/hpux/memory.rb +0 -19
- data/lib/ohai/plugins/hpux/network.rb +0 -19
- data/lib/ohai/plugins/hpux/platform.rb +0 -19
- data/lib/ohai/plugins/hpux/ps.rb +0 -23
- data/lib/ohai/plugins/hpux/uptime.rb +0 -19
- data/lib/ohai/plugins/linux/hostname.rb +0 -40
- data/lib/ohai/plugins/linux/ps.rb +0 -23
- data/lib/ohai/plugins/linux/uptime.rb +0 -28
- data/lib/ohai/plugins/netbsd/hostname.rb +0 -22
- data/lib/ohai/plugins/netbsd/kernel.rb +0 -35
- data/lib/ohai/plugins/netbsd/ps.rb +0 -24
- data/lib/ohai/plugins/netbsd/uptime.rb +0 -31
- data/lib/ohai/plugins/openbsd/hostname.rb +0 -22
- data/lib/ohai/plugins/openbsd/kernel.rb +0 -35
- data/lib/ohai/plugins/openbsd/ps.rb +0 -24
- data/lib/ohai/plugins/sigar/hostname.rb +0 -28
- data/lib/ohai/plugins/sigar/uptime.rb +0 -27
- data/lib/ohai/plugins/solaris2/hostname.rb +0 -34
- data/lib/ohai/plugins/solaris2/kernel.rb +0 -40
- data/lib/ohai/plugins/solaris2/ps.rb +0 -23
- data/lib/ohai/plugins/solaris2/uptime.rb +0 -36
- data/lib/ohai/plugins/windows/hostname.rb +0 -33
- data/lib/ohai/plugins/windows/kernel.rb +0 -58
- data/lib/ohai/plugins/windows/kernel_devices.rb +0 -39
- data/lib/ohai/plugins/windows/uptime.rb +0 -23
- data/spec/unit/mixin/from_file_spec.rb +0 -53
@@ -16,7 +16,14 @@
|
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
18
|
|
19
|
-
|
19
|
+
Ohai.plugin(:Platform) do
|
20
|
+
provides "platform", "platform_version", "platform_family"
|
20
21
|
|
21
|
-
|
22
|
-
|
22
|
+
collect_data(:netbsd) do
|
23
|
+
so = shell_out("uname -s")
|
24
|
+
platform so.stdout.split($/)[0].downcase
|
25
|
+
so = shell_out("uname -r")
|
26
|
+
platform_version so.stdout.split($/)[0]
|
27
|
+
platform_family "netbsd"
|
28
|
+
end
|
29
|
+
end
|
@@ -16,48 +16,51 @@
|
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
18
|
|
19
|
-
|
19
|
+
Ohai.plugin(:Virtualization) do
|
20
|
+
provides "virtualization"
|
20
21
|
|
21
|
-
|
22
|
+
collect_data(:netbsd) do
|
23
|
+
virtualization Mash.new
|
22
24
|
|
23
|
-
# KVM Host support for FreeBSD is in development
|
24
|
-
# http://feanor.sssup.it/~fabio/freebsd/lkvm/
|
25
|
+
# KVM Host support for FreeBSD is in development
|
26
|
+
# http://feanor.sssup.it/~fabio/freebsd/lkvm/
|
25
27
|
|
26
|
-
# Detect KVM/QEMU from cpu, report as KVM
|
27
|
-
# hw.model: QEMU Virtual CPU version 0.9.1
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
# Detect KVM/QEMU from cpu, report as KVM
|
29
|
+
# hw.model: QEMU Virtual CPU version 0.9.1
|
30
|
+
so = shell_out("sysctl -n hw.model")
|
31
|
+
if so.stdout.split($/)[0] =~ /QEMU Virtual CPU/
|
32
|
+
virtualization[:system] = "kvm"
|
33
|
+
virtualization[:role] = "guest"
|
34
|
+
end
|
32
35
|
|
33
|
-
# http://www.dmo.ca/blog/detecting-virtualization-on-linux
|
34
|
-
if File.exists?("/usr/pkg/sbin/dmidecode")
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
36
|
+
# http://www.dmo.ca/blog/detecting-virtualization-on-linux
|
37
|
+
if File.exists?("/usr/pkg/sbin/dmidecode")
|
38
|
+
so = shell_out("dmidecode")
|
39
|
+
found_virt_manufacturer = nil
|
40
|
+
found_virt_product = nil
|
41
|
+
so.stdout.lines do |line|
|
42
|
+
case line
|
43
|
+
when /Manufacturer: Microsoft/
|
44
|
+
found_virt_manufacturer = "microsoft"
|
45
|
+
when /Product Name: Virtual Machine/
|
46
|
+
found_virt_product = "microsoft"
|
47
|
+
when /Version: 5.0/
|
48
|
+
if found_virt_manufacturer == "microsoft" && found_virt_product == "microsoft"
|
49
|
+
virtualization[:system] = "virtualpc"
|
50
|
+
virtualization[:role] = "guest"
|
51
|
+
end
|
52
|
+
when /Version: VS2005R2/
|
53
|
+
if found_virt_manufacturer == "microsoft" && found_virt_product == "microsoft"
|
54
|
+
virtualization[:system] = "virtualserver"
|
55
|
+
virtualization[:role] = "guest"
|
56
|
+
end
|
57
|
+
when /Manufacturer: VMware/
|
58
|
+
found_virt_manufacturer = "vmware"
|
59
|
+
when /Product Name: VMware Virtual Platform/
|
60
|
+
if found_virt_manufacturer == "vmware"
|
61
|
+
virtualization[:system] = "vmware"
|
62
|
+
virtualization[:role] = "guest"
|
63
|
+
end
|
61
64
|
end
|
62
65
|
end
|
63
66
|
end
|
data/lib/ohai/plugins/network.rb
CHANGED
@@ -17,159 +17,160 @@
|
|
17
17
|
#
|
18
18
|
|
19
19
|
require 'ipaddress'
|
20
|
+
require 'ohai/mixin/network_constants'
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
next if addr_v.nil? or not addr_v.has_key? "family" or addr_v['family'] != family
|
47
|
-
ipaddresses << {
|
48
|
-
:ipaddress => addr_v["prefixlen"] ? IPAddress("#{addr}/#{addr_v["prefixlen"]}") : IPAddress("#{addr}/#{addr_v["netmask"]}"),
|
49
|
-
:scope => addr_v["scope"].nil? ? nil : addr_v["scope"].downcase,
|
50
|
-
:iface => iface
|
51
|
-
}
|
22
|
+
Ohai.plugin(:NetworkAddresses) do
|
23
|
+
include Ohai::Mixin::NetworkConstants
|
24
|
+
|
25
|
+
provides "ipaddress", "ip6address", "macaddress"
|
26
|
+
|
27
|
+
depends "network/interfaces"
|
28
|
+
|
29
|
+
def sorted_ips(family = "inet")
|
30
|
+
raise "bad family #{family}" unless [ "inet", "inet6" ].include? family
|
31
|
+
|
32
|
+
# going to use that later to sort by scope
|
33
|
+
scope_prio = [ "global", "site", "link", "host", "node", nil ]
|
34
|
+
|
35
|
+
ipaddresses = []
|
36
|
+
# ipaddresses going to hold #{family} ipaddresses and their scope
|
37
|
+
Mash[network['interfaces']].each do |iface, iface_v|
|
38
|
+
next if iface_v.nil? or not iface_v.has_key? 'addresses'
|
39
|
+
iface_v['addresses'].each do |addr, addr_v|
|
40
|
+
next if addr_v.nil? or not addr_v.has_key? "family" or addr_v['family'] != family
|
41
|
+
ipaddresses << {
|
42
|
+
:ipaddress => addr_v["prefixlen"] ? IPAddress("#{addr}/#{addr_v["prefixlen"]}") : IPAddress("#{addr}/#{addr_v["netmask"]}"),
|
43
|
+
:scope => addr_v["scope"].nil? ? nil : addr_v["scope"].downcase,
|
44
|
+
:iface => iface
|
45
|
+
}
|
46
|
+
end
|
52
47
|
end
|
53
|
-
end
|
54
48
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
49
|
+
# sort ip addresses by scope, by prefixlen and then by ip address
|
50
|
+
# 128 - prefixlen: longest prefixes first
|
51
|
+
ipaddresses.sort_by do |v|
|
52
|
+
[ ( scope_prio.index(v[:scope]) or 999999 ),
|
53
|
+
128 - v[:ipaddress].prefix.to_i,
|
54
|
+
( family == "inet" ? v[:ipaddress].to_u32 : v[:ipaddress].to_u128 )
|
55
|
+
]
|
56
|
+
end
|
62
57
|
end
|
63
|
-
end
|
64
58
|
|
65
|
-
def find_ip(family = "inet")
|
66
|
-
|
59
|
+
def find_ip(family = "inet")
|
60
|
+
ips=sorted_ips(family)
|
67
61
|
|
68
|
-
|
69
|
-
|
62
|
+
# return if there isn't any #{family} address !
|
63
|
+
return [ nil, nil ] if ips.empty?
|
70
64
|
|
71
|
-
|
72
|
-
|
73
|
-
|
65
|
+
# shortcuts to access default #{family} interface and gateway
|
66
|
+
int_attr = Ohai::Mixin::NetworkConstants::FAMILIES[family] +"_interface"
|
67
|
+
gw_attr = Ohai::Mixin::NetworkConstants::FAMILIES[family] + "_gateway"
|
74
68
|
|
75
|
-
|
76
|
-
|
77
|
-
|
69
|
+
# If we have a default interface that has addresses,
|
70
|
+
# populate the short-cut attributes ipaddress, ip6address and macaddress
|
71
|
+
if network[int_attr]
|
78
72
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
r = gw_if_ips.first
|
92
|
-
else
|
93
|
-
# checking network masks
|
94
|
-
r = gw_if_ips.select do |v|
|
95
|
-
network_contains_address(network[gw_attr], v[:ipaddress], v[:iface])
|
96
|
-
end.first
|
97
|
-
if r.nil?
|
73
|
+
# working with the address(es) of the default network interface
|
74
|
+
gw_if_ips = ips.select do |v|
|
75
|
+
v[:iface] == network[int_attr]
|
76
|
+
end
|
77
|
+
if gw_if_ips.empty?
|
78
|
+
Ohai::Log.warn("[#{family}] no ip address on #{network[int_attr]}")
|
79
|
+
elsif network[gw_attr] and
|
80
|
+
network["interfaces"][network[int_attr]] and
|
81
|
+
network["interfaces"][network[int_attr]]["addresses"]
|
82
|
+
if [ "0.0.0.0", "::" ].include? network[gw_attr]
|
83
|
+
# link level default route
|
84
|
+
Ohai::Log.debug("link level default #{family} route, picking ip from #{network[gw_attr]}")
|
98
85
|
r = gw_if_ips.first
|
99
|
-
Ohai::Log.warn("[#{family}] no ipaddress/mask on #{network[int_attr]} matching the gateway #{network[gw_attr]}, picking one anyway")
|
100
86
|
else
|
101
|
-
|
87
|
+
# checking network masks
|
88
|
+
r = gw_if_ips.select do |v|
|
89
|
+
network_contains_address(network[gw_attr], v[:ipaddress], v[:iface])
|
90
|
+
end.first
|
91
|
+
if r.nil?
|
92
|
+
r = gw_if_ips.first
|
93
|
+
Ohai::Log.warn("[#{family}] no ipaddress/mask on #{network[int_attr]} matching the gateway #{network[gw_attr]}, picking one anyway")
|
94
|
+
else
|
95
|
+
Ohai::Log.debug("[#{family}] Using default interface #{network[int_attr]} and default gateway #{network[gw_attr]} to set the default ip to #{r[:ipaddress]}")
|
96
|
+
end
|
102
97
|
end
|
98
|
+
else
|
99
|
+
# return the first ip address on network[int_attr]
|
100
|
+
r = gw_if_ips.first
|
103
101
|
end
|
104
102
|
else
|
105
|
-
|
106
|
-
|
103
|
+
r = ips.first
|
104
|
+
Ohai::Log.debug("[#{family}] no default interface, picking the first ipaddress")
|
107
105
|
end
|
108
|
-
else
|
109
|
-
r = ips.first
|
110
|
-
Ohai::Log.debug("[#{family}] no default interface, picking the first ipaddress")
|
111
|
-
end
|
112
106
|
|
113
|
-
|
107
|
+
return [ nil, nil ] if r.nil? or r.empty?
|
114
108
|
|
115
|
-
|
116
|
-
end
|
117
|
-
|
118
|
-
def find_mac_from_iface(iface)
|
119
|
-
r = network["interfaces"][iface]["addresses"].select{|k,v| v["family"]=="lladdr"}
|
120
|
-
r.nil? or r.first.nil? ? nil : r.first.first
|
121
|
-
end
|
109
|
+
[ r[:ipaddress].to_s, r[:iface] ]
|
110
|
+
end
|
122
111
|
|
123
|
-
def
|
124
|
-
|
125
|
-
|
126
|
-
# iface: String
|
127
|
-
if peer = network["interfaces"][iface]["addresses"][ipaddress.to_s][:peer]
|
128
|
-
IPAddress(peer) == IPAddress(address_to_match)
|
129
|
-
else
|
130
|
-
ipaddress.include? IPAddress(address_to_match)
|
112
|
+
def find_mac_from_iface(iface)
|
113
|
+
r = network["interfaces"][iface]["addresses"].select{|k,v| v["family"]=="lladdr"}
|
114
|
+
r.nil? or r.first.nil? ? nil : r.first.first
|
131
115
|
end
|
132
|
-
end
|
133
116
|
|
134
|
-
|
135
|
-
#
|
136
|
-
#
|
137
|
-
#
|
138
|
-
|
139
|
-
|
140
|
-
results = {}
|
141
|
-
|
142
|
-
# inet family is treated before inet6
|
143
|
-
FAMILIES.keys.sort.each do |family|
|
144
|
-
r = {}
|
145
|
-
( r["ip"], r["iface"] ) = find_ip(family)
|
146
|
-
r["mac"] = find_mac_from_iface(r["iface"]) unless r["iface"].nil?
|
147
|
-
# don't overwrite attributes if they've already been set by the "#{os}::network" plugin
|
148
|
-
if family == "inet" and ipaddress.nil?
|
149
|
-
if r["ip"].nil?
|
150
|
-
Ohai::Log.warn("unable to detect ipaddress")
|
151
|
-
# i don't issue this warning if r["ip"] exists and r["mac"].nil?
|
152
|
-
# as it could be a valid setup with a NOARP default_interface
|
153
|
-
Ohai::Log.warn("unable to detect macaddress")
|
117
|
+
def network_contains_address(address_to_match, ipaddress, iface)
|
118
|
+
# address_to_match: String
|
119
|
+
# ipaddress: IPAddress
|
120
|
+
# iface: String
|
121
|
+
if peer = network["interfaces"][iface]["addresses"][ipaddress.to_s][:peer]
|
122
|
+
IPAddress(peer) == IPAddress(address_to_match)
|
154
123
|
else
|
155
|
-
ipaddress
|
156
|
-
macaddress r["mac"]
|
124
|
+
ipaddress.include? IPAddress(address_to_match)
|
157
125
|
end
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
126
|
+
end
|
127
|
+
|
128
|
+
# ipaddress, ip6address and macaddress can be set by the #{os}::network plugin
|
129
|
+
# atm it is expected macaddress is set at the same time than ipaddress
|
130
|
+
# if ipaddress is set and macaddress is nil, that means the interface
|
131
|
+
# ipaddress is bound to has the NOARP flag
|
132
|
+
|
133
|
+
collect_data do
|
134
|
+
results = {}
|
135
|
+
|
136
|
+
network Mash.new unless network
|
137
|
+
network[:interfaces] = Mash.new unless network[:interfaces]
|
138
|
+
counters Mash.new unless counters
|
139
|
+
counters[:network] = Mash.new unless counters[:network]
|
140
|
+
|
141
|
+
# inet family is treated before inet6
|
142
|
+
Ohai::Mixin::NetworkConstants::FAMILIES.keys.sort.each do |family|
|
143
|
+
r = {}
|
144
|
+
( r["ip"], r["iface"] ) = find_ip(family)
|
145
|
+
r["mac"] = find_mac_from_iface(r["iface"]) unless r["iface"].nil?
|
146
|
+
# don't overwrite attributes if they've already been set by the "#{os}::network" plugin
|
147
|
+
if family == "inet" and ipaddress.nil?
|
148
|
+
if r["ip"].nil?
|
149
|
+
Ohai::Log.warn("unable to detect ipaddress")
|
150
|
+
# i don't issue this warning if r["ip"] exists and r["mac"].nil?
|
151
|
+
# as it could be a valid setup with a NOARP default_interface
|
152
|
+
Ohai::Log.warn("unable to detect macaddress")
|
153
|
+
else
|
154
|
+
ipaddress r["ip"]
|
155
|
+
macaddress r["mac"]
|
156
|
+
end
|
157
|
+
elsif family == "inet6" and ip6address.nil?
|
158
|
+
if r["ip"].nil?
|
159
|
+
Ohai::Log.warn("unable to detect ip6address")
|
160
|
+
else
|
161
|
+
ip6address r["ip"]
|
162
|
+
if r["mac"] and macaddress.nil? and ipaddress.nil?
|
163
|
+
Ohai::Log.debug("macaddress set to #{r["mac"]} from the ipv6 setup")
|
164
|
+
macaddress r["mac"]
|
165
|
+
end
|
166
|
+
end
|
166
167
|
end
|
168
|
+
results[family] = r
|
167
169
|
end
|
168
|
-
end
|
169
|
-
results[family] = r
|
170
|
-
end
|
171
170
|
|
172
|
-
if results["inet"]["iface"] and results["inet6"]["iface"] and
|
173
|
-
|
174
|
-
|
171
|
+
if results["inet"]["iface"] and results["inet6"]["iface"] and
|
172
|
+
results["inet"]["iface"] != results["inet6"]["iface"]
|
173
|
+
Ohai::Log.debug("ipaddress and ip6address are set from different interfaces (#{results["inet"]["iface"]} & #{results["inet6"]["iface"]}), macaddress has been set using the ipaddress interface")
|
174
|
+
end
|
175
|
+
end
|
175
176
|
end
|
@@ -16,32 +16,36 @@
|
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
18
|
|
19
|
-
|
19
|
+
Ohai.plugin(:NetworkListeners) do
|
20
|
+
provides "network/listeners"
|
20
21
|
|
21
|
-
|
22
|
+
depends "network", "counters/network"
|
22
23
|
|
23
|
-
|
24
|
+
collect_data do
|
25
|
+
require 'sigar'
|
26
|
+
flags = Sigar::NETCONN_TCP|Sigar::NETCONN_SERVER
|
24
27
|
|
25
|
-
|
28
|
+
network Mash.new unless network
|
29
|
+
listeners = Mash.new
|
26
30
|
|
27
|
-
|
31
|
+
sigar = Sigar.new
|
32
|
+
sigar.net_connection_list(flags).each do |conn|
|
33
|
+
port = conn.local_port
|
34
|
+
addr = conn.local_address.to_s
|
35
|
+
if addr == "0.0.0.0" || addr == "::"
|
36
|
+
addr = "*"
|
37
|
+
end
|
38
|
+
listeners[port] = Mash.new
|
39
|
+
listeners[port][:address] = addr
|
40
|
+
begin
|
41
|
+
pid = sigar.proc_port(conn.type, port)
|
42
|
+
listeners[port][:pid] = pid
|
43
|
+
listeners[port][:name] = sigar.proc_state(pid).name
|
44
|
+
rescue
|
45
|
+
end
|
46
|
+
end
|
28
47
|
|
29
|
-
|
30
|
-
|
31
|
-
port = conn.local_port
|
32
|
-
addr = conn.local_address.to_s
|
33
|
-
if addr == "0.0.0.0" || addr == "::"
|
34
|
-
addr = "*"
|
35
|
-
end
|
36
|
-
listeners[port] = Mash.new
|
37
|
-
listeners[port][:address] = addr
|
38
|
-
begin
|
39
|
-
pid = sigar.proc_port(conn.type, port)
|
40
|
-
listeners[port][:pid] = pid
|
41
|
-
listeners[port][:name] = sigar.proc_state(pid).name
|
42
|
-
rescue
|
48
|
+
network[:listeners] = Mash.new
|
49
|
+
network[:listeners][:tcp] = listeners
|
43
50
|
end
|
44
51
|
end
|
45
|
-
|
46
|
-
network[:listeners] = Mash.new
|
47
|
-
network[:listeners][:tcp] = listeners
|