ohai 18.0.14 → 18.0.26
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +28 -28
- data/LICENSE +201 -201
- data/bin/ohai +25 -25
- data/lib/ohai/application.rb +189 -189
- data/lib/ohai/common/dmi.rb +167 -163
- data/lib/ohai/config.rb +51 -51
- data/lib/ohai/dsl/plugin/versionvii.rb +203 -203
- data/lib/ohai/dsl/plugin.rb +232 -232
- data/lib/ohai/dsl.rb +22 -22
- data/lib/ohai/exception.rb +36 -36
- data/lib/ohai/hints.rb +68 -68
- data/lib/ohai/loader.rb +178 -178
- data/lib/ohai/log.rb +34 -34
- data/lib/ohai/mash.rb +22 -22
- data/lib/ohai/mixin/alibaba_metadata.rb +86 -86
- data/lib/ohai/mixin/azure_metadata.rb +111 -111
- data/lib/ohai/mixin/chef_utils_wiring.rb +52 -52
- data/lib/ohai/mixin/command.rb +4 -4
- data/lib/ohai/mixin/constant_helper.rb +55 -55
- data/lib/ohai/mixin/dmi_decode.rb +54 -54
- data/lib/ohai/mixin/do_metadata.rb +48 -48
- data/lib/ohai/mixin/ec2_metadata.rb +256 -256
- data/lib/ohai/mixin/gce_metadata.rb +83 -83
- data/lib/ohai/mixin/http_helper.rb +64 -64
- data/lib/ohai/mixin/network_helper.rb +65 -63
- data/lib/ohai/mixin/os.rb +128 -128
- data/lib/ohai/mixin/scaleway_metadata.rb +51 -51
- data/lib/ohai/mixin/seconds_to_human.rb +52 -52
- data/lib/ohai/mixin/shell_out.rb +51 -51
- data/lib/ohai/mixin/softlayer_metadata.rb +74 -74
- data/lib/ohai/mixin/string.rb +31 -31
- data/lib/ohai/mixin/train_helpers.rb +36 -36
- data/lib/ohai/mixin/which.rb +39 -39
- data/lib/ohai/plugin_config.rb +47 -47
- data/lib/ohai/plugins/aix/kernel.rb +50 -50
- data/lib/ohai/plugins/aix/memory.rb +37 -37
- data/lib/ohai/plugins/aix/network.rb +142 -142
- data/lib/ohai/plugins/aix/platform.rb +30 -30
- data/lib/ohai/plugins/aix/uptime.rb +54 -54
- data/lib/ohai/plugins/aix/virtualization.rb +154 -154
- data/lib/ohai/plugins/alibaba.rb +72 -72
- data/lib/ohai/plugins/azure.rb +154 -154
- data/lib/ohai/plugins/bsd/virtualization.rb +121 -121
- data/lib/ohai/plugins/c.rb +178 -178
- data/lib/ohai/plugins/chef.rb +50 -50
- data/lib/ohai/plugins/cloud.rb +357 -357
- data/lib/ohai/plugins/command.rb +26 -26
- data/lib/ohai/plugins/cpu.rb +635 -626
- data/lib/ohai/plugins/darwin/hardware.rb +99 -99
- data/lib/ohai/plugins/darwin/memory.rb +62 -62
- data/lib/ohai/plugins/darwin/network.rb +207 -207
- data/lib/ohai/plugins/darwin/platform.rb +38 -38
- data/lib/ohai/plugins/darwin/virtualization.rb +93 -93
- data/lib/ohai/plugins/digital_ocean.rb +67 -67
- data/lib/ohai/plugins/dmi.rb +134 -134
- data/lib/ohai/plugins/docker.rb +58 -58
- data/lib/ohai/plugins/dragonflybsd/memory.rb +60 -60
- data/lib/ohai/plugins/dragonflybsd/network.rb +128 -128
- data/lib/ohai/plugins/dragonflybsd/platform.rb +28 -28
- data/lib/ohai/plugins/ec2.rb +148 -155
- data/lib/ohai/plugins/elixir.rb +36 -36
- data/lib/ohai/plugins/erlang.rb +60 -60
- data/lib/ohai/plugins/eucalyptus.rb +86 -86
- data/lib/ohai/plugins/filesystem.rb +751 -751
- data/lib/ohai/plugins/fips.rb +36 -35
- data/lib/ohai/plugins/freebsd/memory.rb +60 -60
- data/lib/ohai/plugins/freebsd/network.rb +128 -128
- data/lib/ohai/plugins/freebsd/platform.rb +28 -28
- data/lib/ohai/plugins/gce.rb +89 -89
- data/lib/ohai/plugins/go.rb +34 -34
- data/lib/ohai/plugins/groovy.rb +38 -38
- data/lib/ohai/plugins/grub2.rb +40 -40
- data/lib/ohai/plugins/habitat.rb +73 -73
- data/lib/ohai/plugins/haskell.rb +96 -96
- data/lib/ohai/plugins/hostname.rb +133 -133
- data/lib/ohai/plugins/init_package.rb +26 -26
- data/lib/ohai/plugins/java.rb +78 -78
- data/lib/ohai/plugins/kernel.rb +292 -292
- data/lib/ohai/plugins/keys.rb +27 -27
- data/lib/ohai/plugins/languages.rb +26 -26
- data/lib/ohai/plugins/libvirt.rb +114 -114
- data/lib/ohai/plugins/linode.rb +73 -73
- data/lib/ohai/plugins/linux/block_device.rb +48 -48
- data/lib/ohai/plugins/linux/hostnamectl.rb +34 -34
- data/lib/ohai/plugins/linux/interrupts.rb +84 -84
- data/lib/ohai/plugins/linux/ipc.rb +52 -52
- data/lib/ohai/plugins/linux/livepatch.rb +38 -38
- data/lib/ohai/plugins/linux/lsb.rb +46 -46
- data/lib/ohai/plugins/linux/lspci.rb +76 -76
- data/lib/ohai/plugins/linux/machineid.rb +36 -36
- data/lib/ohai/plugins/linux/mdadm.rb +120 -120
- data/lib/ohai/plugins/linux/memory.rb +106 -106
- data/lib/ohai/plugins/linux/network.rb +879 -879
- data/lib/ohai/plugins/linux/os_release.rb +38 -38
- data/lib/ohai/plugins/linux/platform.rb +314 -313
- data/lib/ohai/plugins/linux/selinux.rb +69 -69
- data/lib/ohai/plugins/linux/sessions.rb +54 -54
- data/lib/ohai/plugins/linux/sysctl.rb +39 -39
- data/lib/ohai/plugins/linux/systemd_paths.rb +36 -36
- data/lib/ohai/plugins/linux/tc.rb +61 -61
- data/lib/ohai/plugins/linux/virtualization.rb +300 -300
- data/lib/ohai/plugins/lua.rb +39 -39
- data/lib/ohai/plugins/mono.rb +50 -50
- data/lib/ohai/plugins/netbsd/memory.rb +99 -99
- data/lib/ohai/plugins/netbsd/network.rb +122 -122
- data/lib/ohai/plugins/netbsd/platform.rb +28 -28
- data/lib/ohai/plugins/network.rb +186 -186
- data/lib/ohai/plugins/nodejs.rb +40 -40
- data/lib/ohai/plugins/ohai.rb +29 -29
- data/lib/ohai/plugins/ohai_time.rb +26 -26
- data/lib/ohai/plugins/openbsd/memory.rb +99 -99
- data/lib/ohai/plugins/openbsd/network.rb +122 -122
- data/lib/ohai/plugins/openbsd/platform.rb +28 -28
- data/lib/ohai/plugins/openstack.rb +84 -84
- data/lib/ohai/plugins/os.rb +55 -55
- data/lib/ohai/plugins/packages.rb +234 -234
- data/lib/ohai/plugins/passwd.rb +104 -104
- data/lib/ohai/plugins/perl.rb +45 -45
- data/lib/ohai/plugins/php.rb +52 -52
- data/lib/ohai/plugins/platform.rb +29 -29
- data/lib/ohai/plugins/powershell.rb +82 -82
- data/lib/ohai/plugins/ps.rb +35 -35
- data/lib/ohai/plugins/python.rb +43 -43
- data/lib/ohai/plugins/rackspace.rb +177 -177
- data/lib/ohai/plugins/root_group.rb +41 -41
- data/lib/ohai/plugins/rpm.rb +121 -119
- data/lib/ohai/plugins/ruby.rb +66 -66
- data/lib/ohai/plugins/rust.rb +34 -34
- data/lib/ohai/plugins/scala.rb +38 -38
- data/lib/ohai/plugins/scaleway.rb +58 -58
- data/lib/ohai/plugins/scsi.rb +52 -52
- data/lib/ohai/plugins/shard.rb +142 -142
- data/lib/ohai/plugins/shells.rb +32 -32
- data/lib/ohai/plugins/softlayer.rb +48 -48
- data/lib/ohai/plugins/solaris2/dmi.rb +191 -191
- data/lib/ohai/plugins/solaris2/memory.rb +32 -32
- data/lib/ohai/plugins/solaris2/network.rb +192 -192
- data/lib/ohai/plugins/solaris2/platform.rb +58 -58
- data/lib/ohai/plugins/solaris2/virtualization.rb +90 -90
- data/lib/ohai/plugins/ssh_host_key.rb +84 -84
- data/lib/ohai/plugins/sysconf.rb +46 -46
- data/lib/ohai/plugins/timezone.rb +25 -25
- data/lib/ohai/plugins/train.rb +35 -35
- data/lib/ohai/plugins/uptime.rb +95 -95
- data/lib/ohai/plugins/virtualbox.rb +197 -197
- data/lib/ohai/plugins/vmware.rb +94 -94
- data/lib/ohai/plugins/windows/dmi.rb +95 -95
- data/lib/ohai/plugins/windows/drivers.rb +52 -52
- data/lib/ohai/plugins/windows/memory.rb +39 -39
- data/lib/ohai/plugins/windows/network.rb +222 -222
- data/lib/ohai/plugins/windows/platform.rb +34 -34
- data/lib/ohai/plugins/windows/system_enclosure.rb +29 -29
- data/lib/ohai/plugins/windows/virtualization.rb +45 -45
- data/lib/ohai/plugins/zpools.rb +94 -94
- data/lib/ohai/provides_map.rb +208 -208
- data/lib/ohai/runner.rb +128 -128
- data/lib/ohai/system.rb +258 -258
- data/lib/ohai/train_transport.rb +29 -29
- data/lib/ohai/util/file_helper.rb +6 -6
- data/lib/ohai/util/ip_helper.rb +56 -56
- data/lib/ohai/util/win32.rb +47 -47
- data/lib/ohai/version.rb +23 -23
- data/lib/ohai.rb +23 -23
- data/ohai.gemspec +35 -35
- metadata +3 -3
data/lib/ohai/plugins/azure.rb
CHANGED
@@ -1,154 +1,154 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
# Copyright:: Copyright (c) Chef Software Inc.
|
3
|
-
# License:: Apache License, Version 2.0
|
4
|
-
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
# you may not use this file except in compliance with the License.
|
7
|
-
# You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
# See the License for the specific language governing permissions and
|
15
|
-
# limitations under the License.
|
16
|
-
#
|
17
|
-
|
18
|
-
Ohai.plugin(:Azure) do
|
19
|
-
require_relative "../mixin/azure_metadata"
|
20
|
-
require_relative "../mixin/http_helper"
|
21
|
-
|
22
|
-
include Ohai::Mixin::AzureMetadata
|
23
|
-
include Ohai::Mixin::HttpHelper
|
24
|
-
|
25
|
-
provides "azure"
|
26
|
-
|
27
|
-
collect_data do
|
28
|
-
# Before we had the metadata endpoint we relied exclusively on
|
29
|
-
# the knife-azure plugin populating data to the hint file.
|
30
|
-
# Please see the lib/chef/knife/azure_server_create.rb file in that
|
31
|
-
# project for details
|
32
|
-
azure_metadata_from_hints = hint?("azure")
|
33
|
-
if azure_metadata_from_hints
|
34
|
-
logger.trace("Plugin Azure: Azure hint is present. Parsing any hint data.")
|
35
|
-
azure Mash.new
|
36
|
-
azure_metadata_from_hints.each { |k, v| azure[k] = v }
|
37
|
-
azure["metadata"] = parse_metadata
|
38
|
-
elsif has_waagent? || has_dhcp_option_245? || has_reddog_dhcp_domain?
|
39
|
-
logger.trace("Plugin Azure: No hints present, but system appears to be on Azure.")
|
40
|
-
azure Mash.new
|
41
|
-
azure["metadata"] = parse_metadata
|
42
|
-
else
|
43
|
-
logger.trace("Plugin Azure: No hints present and doesn't appear to be on Azure.")
|
44
|
-
false
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
# check for either the waagent or the unknown-245 DHCP option that Azure uses
|
49
|
-
# http://blog.mszcool.com/index.php/2015/04/detecting-if-a-virtual-machine-runs-in-microsoft-azure-linux-windows-to-protect-your-software-when-distributed-via-the-azure-marketplace/
|
50
|
-
def has_waagent?
|
51
|
-
if file_exist?("/usr/sbin/waagent") || dir_exist?("C:\\WindowsAzure")
|
52
|
-
logger.trace("Plugin Azure: Found waagent used by Azure.")
|
53
|
-
true
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def has_dhcp_option_245?
|
58
|
-
has_245 = false
|
59
|
-
if file_exist?("/var/lib/dhcp/dhclient.eth0.leases")
|
60
|
-
file_open("/var/lib/dhcp/dhclient.eth0.leases").each do |line|
|
61
|
-
if /unknown-245/.match?(line)
|
62
|
-
logger.trace("Plugin Azure: Found unknown-245 DHCP option used by Azure.")
|
63
|
-
has_245 = true
|
64
|
-
break
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
has_245
|
69
|
-
end
|
70
|
-
|
71
|
-
def has_reddog_dhcp_domain?
|
72
|
-
tcp_ip_dhcp_domain == "reddog.microsoft.com"
|
73
|
-
end
|
74
|
-
|
75
|
-
def tcp_ip_dhcp_domain
|
76
|
-
return unless RUBY_PLATFORM.match?(/mswin|mingw|windows/)
|
77
|
-
|
78
|
-
if ChefUtils.windows?
|
79
|
-
require "win32/registry" unless defined?(Win32::Registry)
|
80
|
-
end
|
81
|
-
|
82
|
-
begin
|
83
|
-
key = Win32::Registry::HKEY_LOCAL_MACHINE.open("SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters")
|
84
|
-
dhcp_domain = key["DhcpDomain"]
|
85
|
-
Ohai::Log.trace("Plugin Azure: DhcpDomain registry value is #{dhcp_domain}")
|
86
|
-
rescue Win32::Registry::Error
|
87
|
-
Ohai::Log.trace("Plugin Azure: DhcpDomain registry value cannot be found")
|
88
|
-
end
|
89
|
-
|
90
|
-
dhcp_domain
|
91
|
-
end
|
92
|
-
|
93
|
-
# create the basic structure we'll store our data in
|
94
|
-
def initialize_metadata_mash_compute
|
95
|
-
metadata = Mash.new
|
96
|
-
metadata["compute"] = Mash.new
|
97
|
-
metadata
|
98
|
-
end
|
99
|
-
|
100
|
-
def initialize_metadata_mash_network(metadata)
|
101
|
-
metadata["network"] = Mash.new
|
102
|
-
metadata["network"]["interfaces"] = Mash.new
|
103
|
-
%w{public_ipv4 local_ipv4 public_ipv6 local_ipv6}.each do |type|
|
104
|
-
metadata["network"][type] = []
|
105
|
-
end
|
106
|
-
metadata
|
107
|
-
end
|
108
|
-
|
109
|
-
def fetch_ip_data(data, type, field)
|
110
|
-
ips = []
|
111
|
-
|
112
|
-
data[type]["ipAddress"].each do |val|
|
113
|
-
ips << val[field] unless val[field].empty?
|
114
|
-
end
|
115
|
-
ips
|
116
|
-
end
|
117
|
-
|
118
|
-
def parse_metadata
|
119
|
-
return nil unless can_socket_connect?(Ohai::Mixin::AzureMetadata::AZURE_METADATA_ADDR, 80)
|
120
|
-
|
121
|
-
endpoint_data = fetch_metadata
|
122
|
-
return nil if endpoint_data.nil?
|
123
|
-
|
124
|
-
metadata = initialize_metadata_mash_compute
|
125
|
-
|
126
|
-
# blindly add everything in compute to our data structure
|
127
|
-
endpoint_data["compute"].each do |k, v|
|
128
|
-
metadata["compute"][k] = v
|
129
|
-
end
|
130
|
-
|
131
|
-
# receiving network output is not guaranteed
|
132
|
-
unless endpoint_data["network"].nil?
|
133
|
-
metadata = initialize_metadata_mash_network(metadata)
|
134
|
-
# parse out per interface interface IP data
|
135
|
-
endpoint_data["network"]["interface"].each do |int|
|
136
|
-
metadata["network"]["interfaces"][int["macAddress"]] = Mash.new
|
137
|
-
metadata["network"]["interfaces"][int["macAddress"]]["mac"] = int["macAddress"]
|
138
|
-
metadata["network"]["interfaces"][int["macAddress"]]["public_ipv6"] = fetch_ip_data(int, "ipv6", "publicIpAddress")
|
139
|
-
metadata["network"]["interfaces"][int["macAddress"]]["public_ipv4"] = fetch_ip_data(int, "ipv4", "publicIpAddress")
|
140
|
-
metadata["network"]["interfaces"][int["macAddress"]]["local_ipv6"] = fetch_ip_data(int, "ipv6", "privateIpAddress")
|
141
|
-
metadata["network"]["interfaces"][int["macAddress"]]["local_ipv4"] = fetch_ip_data(int, "ipv4", "privateIpAddress")
|
142
|
-
end
|
143
|
-
|
144
|
-
# aggregate the total IP data
|
145
|
-
%w{public_ipv4 local_ipv4 public_ipv6 local_ipv6}.each do |type|
|
146
|
-
metadata["network"]["interfaces"].each_value do |val|
|
147
|
-
metadata["network"][type].concat val[type] unless val[type].empty?
|
148
|
-
end
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
metadata
|
153
|
-
end
|
154
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# Copyright:: Copyright (c) Chef Software Inc.
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
Ohai.plugin(:Azure) do
|
19
|
+
require_relative "../mixin/azure_metadata"
|
20
|
+
require_relative "../mixin/http_helper"
|
21
|
+
|
22
|
+
include Ohai::Mixin::AzureMetadata
|
23
|
+
include Ohai::Mixin::HttpHelper
|
24
|
+
|
25
|
+
provides "azure"
|
26
|
+
|
27
|
+
collect_data do
|
28
|
+
# Before we had the metadata endpoint we relied exclusively on
|
29
|
+
# the knife-azure plugin populating data to the hint file.
|
30
|
+
# Please see the lib/chef/knife/azure_server_create.rb file in that
|
31
|
+
# project for details
|
32
|
+
azure_metadata_from_hints = hint?("azure")
|
33
|
+
if azure_metadata_from_hints
|
34
|
+
logger.trace("Plugin Azure: Azure hint is present. Parsing any hint data.")
|
35
|
+
azure Mash.new
|
36
|
+
azure_metadata_from_hints.each { |k, v| azure[k] = v }
|
37
|
+
azure["metadata"] = parse_metadata
|
38
|
+
elsif has_waagent? || has_dhcp_option_245? || has_reddog_dhcp_domain?
|
39
|
+
logger.trace("Plugin Azure: No hints present, but system appears to be on Azure.")
|
40
|
+
azure Mash.new
|
41
|
+
azure["metadata"] = parse_metadata
|
42
|
+
else
|
43
|
+
logger.trace("Plugin Azure: No hints present and doesn't appear to be on Azure.")
|
44
|
+
false
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# check for either the waagent or the unknown-245 DHCP option that Azure uses
|
49
|
+
# http://blog.mszcool.com/index.php/2015/04/detecting-if-a-virtual-machine-runs-in-microsoft-azure-linux-windows-to-protect-your-software-when-distributed-via-the-azure-marketplace/
|
50
|
+
def has_waagent?
|
51
|
+
if file_exist?("/usr/sbin/waagent") || dir_exist?("C:\\WindowsAzure")
|
52
|
+
logger.trace("Plugin Azure: Found waagent used by Azure.")
|
53
|
+
true
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def has_dhcp_option_245?
|
58
|
+
has_245 = false
|
59
|
+
if file_exist?("/var/lib/dhcp/dhclient.eth0.leases")
|
60
|
+
file_open("/var/lib/dhcp/dhclient.eth0.leases").each do |line|
|
61
|
+
if /unknown-245/.match?(line)
|
62
|
+
logger.trace("Plugin Azure: Found unknown-245 DHCP option used by Azure.")
|
63
|
+
has_245 = true
|
64
|
+
break
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
has_245
|
69
|
+
end
|
70
|
+
|
71
|
+
def has_reddog_dhcp_domain?
|
72
|
+
tcp_ip_dhcp_domain == "reddog.microsoft.com"
|
73
|
+
end
|
74
|
+
|
75
|
+
def tcp_ip_dhcp_domain
|
76
|
+
return unless RUBY_PLATFORM.match?(/mswin|mingw|windows/)
|
77
|
+
|
78
|
+
if ChefUtils.windows?
|
79
|
+
require "win32/registry" unless defined?(Win32::Registry)
|
80
|
+
end
|
81
|
+
|
82
|
+
begin
|
83
|
+
key = Win32::Registry::HKEY_LOCAL_MACHINE.open("SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters")
|
84
|
+
dhcp_domain = key["DhcpDomain"]
|
85
|
+
Ohai::Log.trace("Plugin Azure: DhcpDomain registry value is #{dhcp_domain}")
|
86
|
+
rescue Win32::Registry::Error
|
87
|
+
Ohai::Log.trace("Plugin Azure: DhcpDomain registry value cannot be found")
|
88
|
+
end
|
89
|
+
|
90
|
+
dhcp_domain
|
91
|
+
end
|
92
|
+
|
93
|
+
# create the basic structure we'll store our data in
|
94
|
+
def initialize_metadata_mash_compute
|
95
|
+
metadata = Mash.new
|
96
|
+
metadata["compute"] = Mash.new
|
97
|
+
metadata
|
98
|
+
end
|
99
|
+
|
100
|
+
def initialize_metadata_mash_network(metadata)
|
101
|
+
metadata["network"] = Mash.new
|
102
|
+
metadata["network"]["interfaces"] = Mash.new
|
103
|
+
%w{public_ipv4 local_ipv4 public_ipv6 local_ipv6}.each do |type|
|
104
|
+
metadata["network"][type] = []
|
105
|
+
end
|
106
|
+
metadata
|
107
|
+
end
|
108
|
+
|
109
|
+
def fetch_ip_data(data, type, field)
|
110
|
+
ips = []
|
111
|
+
|
112
|
+
data[type]["ipAddress"].each do |val|
|
113
|
+
ips << val[field] unless val[field].empty?
|
114
|
+
end
|
115
|
+
ips
|
116
|
+
end
|
117
|
+
|
118
|
+
def parse_metadata
|
119
|
+
return nil unless can_socket_connect?(Ohai::Mixin::AzureMetadata::AZURE_METADATA_ADDR, 80)
|
120
|
+
|
121
|
+
endpoint_data = fetch_metadata
|
122
|
+
return nil if endpoint_data.nil?
|
123
|
+
|
124
|
+
metadata = initialize_metadata_mash_compute
|
125
|
+
|
126
|
+
# blindly add everything in compute to our data structure
|
127
|
+
endpoint_data["compute"].each do |k, v|
|
128
|
+
metadata["compute"][k] = v
|
129
|
+
end
|
130
|
+
|
131
|
+
# receiving network output is not guaranteed
|
132
|
+
unless endpoint_data["network"].nil?
|
133
|
+
metadata = initialize_metadata_mash_network(metadata)
|
134
|
+
# parse out per interface interface IP data
|
135
|
+
endpoint_data["network"]["interface"].each do |int|
|
136
|
+
metadata["network"]["interfaces"][int["macAddress"]] = Mash.new
|
137
|
+
metadata["network"]["interfaces"][int["macAddress"]]["mac"] = int["macAddress"]
|
138
|
+
metadata["network"]["interfaces"][int["macAddress"]]["public_ipv6"] = fetch_ip_data(int, "ipv6", "publicIpAddress")
|
139
|
+
metadata["network"]["interfaces"][int["macAddress"]]["public_ipv4"] = fetch_ip_data(int, "ipv4", "publicIpAddress")
|
140
|
+
metadata["network"]["interfaces"][int["macAddress"]]["local_ipv6"] = fetch_ip_data(int, "ipv6", "privateIpAddress")
|
141
|
+
metadata["network"]["interfaces"][int["macAddress"]]["local_ipv4"] = fetch_ip_data(int, "ipv4", "privateIpAddress")
|
142
|
+
end
|
143
|
+
|
144
|
+
# aggregate the total IP data
|
145
|
+
%w{public_ipv4 local_ipv4 public_ipv6 local_ipv6}.each do |type|
|
146
|
+
metadata["network"]["interfaces"].each_value do |val|
|
147
|
+
metadata["network"][type].concat val[type] unless val[type].empty?
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
metadata
|
153
|
+
end
|
154
|
+
end
|
@@ -1,121 +1,121 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
#
|
3
|
-
# Author:: Bryan McLellan (btm@loftninjas.org)
|
4
|
-
# Copyright:: Copyright (c) 2009 Bryan McLellan
|
5
|
-
# Copyright:: Copyright (c) Chef Software Inc.
|
6
|
-
# License:: Apache License, Version 2.0
|
7
|
-
#
|
8
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
9
|
-
# you may not use this file except in compliance with the License.
|
10
|
-
# You may obtain a copy of the License at
|
11
|
-
#
|
12
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
13
|
-
#
|
14
|
-
# Unless required by applicable law or agreed to in writing, software
|
15
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
16
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
17
|
-
# See the License for the specific language governing permissions and
|
18
|
-
# limitations under the License.
|
19
|
-
#
|
20
|
-
|
21
|
-
Ohai.plugin(:Virtualization) do
|
22
|
-
provides "virtualization"
|
23
|
-
depends "dmi"
|
24
|
-
require_relative "../../mixin/dmi_decode"
|
25
|
-
include Ohai::Mixin::DmiDecode
|
26
|
-
|
27
|
-
collect_data(:freebsd, :openbsd, :netbsd, :dragonflybsd) do
|
28
|
-
|
29
|
-
virtualization Mash.new unless virtualization
|
30
|
-
virtualization[:systems] ||= Mash.new
|
31
|
-
|
32
|
-
# detect when in a jail or when a jail is actively running (not in stopped state)
|
33
|
-
so = shell_out("sysctl -n security.jail.jailed")
|
34
|
-
if so.stdout.strip.to_i == 1
|
35
|
-
virtualization[:system] = "jail"
|
36
|
-
virtualization[:role] = "guest"
|
37
|
-
virtualization[:systems][:jail] = "guest"
|
38
|
-
logger.trace("Plugin Virtualization: Guest running in FreeBSD jail detected")
|
39
|
-
end
|
40
|
-
|
41
|
-
# run jls to get a list of running jails
|
42
|
-
# -n: name=value 1 line per jail format
|
43
|
-
# -d: list the dying jails as well as active jails
|
44
|
-
so = shell_out("jls -nd")
|
45
|
-
if (so.stdout || "").lines.count >= 1
|
46
|
-
virtualization[:system] = "jail"
|
47
|
-
virtualization[:role] = "host"
|
48
|
-
virtualization[:systems][:jail] = "host"
|
49
|
-
logger.trace("Plugin Virtualization: Host running FreeBSD jails detected")
|
50
|
-
end
|
51
|
-
|
52
|
-
# detect from modules
|
53
|
-
so = shell_out(Ohai.abs_path("/sbin/kldstat").to_s)
|
54
|
-
so.stdout.lines do |line|
|
55
|
-
case line
|
56
|
-
when /vboxdrv/
|
57
|
-
virtualization[:system] = "vbox"
|
58
|
-
virtualization[:role] = "host"
|
59
|
-
virtualization[:systems][:vbox] = "host"
|
60
|
-
logger.trace("Plugin Virtualization: Guest running on VirtualBox detected")
|
61
|
-
when /vboxguest/
|
62
|
-
virtualization[:system] = "vbox"
|
63
|
-
virtualization[:role] = "guest"
|
64
|
-
virtualization[:systems][:vbox] = "guest"
|
65
|
-
logger.trace("Plugin Virtualization: Host running VirtualBox detected")
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
# Detect bhyve by presence of /dev/vmm
|
70
|
-
if file_exist?("/dev/vmm")
|
71
|
-
virtualization[:system] = "bhyve"
|
72
|
-
virtualization[:role] = "host"
|
73
|
-
virtualization[:systems][:bhyve] = "host"
|
74
|
-
logger.trace("Plugin Virtualization: Host running bhyve detected")
|
75
|
-
end
|
76
|
-
|
77
|
-
# Detect KVM/QEMU paravirt guests from cpu, report as KVM
|
78
|
-
# hw.model: QEMU Virtual CPU version 0.9.1
|
79
|
-
so = shell_out("sysctl -n hw.model")
|
80
|
-
if /QEMU Virtual CPU|KVM processor/.match?(so.stdout)
|
81
|
-
virtualization[:system] = "kvm"
|
82
|
-
virtualization[:role] = "guest"
|
83
|
-
virtualization[:systems][:kvm] = "guest"
|
84
|
-
logger.trace("Plugin Virtualization: Guest running on KVM detected")
|
85
|
-
end
|
86
|
-
|
87
|
-
# gather hypervisor of guests from sysctl kern.vm_guest
|
88
|
-
# there are a limited number of hypervisors detected here, BUT it doesn't
|
89
|
-
# require dmidecode to be installed and dmidecode isn't in freebsd out of the box
|
90
|
-
so = shell_out("sysctl -n kern.vm_guest")
|
91
|
-
hypervisor = case so.stdout
|
92
|
-
when /vmware/
|
93
|
-
"vmware"
|
94
|
-
when /hv/
|
95
|
-
"hyperv"
|
96
|
-
when /xen/
|
97
|
-
"xen"
|
98
|
-
when /kvm/
|
99
|
-
so = shell_out("sysctl -n kern.hostuuid")
|
100
|
-
/^ec2/.match?(so.stdout) ? "amazonec2" : "kvm"
|
101
|
-
when /bhyve/
|
102
|
-
"bhyve"
|
103
|
-
end
|
104
|
-
|
105
|
-
if hypervisor
|
106
|
-
virtualization[:system] = hypervisor
|
107
|
-
virtualization[:role] = "guest"
|
108
|
-
virtualization[:systems][hypervisor.to_sym] = "guest"
|
109
|
-
logger.trace("Plugin Virtualization: Guest running on #{hypervisor} detected")
|
110
|
-
end
|
111
|
-
|
112
|
-
# parse dmi to discover various virtualization guests
|
113
|
-
guest = guest_from_dmi_data(get_attribute(:dmi, :system, :manufacturer), get_attribute(:dmi, :system, :product), get_attribute(:dmi, :system, :version))
|
114
|
-
if guest
|
115
|
-
logger.trace("Plugin Virtualization: DMI data indicates #{guest} guest")
|
116
|
-
virtualization[:system] = guest
|
117
|
-
virtualization[:role] = "guest"
|
118
|
-
virtualization[:systems][guest.to_sym] = "guest"
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# Author:: Bryan McLellan (btm@loftninjas.org)
|
4
|
+
# Copyright:: Copyright (c) 2009 Bryan McLellan
|
5
|
+
# Copyright:: Copyright (c) Chef Software Inc.
|
6
|
+
# License:: Apache License, Version 2.0
|
7
|
+
#
|
8
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
9
|
+
# you may not use this file except in compliance with the License.
|
10
|
+
# You may obtain a copy of the License at
|
11
|
+
#
|
12
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
13
|
+
#
|
14
|
+
# Unless required by applicable law or agreed to in writing, software
|
15
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
16
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
17
|
+
# See the License for the specific language governing permissions and
|
18
|
+
# limitations under the License.
|
19
|
+
#
|
20
|
+
|
21
|
+
Ohai.plugin(:Virtualization) do
|
22
|
+
provides "virtualization"
|
23
|
+
depends "dmi"
|
24
|
+
require_relative "../../mixin/dmi_decode"
|
25
|
+
include Ohai::Mixin::DmiDecode
|
26
|
+
|
27
|
+
collect_data(:freebsd, :openbsd, :netbsd, :dragonflybsd) do
|
28
|
+
|
29
|
+
virtualization Mash.new unless virtualization
|
30
|
+
virtualization[:systems] ||= Mash.new
|
31
|
+
|
32
|
+
# detect when in a jail or when a jail is actively running (not in stopped state)
|
33
|
+
so = shell_out("sysctl -n security.jail.jailed")
|
34
|
+
if so.stdout.strip.to_i == 1
|
35
|
+
virtualization[:system] = "jail"
|
36
|
+
virtualization[:role] = "guest"
|
37
|
+
virtualization[:systems][:jail] = "guest"
|
38
|
+
logger.trace("Plugin Virtualization: Guest running in FreeBSD jail detected")
|
39
|
+
end
|
40
|
+
|
41
|
+
# run jls to get a list of running jails
|
42
|
+
# -n: name=value 1 line per jail format
|
43
|
+
# -d: list the dying jails as well as active jails
|
44
|
+
so = shell_out("jls -nd")
|
45
|
+
if (so.stdout || "").lines.count >= 1
|
46
|
+
virtualization[:system] = "jail"
|
47
|
+
virtualization[:role] = "host"
|
48
|
+
virtualization[:systems][:jail] = "host"
|
49
|
+
logger.trace("Plugin Virtualization: Host running FreeBSD jails detected")
|
50
|
+
end
|
51
|
+
|
52
|
+
# detect from modules
|
53
|
+
so = shell_out(Ohai.abs_path("/sbin/kldstat").to_s)
|
54
|
+
so.stdout.lines do |line|
|
55
|
+
case line
|
56
|
+
when /vboxdrv/
|
57
|
+
virtualization[:system] = "vbox"
|
58
|
+
virtualization[:role] = "host"
|
59
|
+
virtualization[:systems][:vbox] = "host"
|
60
|
+
logger.trace("Plugin Virtualization: Guest running on VirtualBox detected")
|
61
|
+
when /vboxguest/
|
62
|
+
virtualization[:system] = "vbox"
|
63
|
+
virtualization[:role] = "guest"
|
64
|
+
virtualization[:systems][:vbox] = "guest"
|
65
|
+
logger.trace("Plugin Virtualization: Host running VirtualBox detected")
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# Detect bhyve by presence of /dev/vmm
|
70
|
+
if file_exist?("/dev/vmm")
|
71
|
+
virtualization[:system] = "bhyve"
|
72
|
+
virtualization[:role] = "host"
|
73
|
+
virtualization[:systems][:bhyve] = "host"
|
74
|
+
logger.trace("Plugin Virtualization: Host running bhyve detected")
|
75
|
+
end
|
76
|
+
|
77
|
+
# Detect KVM/QEMU paravirt guests from cpu, report as KVM
|
78
|
+
# hw.model: QEMU Virtual CPU version 0.9.1
|
79
|
+
so = shell_out("sysctl -n hw.model")
|
80
|
+
if /QEMU Virtual CPU|KVM processor/.match?(so.stdout)
|
81
|
+
virtualization[:system] = "kvm"
|
82
|
+
virtualization[:role] = "guest"
|
83
|
+
virtualization[:systems][:kvm] = "guest"
|
84
|
+
logger.trace("Plugin Virtualization: Guest running on KVM detected")
|
85
|
+
end
|
86
|
+
|
87
|
+
# gather hypervisor of guests from sysctl kern.vm_guest
|
88
|
+
# there are a limited number of hypervisors detected here, BUT it doesn't
|
89
|
+
# require dmidecode to be installed and dmidecode isn't in freebsd out of the box
|
90
|
+
so = shell_out("sysctl -n kern.vm_guest")
|
91
|
+
hypervisor = case so.stdout
|
92
|
+
when /vmware/
|
93
|
+
"vmware"
|
94
|
+
when /hv/
|
95
|
+
"hyperv"
|
96
|
+
when /xen/
|
97
|
+
"xen"
|
98
|
+
when /kvm/
|
99
|
+
so = shell_out("sysctl -n kern.hostuuid")
|
100
|
+
/^ec2/.match?(so.stdout) ? "amazonec2" : "kvm"
|
101
|
+
when /bhyve/
|
102
|
+
"bhyve"
|
103
|
+
end
|
104
|
+
|
105
|
+
if hypervisor
|
106
|
+
virtualization[:system] = hypervisor
|
107
|
+
virtualization[:role] = "guest"
|
108
|
+
virtualization[:systems][hypervisor.to_sym] = "guest"
|
109
|
+
logger.trace("Plugin Virtualization: Guest running on #{hypervisor} detected")
|
110
|
+
end
|
111
|
+
|
112
|
+
# parse dmi to discover various virtualization guests
|
113
|
+
guest = guest_from_dmi_data(get_attribute(:dmi, :system, :manufacturer), get_attribute(:dmi, :system, :product), get_attribute(:dmi, :system, :version))
|
114
|
+
if guest
|
115
|
+
logger.trace("Plugin Virtualization: DMI data indicates #{guest} guest")
|
116
|
+
virtualization[:system] = guest
|
117
|
+
virtualization[:role] = "guest"
|
118
|
+
virtualization[:systems][guest.to_sym] = "guest"
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|