summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThom May <thom@may.lt>2015-06-24 17:47:50 +0100
committerThom May <thom@may.lt>2015-06-24 17:47:50 +0100
commit85e605426056694c596f1bed1680a7a914abd808 (patch)
treef4fda4ab037ea73fa980b473b30c1e39d4f6e9cc
parente44be812aa0e6d8c10a37b4931519a39f888aa8c (diff)
parenta7ab16f6cd38c73a922a2e75bff17cc398918702 (diff)
downloadohai-85e605426056694c596f1bed1680a7a914abd808.tar.gz
Merge pull request #557 from Kasen/master
The detection of Parallels virtualization added.
-rw-r--r--lib/ohai/plugins/darwin/virtualization.rb54
-rw-r--r--lib/ohai/plugins/linux/virtualization.rb9
-rw-r--r--lib/ohai/plugins/windows/virtualization.rb44
-rw-r--r--spec/unit/plugins/darwin/virtualization_spec.rb109
-rw-r--r--spec/unit/plugins/linux/virtualization_spec.rb27
-rw-r--r--spec/unit/plugins/windows/virtualization_spec.rb64
6 files changed, 307 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..b586d47b
--- /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
diff --git a/spec/unit/plugins/darwin/virtualization_spec.rb b/spec/unit/plugins/darwin/virtualization_spec.rb
new file mode 100644
index 00000000..86487e9a
--- /dev/null
+++ b/spec/unit/plugins/darwin/virtualization_spec.rb
@@ -0,0 +1,109 @@
+#
+# 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 File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
+
+describe Ohai::System, "Darwin virtualization platform" do
+ let(:plugin) { get_plugin("darwin/virtualization")}
+
+ before(:each) do
+ allow(plugin).to receive(:collect_os).and_return(:darwin)
+ allow(plugin).to receive(:prlctl_exists?).and_return(false)
+ end
+
+ describe "when we are checking for parallels" do
+ it "should set parallels host if /usr/bin/prlctl exists" do
+ allow(plugin).to receive(:prlctl_exists?).and_return("/usr/bin/prlctl")
+ plugin.run
+ expect(plugin[:virtualization][:system]).to eq("parallels")
+ expect(plugin[:virtualization][:role]).to eq("host")
+ expect(plugin[:virtualization][:systems][:parallels]).to eq("host")
+ end
+
+ it "should not set parallels host if /usr/bin/prlctl not exist" do
+ allow(plugin).to receive(:prlctl_exists?).and_return(false)
+ plugin.run
+ expect(plugin[:virtualization]).to eq({'systems' => {}})
+ end
+
+ it "should set parallels guest if /usr/sbin/ioreg exists and it's output contains pci1ab8,4000" do
+ allow(plugin).to receive(:ioreg_exists?).and_return(true)
+ ioreg=<<-IOREG
+ | | +-o pci1ab8,4000@3 <class IOPCIDevice, id 0x1000001d1, registered, matched, active, busy 0 (40 ms), retain 9>
+ | | | | {
+ | | | | "compatible" = <"pci1ab8,400","pci1ab8,4000","pciclass,ff0000">
+ | | | | "subsystem-vendor-id" = <b81a0000>
+ | | | | "IOName" = "pci1ab8,4000"
+ | | | | "reg" = <00180000000000000000000000000000000000001018000100000000000000000000000020000000>
+ | | | | "device-id" = <00400000>
+ | | | | "assigned-addresses" = <101800810000000040d200000000000020000000>
+ | | | | "IOPowerManagement" = {"MaxPowerState"=3,"ChildProxyPowerState"=2,"CurrentPowerState"=2}
+ | | | | "IOPCIResourced" = Yes
+ | | | | "IODeviceMemory" = ("IOSubMemoryDescriptor is not serializable")
+ | | | | "revision-id" = <00000000>
+ | | | | "IOInterruptControllers" = ("IOPCIMessagedInterruptController")
+ | | | | "vendor-id" = <b81a0000>
+ | | | | "pcidebug" = "0:3:0"
+ | | | | "class-code" = <0000ff00>
+ | | | | "IOInterruptSpecifiers" = (<0000000000000100>)
+ | | | | "IOPCIMSIMode" = Yes
+ | | | | "subsystem-id" = <00040000>
+ | | | | "name" = <"pci1ab8,4000">
+ | | | | }
+ IOREG
+ shellout = double("shellout")
+ allow(shellout).to receive(:stdout).and_return(ioreg)
+ allow(plugin).to receive(:shell_out).with("ioreg -l").and_return(shellout)
+ plugin.run
+ expect(plugin[:virtualization][:system]).to eq("parallels")
+ expect(plugin[:virtualization][:role]).to eq("guest")
+ expect(plugin[:virtualization][:systems][:parallels]).to eq("guest")
+ end
+
+ it "should not set parallels guest if /usr/sbin/ioreg exists and it's output not contain pci1ab8,4000" do
+ allow(plugin).to receive(:ioreg_exists?).and_return(true)
+ ioreg=<<-IOREG
+ | | +-o pci8086,2445@1F,4 <class IOPCIDevice, id 0x1000001d4, registered, matched, active, busy 0 (974 ms), retain 11>
+ | | | {
+ | | | "compatible" = <"pci1ab8,400","pci8086,2445","pciclass,040100">
+ | | | "subsystem-vendor-id" = <b81a0000>
+ | | | "IOName" = "pci8086,2445"
+ | | | "reg" = <00fc00000000000000000000000000000000000010fc00010000000000000000000000000001000014fc000100000000000000000000000000010000>
+ | | | "device-id" = <45240000>
+ | | | "assigned-addresses" = <10fc00810000000000d10000000000000001000014fc00810000000000d000000000000000010000>
+ | | | "IOPowerManagement" = {"ChildrenPowerState"=2,"CurrentPowerState"=2,"ChildProxyPowerState"=2,"MaxPowerState"=3}
+ | | | "IOPCIResourced" = Yes
+ | | | "IODeviceMemory" = ("IOSubMemoryDescriptor is not serializable","IOSubMemoryDescriptor is not serializable")
+ | | | "revision-id" = <02000000>
+ | | | "IOInterruptControllers" = ("io-apic-0")
+ | | | "vendor-id" = <86800000>
+ | | | "pcidebug" = "0:31:4"
+ | | | "class-code" = <00010400>
+ | | | "IOInterruptSpecifiers" = (<1100000007000000>)
+ | | | "subsystem-id" = <00040000>
+ | | | "name" = <"pci8086,2445">
+ | | | }
+ IOREG
+ shellout = double("shellout")
+ allow(shellout).to receive(:stdout).and_return(ioreg)
+ allow(plugin).to receive(:shell_out).with("ioreg -l").and_return(shellout)
+ plugin.run
+ expect(plugin[:virtualization]).to eq({'systems' => {}})
+ end
+ end
+end
diff --git a/spec/unit/plugins/linux/virtualization_spec.rb b/spec/unit/plugins/linux/virtualization_spec.rb
index a9e2ae10..152d11b0 100644
--- a/spec/unit/plugins/linux/virtualization_spec.rb
+++ b/spec/unit/plugins/linux/virtualization_spec.rb
@@ -35,6 +35,7 @@ describe Ohai::System, "Linux virtualization platform" do
allow(File).to receive(:exists?).with("/proc/self/cgroup").and_return(false)
allow(File).to receive(:exists?).with("/.dockerenv").and_return(false)
allow(File).to receive(:exists?).with("/.dockerinit").and_return(false)
+ allow(File).to receive(:exists?).with("/proc/bus/pci/devices").and_return(false)
end
describe "when we are checking for xen" do
@@ -320,6 +321,32 @@ OPENSTACK
end
end
+ describe "when we are checking for parallels" do
+ it "should set parallels guest if /proc/bus/pci/devices contains 1ab84000" do
+ devices=<<-DEVICES
+0018 1ab84000 1f 8001 0 0 0 0 0 0 20 0 0 0 0 0 0 prl_tg
+0028 1af41000 17 8201 ee000000 0 0 0 0 0 40 1000 0 0 0 0 0 virtio-pci
+ DEVICES
+ expect(File).to receive(:exists?).with("/proc/bus/pci/devices").and_return(true)
+ allow(File).to receive(:read).with("/proc/bus/pci/devices").and_return(devices)
+ @plugin.run
+ expect(@plugin[:virtualization][:system]).to eq("parallels")
+ expect(@plugin[:virtualization][:role]).to eq("guest")
+ expect(@plugin[:virtualization][:systems][:parallels]).to eq("guest")
+ end
+
+ it "should not set virtualization if /proc/bus/pci/devices not contains 1ab84000" do
+ devices=<<-DEVICES
+0030 1af41000 a 8401 ee040000 0 0 0 0 0 40 1000 0 0 0 0 0 virtio-pci
+0050 10110022 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+ DEVICES
+ expect(File).to receive(:exists?).with("/proc/bus/pci/devices").and_return(true)
+ allow(File).to receive(:read).with("/proc/bus/pci/devices").and_return(devices)
+ @plugin.run
+ expect(@plugin[:virtualization]).to eq({'systems' => {}})
+ end
+ end
+
describe "when we are checking for lxc" do
it "should set lxc guest if /proc/self/cgroup exist and there are /lxc/<hexadecimal> mounts" do
self_cgroup=<<-CGROUP
diff --git a/spec/unit/plugins/windows/virtualization_spec.rb b/spec/unit/plugins/windows/virtualization_spec.rb
new file mode 100644
index 00000000..213aba13
--- /dev/null
+++ b/spec/unit/plugins/windows/virtualization_spec.rb
@@ -0,0 +1,64 @@
+#
+# 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 File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
+
+describe Ohai::System, "Windows virtualization platform" do
+ let(:plugin) { get_plugin("windows/virtualization")}
+
+ before(:each) do
+ allow(plugin).to receive(:collect_os).and_return(:windows)
+ allow(plugin).to receive(:powershell_exists?).and_return(false)
+ end
+
+ describe "when we are checking for parallels" do
+ it "should set parallels guest if powershell exists and it's output contains 'Parallels Software International Inc.'" do
+ allow(plugin).to receive(:powershell_exists?).and_return(true)
+ bios=<<-BIOS
+SMBIOSBIOSVersion : 10.2.0 (28956) rev 0
+Manufacturer : Parallels Software International Inc.
+Name : Default System BIOS
+SerialNumber : Parallels-92 05 B4 56 97 11 4F FA B1 95 1A FF 8E F9 DD CE
+Version : PRLS - 1
+ BIOS
+ shellout = double("shellout")
+ allow(shellout).to receive(:stdout).and_return(bios)
+ allow(plugin).to receive(:shell_out).with('powershell.exe "Get-WmiObject -Class Win32_BIOS"').and_return(shellout)
+ plugin.run
+ expect(plugin[:virtualization][:system]).to eq("parallels")
+ expect(plugin[:virtualization][:role]).to eq("guest")
+ expect(plugin[:virtualization][:systems][:parallels]).to eq("guest")
+ end
+
+ it "should not set parallels guest if powershell exists and it's output not contain 'Parallels Software International Inc.'" do
+ allow(plugin).to receive(:ioreg_exists?).and_return(true)
+ bios=<<-BIOS
+SMBIOSBIOSVersion : 4.6.5
+Manufacturer      : American Megatrends Inc.
+Name              : BIOS Date: 10/23/12 15:38:23 Ver: 04.06.05
+SerialNumber      : 334281-001
+Version           : Dealin - 1072009
+ BIOS
+ shellout = double("shellout")
+ allow(shellout).to receive(:stdout).and_return(bios)
+ allow(plugin).to receive(:shell_out).with('powershell.exe "Get-WmiObject -Class Win32_BIOS"').and_return(shellout)
+ plugin.run
+ expect(plugin[:virtualization]).to eq({'systems' => {}})
+ end
+ end
+end