ohai 16.4.11 → 16.6.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +11 -6
- data/bin/ohai +1 -1
- data/lib/ohai.rb +1 -1
- data/lib/ohai/application.rb +39 -0
- data/lib/ohai/common/dmi.rb +7 -3
- data/lib/ohai/config.rb +2 -3
- data/lib/ohai/dsl.rb +1 -1
- data/lib/ohai/dsl/plugin.rb +12 -5
- data/lib/ohai/dsl/plugin/versionvii.rb +28 -16
- data/lib/ohai/exception.rb +1 -1
- data/lib/ohai/hints.rb +1 -1
- data/lib/ohai/loader.rb +1 -1
- data/lib/ohai/log.rb +1 -1
- data/lib/ohai/mixin/azure_metadata.rb +1 -1
- data/lib/ohai/mixin/chef_utils_wiring.rb +51 -0
- data/lib/ohai/mixin/command.rb +3 -54
- data/lib/ohai/mixin/constant_helper.rb +1 -1
- data/lib/ohai/mixin/dmi_decode.rb +1 -1
- data/lib/ohai/mixin/do_metadata.rb +1 -1
- data/lib/ohai/mixin/ec2_metadata.rb +3 -3
- data/lib/ohai/mixin/http_helper.rb +1 -1
- data/lib/ohai/mixin/network_helper.rb +1 -1
- data/lib/ohai/mixin/os.rb +67 -2
- data/lib/ohai/mixin/scaleway_metadata.rb +1 -1
- data/lib/ohai/mixin/seconds_to_human.rb +1 -1
- data/lib/ohai/mixin/shell_out.rb +50 -0
- data/lib/ohai/mixin/string.rb +1 -1
- data/lib/ohai/mixin/train_helpers.rb +35 -0
- data/lib/ohai/mixin/which.rb +38 -0
- data/lib/ohai/plugin_config.rb +1 -1
- data/lib/ohai/plugins/aix/kernel.rb +1 -1
- data/lib/ohai/plugins/aix/memory.rb +3 -3
- data/lib/ohai/plugins/aix/network.rb +1 -1
- data/lib/ohai/plugins/aix/platform.rb +1 -1
- data/lib/ohai/plugins/aix/uptime.rb +1 -1
- data/lib/ohai/plugins/aix/virtualization.rb +1 -1
- data/lib/ohai/plugins/azure.rb +25 -5
- data/lib/ohai/plugins/bsd/virtualization.rb +3 -3
- data/lib/ohai/plugins/chef.rb +1 -1
- data/lib/ohai/plugins/cloud.rb +1 -1
- data/lib/ohai/plugins/command.rb +1 -1
- data/lib/ohai/plugins/cpu.rb +6 -6
- data/lib/ohai/plugins/darwin/memory.rb +1 -1
- data/lib/ohai/plugins/darwin/network.rb +1 -1
- data/lib/ohai/plugins/darwin/platform.rb +2 -2
- data/lib/ohai/plugins/darwin/virtualization.rb +2 -2
- data/lib/ohai/plugins/dmi.rb +1 -1
- data/lib/ohai/plugins/docker.rb +1 -1
- data/lib/ohai/plugins/ec2.rb +15 -9
- data/lib/ohai/plugins/erlang.rb +1 -1
- data/lib/ohai/plugins/eucalyptus.rb +1 -1
- data/lib/ohai/plugins/filesystem.rb +4 -4
- data/lib/ohai/plugins/fips.rb +1 -1
- data/lib/ohai/plugins/gce.rb +2 -2
- data/lib/ohai/plugins/hostname.rb +1 -1
- data/lib/ohai/plugins/init_package.rb +2 -2
- data/lib/ohai/plugins/java.rb +1 -1
- data/lib/ohai/plugins/joyent.rb +2 -2
- data/lib/ohai/plugins/kernel.rb +9 -5
- data/lib/ohai/plugins/keys.rb +1 -1
- data/lib/ohai/plugins/languages.rb +1 -1
- data/lib/ohai/plugins/libvirt.rb +1 -1
- data/lib/ohai/plugins/linode.rb +1 -1
- data/lib/ohai/plugins/linux/block_device.rb +9 -9
- data/lib/ohai/plugins/linux/interrupts.rb +3 -3
- data/lib/ohai/plugins/linux/ipc.rb +1 -1
- data/lib/ohai/plugins/linux/lsb.rb +4 -4
- data/lib/ohai/plugins/linux/machineid.rb +4 -4
- data/lib/ohai/plugins/linux/mdadm.rb +2 -2
- data/lib/ohai/plugins/linux/memory.rb +2 -2
- data/lib/ohai/plugins/linux/network.rb +13 -13
- data/lib/ohai/plugins/linux/platform.rb +30 -30
- data/lib/ohai/plugins/linux/virtualization.rb +24 -24
- data/lib/ohai/plugins/network.rb +1 -1
- data/lib/ohai/plugins/ohai_time.rb +2 -2
- data/lib/ohai/plugins/openstack.rb +1 -1
- data/lib/ohai/plugins/os.rb +5 -1
- data/lib/ohai/plugins/packages.rb +20 -0
- data/lib/ohai/plugins/passwd.rb +57 -1
- data/lib/ohai/plugins/perl.rb +1 -1
- data/lib/ohai/plugins/platform.rb +1 -1
- data/lib/ohai/plugins/powershell.rb +1 -1
- data/lib/ohai/plugins/ps.rb +1 -1
- data/lib/ohai/plugins/python.rb +1 -1
- data/lib/ohai/plugins/rackspace.rb +2 -2
- data/lib/ohai/plugins/scaleway.rb +1 -1
- data/lib/ohai/plugins/shard.rb +1 -1
- data/lib/ohai/plugins/shells.rb +3 -3
- data/lib/ohai/plugins/softlayer.rb +1 -1
- data/lib/ohai/plugins/solaris2/dmi.rb +1 -1
- data/lib/ohai/plugins/solaris2/network.rb +6 -8
- data/lib/ohai/plugins/solaris2/platform.rb +3 -3
- data/lib/ohai/plugins/solaris2/virtualization.rb +2 -2
- data/lib/ohai/plugins/ssh_host_key.rb +13 -13
- data/lib/ohai/plugins/train.rb +35 -0
- data/lib/ohai/plugins/uptime.rb +2 -2
- data/lib/ohai/plugins/virtualbox.rb +1 -1
- data/lib/ohai/plugins/vmware.rb +2 -2
- data/lib/ohai/plugins/windows/drivers.rb +1 -1
- data/lib/ohai/plugins/windows/network.rb +2 -2
- data/lib/ohai/plugins/windows/platform.rb +1 -1
- data/lib/ohai/plugins/windows/system_enclosure.rb +1 -1
- data/lib/ohai/plugins/windows/virtualization.rb +1 -1
- data/lib/ohai/plugins/zpools.rb +1 -1
- data/lib/ohai/provides_map.rb +1 -1
- data/lib/ohai/runner.rb +5 -1
- data/lib/ohai/system.rb +34 -7
- data/lib/ohai/train_transport.rb +28 -0
- data/lib/ohai/util/file_helper.rb +4 -37
- data/lib/ohai/util/win32.rb +1 -1
- data/lib/ohai/version.rb +3 -3
- data/ohai.gemspec +7 -7
- metadata +80 -60
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
2
|
# Author:: Serdar Sutay (<serdar@chef.io>)
|
3
|
-
# Copyright:: Copyright (c)
|
3
|
+
# Copyright:: Copyright (c) Chef Software Inc.
|
4
4
|
# License:: Apache License, Version 2.0
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -2,7 +2,7 @@
|
|
2
2
|
# Author:: Tim Dysinger (<tim@dysinger.net>)
|
3
3
|
# Author:: Benjamin Black (<bb@chef.io>)
|
4
4
|
# Author:: Christopher Brown (<cb@chef.io>)
|
5
|
-
# Copyright::
|
5
|
+
# Copyright:: Copyright (c) Chef Software Inc.
|
6
6
|
# License:: Apache License, Version 2.0
|
7
7
|
#
|
8
8
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -142,7 +142,7 @@ module Ohai
|
|
142
142
|
key = expand_path(o)
|
143
143
|
if key[-1..-1] != "/"
|
144
144
|
retr_meta = metadata_get("#{id}#{key}", api_version)
|
145
|
-
metadata[metadata_key(key)] = retr_meta
|
145
|
+
metadata[metadata_key(key)] = retr_meta || ""
|
146
146
|
elsif not key.eql?("/")
|
147
147
|
metadata[key[0..-2]] = fetch_dir_metadata("#{id}#{key}", api_version)
|
148
148
|
end
|
@@ -159,7 +159,7 @@ module Ohai
|
|
159
159
|
key = expand_path(o)
|
160
160
|
if key[-1..-1] != "/"
|
161
161
|
retr_meta = metadata_get("#{id}#{key}", api_version)
|
162
|
-
data = retr_meta
|
162
|
+
data = retr_meta || ""
|
163
163
|
json = String(data)
|
164
164
|
parser = FFI_Yajl::Parser.new
|
165
165
|
metadata[metadata_key(key)] = parser.parse(json)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
2
|
# Author:: Serdar Sutay (<serdar@chef.io>)
|
3
|
-
# Copyright:: Copyright (c)
|
3
|
+
# Copyright:: Copyright (c) Chef Software Inc.
|
4
4
|
# License:: Apache License, Version 2.0
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
data/lib/ohai/mixin/os.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
2
|
# Author:: Adam Jacob (<adam@chef.io>)
|
3
|
-
# Copyright:: Copyright (c)
|
3
|
+
# Copyright:: Copyright (c) Chef Software Inc.
|
4
4
|
# License:: Apache License, Version 2.0
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -27,6 +27,71 @@ module Ohai
|
|
27
27
|
#
|
28
28
|
# @return [String] the OS
|
29
29
|
def collect_os
|
30
|
+
if target_mode?
|
31
|
+
collect_os_target
|
32
|
+
else
|
33
|
+
collect_os_local
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# This should exactly preserve the semantics of collect_os_local below, which is authoritative
|
38
|
+
# for the API and must adhere to pre-existing ohai semantics and not follow inspec's notion of
|
39
|
+
# os/family/hierarchy.
|
40
|
+
#
|
41
|
+
# Right or wrong the ohai `os` variable has matched the ruby `host_os` definition for the past
|
42
|
+
# 10+ years, preceding inspec/train's definitions and this is the documented correct API of
|
43
|
+
# these methods. Mismatches between the ruby notion and the train version will be fixed as
|
44
|
+
# bugfixes in these methods and may not be considered semver violating even though they make
|
45
|
+
# break downstream consumers. Please ensure that both methods produce the same results if
|
46
|
+
# you are on a platform which supports running ruby (train is considered authoritative for
|
47
|
+
# any "OS" which cannot run ruby -- server consoles, REST APIs, etc...)
|
48
|
+
#
|
49
|
+
# @api private
|
50
|
+
def collect_os_target
|
51
|
+
case
|
52
|
+
when transport_connection.os.aix?
|
53
|
+
"aix"
|
54
|
+
when transport_connection.os.darwin?
|
55
|
+
"darwin"
|
56
|
+
when transport_connection.os.linux?
|
57
|
+
"linux"
|
58
|
+
when transport_connection.os.family == "freebsd"
|
59
|
+
"freebsd"
|
60
|
+
when transport_connection.os.family == "openbsd"
|
61
|
+
"openbsd"
|
62
|
+
when transport_connection.os.family == "netbsd"
|
63
|
+
"netbsd"
|
64
|
+
when transport_connection.os.family == "dragonflybsd"
|
65
|
+
"dragonflybsd"
|
66
|
+
when transport_connection.os.solaris?
|
67
|
+
"solaris2"
|
68
|
+
when transport_connection.os.windows?
|
69
|
+
"windows"
|
70
|
+
|
71
|
+
#
|
72
|
+
# The purpose of the next two lines is that anything which runs Unix is presumed to be able to run ruby, and
|
73
|
+
# if it was not caught above, we MUST translate whatever train uses as the 'os' into the proper ruby host_os
|
74
|
+
# string. If it is not unix and not caught above we assume it is something like a REST API which cannot run
|
75
|
+
# ruby. If these assumptions are incorrect then it is a bug, which should be submitted to fix it, and the
|
76
|
+
# values should not be relied upon until that bug is fixed. The train os is NEVER considered authoritative
|
77
|
+
# for any target which can run ruby.
|
78
|
+
#
|
79
|
+
when transport_connection.os.unix?
|
80
|
+
raise "Target mode unsupported on this Unix-like host, please update the collect_os_target case statement with the correct ruby host_os value."
|
81
|
+
else
|
82
|
+
# now we have something like an IPMI console that isn't Unix-like or Windows, presumably cannot run ruby, and
|
83
|
+
# so we just trust the train O/S information.
|
84
|
+
transport_connection.os
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
# @api private
|
89
|
+
def nonruby_target?
|
90
|
+
transport_connection && !transport_connection.os.unix? && !transport_connection.os.windows
|
91
|
+
end
|
92
|
+
|
93
|
+
# @api private
|
94
|
+
def collect_os_local
|
30
95
|
case ::RbConfig::CONFIG["host_os"]
|
31
96
|
when /aix(.+)$/
|
32
97
|
"aix"
|
@@ -56,7 +121,7 @@ module Ohai
|
|
56
121
|
end
|
57
122
|
end
|
58
123
|
|
59
|
-
|
124
|
+
extend self
|
60
125
|
end
|
61
126
|
end
|
62
127
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Adam Jacob (<adam@chef.io>)
|
3
|
+
# Author:: Tim Smith (<tsmith@chef.io>)
|
4
|
+
# Copyright:: Copyright (c) Chef Software Inc.
|
5
|
+
# License:: Apache License, Version 2.0
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
#
|
19
|
+
|
20
|
+
require_relative "../exception"
|
21
|
+
require_relative "../log"
|
22
|
+
|
23
|
+
require "mixlib/shellout/helper" unless defined?(Mixlib::ShellOut::Helper)
|
24
|
+
require_relative "chef_utils_wiring" unless defined?(Ohai::Mixin::ChefUtilsWiring)
|
25
|
+
|
26
|
+
module Ohai
|
27
|
+
module Mixin
|
28
|
+
module ShellOut
|
29
|
+
include Mixlib::ShellOut::Helper
|
30
|
+
include Ohai::Mixin::ChefUtilsWiring
|
31
|
+
|
32
|
+
def shell_out(cmd, **options)
|
33
|
+
options = options.dup
|
34
|
+
# unless specified by the caller timeout after configured timeout (default 30 seconds)
|
35
|
+
options[:timeout] ||= Ohai::Config.ohai[:shellout_timeout]
|
36
|
+
begin
|
37
|
+
so = super(cmd, **options)
|
38
|
+
logger.trace("Plugin #{name}: ran '#{cmd}' and returned #{so.exitstatus}")
|
39
|
+
so
|
40
|
+
rescue Errno::ENOENT => e
|
41
|
+
logger.trace("Plugin #{name}: ran '#{cmd}' and failed #{e.inspect}")
|
42
|
+
raise Ohai::Exceptions::Exec, e
|
43
|
+
rescue Mixlib::ShellOut::CommandTimeout => e
|
44
|
+
logger.trace("Plugin #{name}: ran '#{cmd}' and timed out after #{options[:timeout]} seconds")
|
45
|
+
raise Ohai::Exceptions::Exec, e
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/ohai/mixin/string.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
2
|
# Author:: James Gartrell (<jgartrel@gmail.com>)
|
3
|
-
# Copyright:: Copyright (c)
|
3
|
+
# Copyright:: Copyright (c) Chef Software Inc.
|
4
4
|
# License:: Apache License, Version 2.0
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -0,0 +1,35 @@
|
|
1
|
+
#
|
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
|
+
require "chef-utils/dsl/train_helpers" unless defined?(ChefUtils::DSL::TrainHelpers)
|
18
|
+
require_relative "chef_utils_wiring" unless defined?(Ohai::Mixin::ChefUtilsWiring)
|
19
|
+
|
20
|
+
module Ohai
|
21
|
+
module Mixin
|
22
|
+
module TrainHelpers
|
23
|
+
include ChefUtils::DSL::TrainHelpers
|
24
|
+
include ChefUtilsWiring
|
25
|
+
|
26
|
+
# anything added to this file temporarily should be pushed back up
|
27
|
+
# into ChefUtils::DSL::TrainHelpers
|
28
|
+
|
29
|
+
# XXX: this needs better support directly in train
|
30
|
+
def dir_glob(path)
|
31
|
+
shell_out!("ls -d #{path}").stdout.split
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
#
|
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
|
+
require "chef-utils/dsl/which" unless defined?(ChefUtils::DSL::Which)
|
18
|
+
require "chef-utils/dsl/default_paths" unless defined?(ChefUtils::DSL::DefaultPaths)
|
19
|
+
require_relative "chef_utils_wiring" unless defined?(Ohai::Mixin::ChefUtilsWiring)
|
20
|
+
|
21
|
+
module Ohai
|
22
|
+
module Mixin
|
23
|
+
module Which
|
24
|
+
include ChefUtils::DSL::Which
|
25
|
+
include ChefUtils::DSL::DefaultPaths
|
26
|
+
include ChefUtilsWiring
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
# we dep-inject default paths into this API for historical reasons
|
31
|
+
#
|
32
|
+
# @api private
|
33
|
+
def __extra_path
|
34
|
+
__default_paths
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/ohai/plugin_config.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#
|
2
2
|
# Author:: Joshua Timberman <joshua@chef.io>
|
3
3
|
# Author:: Isa Farnik (<isa@chef.io>)
|
4
|
-
# Copyright:: Copyright (c)
|
4
|
+
# Copyright:: Copyright (c) Chef Software Inc.
|
5
5
|
# License:: Apache License, Version 2.0
|
6
6
|
#
|
7
7
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -1,7 +1,7 @@
|
|
1
1
|
#
|
2
2
|
# Author:: Joshua Timberman <joshua@chef.io>
|
3
3
|
# Author:: Isa Farnik (<isa@chef.io>)
|
4
|
-
# Copyright:: Copyright (c)
|
4
|
+
# Copyright:: Copyright (c) Chef Software Inc.
|
5
5
|
# License:: Apache License, Version 2.0
|
6
6
|
#
|
7
7
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -30,7 +30,7 @@ Ohai.plugin(:Memory) do
|
|
30
30
|
memory[:free] = "#{free_in_mb.to_i * 1024}kB"
|
31
31
|
|
32
32
|
swap_info = shell_out("swap -s").stdout.split # returns swap info in 4K blocks
|
33
|
-
memory[:swap]["total"] = "#{
|
34
|
-
memory[:swap]["free"] = "#{
|
33
|
+
memory[:swap]["total"] = "#{swap_info[2].to_i * 4}kB"
|
34
|
+
memory[:swap]["free"] = "#{swap_info[10].to_i * 4}kB"
|
35
35
|
end
|
36
36
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
# Author:: Kaustubh Deorukhkar (<kaustubh@clogeny.com>)
|
3
3
|
# Author:: Prabhu Das (<prabhu.das@clogeny.com>)
|
4
4
|
# Author:: Isa Farnik (<isa@chef.io>)
|
5
|
-
# Copyright:: Copyright (c)
|
5
|
+
# Copyright:: Copyright (c) Chef Software Inc.
|
6
6
|
# License:: Apache License, Version 2.0
|
7
7
|
#
|
8
8
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -1,7 +1,7 @@
|
|
1
1
|
#
|
2
2
|
# Author:: Joshua Timberman <joshua@chef.io>
|
3
3
|
# Author:: Isa Farnik (<isa@chef.io>)
|
4
|
-
# Copyright:: Copyright (c)
|
4
|
+
# Copyright:: Copyright (c) Chef Software Inc.
|
5
5
|
# License:: Apache License, Version 2.0
|
6
6
|
#
|
7
7
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -1,7 +1,7 @@
|
|
1
1
|
#
|
2
2
|
# Author:: Kurt Yoder (<ktyopscode@yoderhome.com>)
|
3
3
|
# Author:: Isa Farnik (<isa@chef.io>)
|
4
|
-
# Copyright:: Copyright (c)
|
4
|
+
# Copyright:: Copyright (c) Chef Software Inc.
|
5
5
|
# License:: Apache License, Version 2.0
|
6
6
|
#
|
7
7
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -1,7 +1,7 @@
|
|
1
1
|
#
|
2
2
|
# Author:: Julian C. Dunn (<jdunn@chef.io>)
|
3
3
|
# Author:: Isa Farnik (<isa@chef.io>)
|
4
|
-
# Copyright:: Copyright (c)
|
4
|
+
# Copyright:: Copyright (c) Chef Software Inc.
|
5
5
|
# License:: Apache License, Version 2.0
|
6
6
|
#
|
7
7
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
data/lib/ohai/plugins/azure.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright:: Copyright
|
1
|
+
# Copyright:: Copyright (c) Chef Software Inc.
|
2
2
|
# License:: Apache License, Version 2.0
|
3
3
|
#
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -34,7 +34,7 @@ Ohai.plugin(:Azure) do
|
|
34
34
|
azure Mash.new
|
35
35
|
azure_metadata_from_hints.each { |k, v| azure[k] = v }
|
36
36
|
azure["metadata"] = parse_metadata
|
37
|
-
elsif has_waagent? || has_dhcp_option_245?
|
37
|
+
elsif has_waagent? || has_dhcp_option_245? || has_reddog_dhcp_domain?
|
38
38
|
logger.trace("Plugin Azure: No hints present, but system appears to be on Azure.")
|
39
39
|
azure Mash.new
|
40
40
|
azure["metadata"] = parse_metadata
|
@@ -47,7 +47,7 @@ Ohai.plugin(:Azure) do
|
|
47
47
|
# check for either the waagent or the unknown-245 DHCP option that Azure uses
|
48
48
|
# 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/
|
49
49
|
def has_waagent?
|
50
|
-
if
|
50
|
+
if file_exist?("/usr/sbin/waagent") || dir_exist?('C:\WindowsAzure')
|
51
51
|
logger.trace("Plugin Azure: Found waagent used by Azure.")
|
52
52
|
true
|
53
53
|
end
|
@@ -55,8 +55,8 @@ Ohai.plugin(:Azure) do
|
|
55
55
|
|
56
56
|
def has_dhcp_option_245?
|
57
57
|
has_245 = false
|
58
|
-
if
|
59
|
-
|
58
|
+
if file_exist?("/var/lib/dhcp/dhclient.eth0.leases")
|
59
|
+
file_open("/var/lib/dhcp/dhclient.eth0.leases").each do |line|
|
60
60
|
if /unknown-245/.match?(line)
|
61
61
|
logger.trace("Plugin Azure: Found unknown-245 DHCP option used by Azure.")
|
62
62
|
has_245 = true
|
@@ -67,6 +67,26 @@ Ohai.plugin(:Azure) do
|
|
67
67
|
has_245
|
68
68
|
end
|
69
69
|
|
70
|
+
def has_reddog_dhcp_domain?
|
71
|
+
tcp_ip_dhcp_domain == "reddog.microsoft.com"
|
72
|
+
end
|
73
|
+
|
74
|
+
def tcp_ip_dhcp_domain
|
75
|
+
return unless RUBY_PLATFORM.match?(/mswin|mingw32|windows/)
|
76
|
+
|
77
|
+
require "win32/registry" unless defined?(Win32::Registry)
|
78
|
+
|
79
|
+
begin
|
80
|
+
key = Win32::Registry::HKEY_LOCAL_MACHINE.open("SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters")
|
81
|
+
dhcp_domain = key["DhcpDomain"]
|
82
|
+
Ohai::Log.trace("Plugin Azure: DhcpDomain registry value is #{dhcp_domain}")
|
83
|
+
rescue Win32::Registry::Error
|
84
|
+
Ohai::Log.trace("Plugin Azure: DhcpDomain registry value cannot be found")
|
85
|
+
end
|
86
|
+
|
87
|
+
dhcp_domain
|
88
|
+
end
|
89
|
+
|
70
90
|
# create the basic structure we'll store our data in
|
71
91
|
def initialize_metadata_mash_compute
|
72
92
|
metadata = Mash.new
|