diff options
author | Pavel Yudin <pyudin@parallels.com> | 2015-06-17 14:23:19 +0300 |
---|---|---|
committer | Pavel Yudin <pyudin@parallels.com> | 2015-06-17 16:19:10 +0300 |
commit | f4bb444c46455144bd02c495055f8a72949b5970 (patch) | |
tree | 98aa8392e435474a5583cfebeab12ee2cd55cfa2 | |
parent | 31f6415c853f3070b0399ac2eb09094eb81939d2 (diff) | |
download | ohai-f4bb444c46455144bd02c495055f8a72949b5970.tar.gz |
the detection of parallels virtualization added
-rw-r--r-- | lib/ohai/plugins/darwin/virtualization.rb | 54 | ||||
-rw-r--r-- | lib/ohai/plugins/linux/virtualization.rb | 9 | ||||
-rw-r--r-- | lib/ohai/plugins/windows/virtualization.rb | 44 |
3 files changed, 107 insertions, 0 deletions
diff --git a/lib/ohai/plugins/darwin/virtualization.rb b/lib/ohai/plugins/darwin/virtualization.rb new file mode 100644 index 00000000..ea108e7c --- /dev/null +++ b/lib/ohai/plugins/darwin/virtualization.rb @@ -0,0 +1,54 @@ +# +# Author:: Pavel Yudin (<pyudin@parallels.com>) +# Copyright:: Copyright (c) 2015 Pavel Yudin +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'ohai/util/file_helper' + +include Ohai::Util::FileHelper + +Ohai.plugin(:Virtualization) do + provides "virtualization" + + def prlctl_exists? + which('prlctl') + end + + def ioreg_exists? + which('ioreg') + end + + collect_data(:darwin) do + virtualization Mash.new unless virtualization + virtualization[:systems] = Mash.new unless virtualization[:systems] + + if prlctl_exists? + virtualization[:system] = 'parallels' + virtualization[:role] = 'host' + virtualization[:systems][:parallels] = 'host' + end + + # Detect Parallels virtual machine from pci devices + if ioreg_exists? + so = shell_out('ioreg -l') + if so.stdout =~ /pci1ab8,4000/ + virtualization[:system] = 'parallels' + virtualization[:role] = 'guest' + virtualization[:systems][:parallels] = 'guest' + end + end + end +end diff --git a/lib/ohai/plugins/linux/virtualization.rb b/lib/ohai/plugins/linux/virtualization.rb index 1990b773..75c7f189 100644 --- a/lib/ohai/plugins/linux/virtualization.rb +++ b/lib/ohai/plugins/linux/virtualization.rb @@ -105,6 +105,15 @@ Ohai.plugin(:Virtualization) do virtualization[:systems][:openvz] = "guest" end + # Detect Parallels virtual machine from pci devices + if File.exists?("/proc/bus/pci/devices") + if File.read("/proc/bus/pci/devices") =~ /1ab84000/ + virtualization[:system] = "parallels" + virtualization[:role] = "guest" + virtualization[:systems][:parallels] = "guest" + end + end + # http://www.dmo.ca/blog/detecting-virtualization-on-linux if File.exists?("/usr/sbin/dmidecode") so = shell_out("dmidecode") diff --git a/lib/ohai/plugins/windows/virtualization.rb b/lib/ohai/plugins/windows/virtualization.rb new file mode 100644 index 00000000..6090fd3a --- /dev/null +++ b/lib/ohai/plugins/windows/virtualization.rb @@ -0,0 +1,44 @@ +# +# Author:: Pavel Yudin (<pyudin@parallels.com>) +# Copyright:: Copyright (c) 2015 Pavel Yudin +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'ohai/util/file_helper' + +include Ohai::Util::FileHelper + +Ohai.plugin(:Virtualization) do + provides "virtualization" + + def powershell_exists? + which('powershell.exe') + end + + collect_data(:windows) do + virtualization Mash.new unless virtualization + virtualization[:systems] = Mash.new unless virtualization[:systems] + + # Detect Parallels virtual machine from BIOS information + if powershell_exists? + so = shell_out('powershell.exe "Get-WmiObject -Class Win32_BIOS"') + if so.stdout =~ /Parallels Software International Inc./ + virtualization[:system] = 'parallels' + virtualization[:role] = 'guest' + virtualization[:systems][:parallels] = 'guest' + end + end + end +end |