summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2015-12-01 10:21:54 -0800
committerTim Smith <tsmith@chef.io>2015-12-01 10:21:54 -0800
commit417d9ea541d11eb3bfa7944789bc5447655c6ab8 (patch)
treef0161b424d06b9bf578de18f76d8e574ea049833
parentf26efd8c7f1ce1d36a72a19552a7b8af4316ed42 (diff)
parent38e107fe7938a01768420cfbf0207821a36d2be6 (diff)
downloadohai-417d9ea541d11eb3bfa7944789bc5447655c6ab8.tar.gz
Merge pull request #655 from tas50/bsd
Dedupe BSD Plugins, create Mixin for parsing DMI Decode, add HyperV detection
-rw-r--r--lib/ohai/mixin/dmi_decode.rb47
-rw-r--r--lib/ohai/plugins/bsd/filesystem.rb (renamed from lib/ohai/plugins/freebsd/filesystem.rb)2
-rw-r--r--lib/ohai/plugins/bsd/virtualization.rb80
-rw-r--r--lib/ohai/plugins/dragonflybsd/filesystem.rb57
-rw-r--r--lib/ohai/plugins/freebsd/virtualization.rb94
-rw-r--r--lib/ohai/plugins/linux/virtualization.rb45
-rw-r--r--lib/ohai/plugins/netbsd/filesystem.rb57
-rw-r--r--lib/ohai/plugins/netbsd/virtualization.rb68
-rw-r--r--lib/ohai/plugins/openbsd/filesystem.rb57
-rw-r--r--lib/ohai/plugins/openbsd/virtualization.rb68
-rw-r--r--spec/unit/plugins/bsd/filesystem_spec.rb (renamed from spec/unit/plugins/freebsd/filesystem_spec.rb)4
-rw-r--r--spec/unit/plugins/bsd/virtualization_spec.rb (renamed from spec/unit/plugins/freebsd/virtualization_spec.rb)11
-rw-r--r--spec/unit/plugins/linux/virtualization_spec.rb44
13 files changed, 184 insertions, 450 deletions
diff --git a/lib/ohai/mixin/dmi_decode.rb b/lib/ohai/mixin/dmi_decode.rb
new file mode 100644
index 00000000..f367e41d
--- /dev/null
+++ b/lib/ohai/mixin/dmi_decode.rb
@@ -0,0 +1,47 @@
+#
+# Author:: Tim Smith <tsmith@chef.io>
+# Copyright:: Copyright (c) 2015 Chef Software, Inc.
+# 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.
+
+# http://www.dmo.ca/blog/detecting-virtualization-on-linux
+module ::Ohai::Mixin::DmiDecode
+ def determine_guest(dmi_data)
+ dmi_data.each_line do |line|
+ case line
+ when /Manufacturer: Microsoft/
+ if dmi_data =~ /Product Name: Virtual Machine/
+ if dmi_data =~ /Version: (VS2005R2|6.0)/
+ return 'virtualpc'
+ elsif dmi_data =~ /Version: (7.0|Hyper-V)/
+ return 'hyperv'
+ elsif dmi_data =~ /Version: 5.0/
+ return 'virtualserver'
+ end
+ end
+ when /Manufacturer: VMware/
+ return 'vmware'
+ when /Manufacturer: Xen/
+ return 'xen'
+ when /Product Name: VirtualBox/
+ return 'vbox'
+ when /Product Name: OpenStack/
+ return 'openstack'
+ when /Manufacturer: QEMU|Product Name: (KVM|RHEV)/
+ return 'kvm'
+ end
+ end
+ return nil
+ end
+end
diff --git a/lib/ohai/plugins/freebsd/filesystem.rb b/lib/ohai/plugins/bsd/filesystem.rb
index 9b5a573a..6c5d73f5 100644
--- a/lib/ohai/plugins/freebsd/filesystem.rb
+++ b/lib/ohai/plugins/bsd/filesystem.rb
@@ -20,7 +20,7 @@
Ohai.plugin(:Filesystem) do
provides "filesystem"
- collect_data(:freebsd) do
+ collect_data(:freebsd, :openbsd, :netbsd, :dragonflybsd) do
fs = Mash.new
# Grab filesystem data from df
diff --git a/lib/ohai/plugins/bsd/virtualization.rb b/lib/ohai/plugins/bsd/virtualization.rb
new file mode 100644
index 00000000..5317fa9e
--- /dev/null
+++ b/lib/ohai/plugins/bsd/virtualization.rb
@@ -0,0 +1,80 @@
+#
+# Author:: Bryan McLellan (btm@loftninjas.org)
+# Copyright:: Copyright (c) 2009 Bryan McLellan
+# 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/mixin/dmi_decode'
+
+include Ohai::Mixin::DmiDecode
+
+Ohai.plugin(:Virtualization) do
+ provides 'virtualization'
+
+ collect_data(:freebsd, :openbsd, :netbsd, :dragonflybsd) do
+
+ virtualization Mash.new unless virtualization
+ virtualization[:systems] = Mash.new unless virtualization[:systems]
+
+ # detect when in a jail or when a jail is actively running (not in stopped state)
+ so = shell_out("sysctl -n security.jail.jailed")
+ if so.stdout.split($/)[0].to_i == 1
+ virtualization[:system] = "jail"
+ virtualization[:role] = "guest"
+ virtualization[:systems][:jail] = 'guest'
+ end
+
+ so = shell_out('jls -n')
+ if (so.stdout || '').lines.count >= 1
+ virtualization[:system] = 'jail'
+ virtualization[:role] = 'host'
+ virtualization[:systems][:jail] = 'host'
+ end
+
+ # detect from modules
+ so = shell_out("#{Ohai.abs_path('/sbin/kldstat')}")
+ so.stdout.lines do |line|
+ case line
+ when /vboxdrv/
+ virtualization[:system] = 'vbox'
+ virtualization[:role] = 'host'
+ virtualization[:systems][:vbox] = 'host'
+ when /vboxguest/
+ virtualization[:system] = 'vbox'
+ virtualization[:role] = 'guest'
+ virtualization[:systems][:vbox] = 'guest'
+ end
+ end
+
+ # Detect KVM/QEMU from cpu, report as KVM
+ # hw.model: QEMU Virtual CPU version 0.9.1
+ so = shell_out('sysctl -n hw.model')
+ if so.stdout.split($/)[0] =~ /QEMU Virtual CPU|Common KVM processor|Common 32-bit KVM processor/
+ virtualization[:system] = 'kvm'
+ virtualization[:role] = 'guest'
+ virtualization[:systems][:kvm] = 'guest'
+ end
+
+ # parse dmidecode to discover various virtualization guests
+ if File.exist?('/usr/local/sbin/dmidecode') || File.exist?('/usr/pkg/sbin/dmidecode')
+ guest = determine_guest(shell_out('dmidecode').stdout)
+ if guest
+ virtualization[:system] = guest
+ virtualization[:role] = 'guest'
+ virtualization[:systems][guest.to_sym] = 'guest'
+ end
+ end
+ end
+end
diff --git a/lib/ohai/plugins/dragonflybsd/filesystem.rb b/lib/ohai/plugins/dragonflybsd/filesystem.rb
deleted file mode 100644
index 558efb00..00000000
--- a/lib/ohai/plugins/dragonflybsd/filesystem.rb
+++ /dev/null
@@ -1,57 +0,0 @@
-#
-# Author:: Adam Jacob (<adam@opscode.com>)
-# Copyright:: Copyright (c) 2008 Opscode, Inc.
-# 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.
-#
-
-Ohai.plugin(:Filesystem) do
- provides "filesystem"
-
- collect_data(:dragonflybsd) do
- fs = Mash.new
-
- # Grab filesystem data from df
- so = shell_out("df")
- so.stdout.lines do |line|
- case line
- when /^Filesystem/
- next
- when /^(.+?)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+\%)\s+(.+)$/
- filesystem = $1
- fs[filesystem] = Mash.new
- fs[filesystem][:kb_size] = $2
- fs[filesystem][:kb_used] = $3
- fs[filesystem][:kb_available] = $4
- fs[filesystem][:percent_used] = $5
- fs[filesystem][:mount] = $6
- end
- end
-
- # Grab mount information from mount
- so = shell_out("mount")
- so.stdout.lines do |line|
- if line =~ /^(.+?) on (.+?) \((.+?), (.+?)\)$/
- filesystem = $1
- fs[filesystem] = Mash.new unless fs.has_key?(filesystem)
- fs[filesystem][:mount] = $2
- fs[filesystem][:fs_type] = $3
- fs[filesystem][:mount_options] = $4.split(/,\s*/)
- end
- end
-
- # Set the filesystem data
- filesystem fs
- end
-end
diff --git a/lib/ohai/plugins/freebsd/virtualization.rb b/lib/ohai/plugins/freebsd/virtualization.rb
deleted file mode 100644
index bad34fd2..00000000
--- a/lib/ohai/plugins/freebsd/virtualization.rb
+++ /dev/null
@@ -1,94 +0,0 @@
-#
-# Author:: Bryan McLellan (btm@loftninjas.org)
-# Copyright:: Copyright (c) 2009 Bryan McLellan
-# 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.
-#
-
-Ohai.plugin(:Virtualization) do
- provides "virtualization"
-
- collect_data(:freebsd) do
- virtualization Mash.new
-
- so = shell_out("sysctl -n security.jail.jailed")
- if so.stdout.split($/)[0].to_i == 1
- virtualization[:system] = "jail"
- virtualization[:role] = "guest"
- end
-
- # detect from modules
- so = shell_out("#{ Ohai.abs_path( "/sbin/kldstat" )}")
- so.stdout.lines do |line|
- case line
- when /vboxdrv/
- virtualization[:system] = "vbox"
- virtualization[:role] = "host"
- when /vboxguest/
- virtualization[:system] = "vbox"
- virtualization[:role] = "guest"
- end
- end
-
- # XXX doesn't work when jail is there but not running (ezjail-admin stop)
- so = shell_out("jls -n")
- if ( so.stdout || "" ).lines.count >= 1
- virtualization[:system] = "jail"
- virtualization[:role] = "host"
- end
-
- # KVM Host support for FreeBSD is in development
- # http://feanor.sssup.it/~fabio/freebsd/lkvm/
-
- # Detect KVM/QEMU from cpu, report as KVM
- # hw.model: QEMU Virtual CPU version 0.9.1
- so = shell_out("sysctl -n hw.model")
- if so.stdout.split($/)[0] =~ /QEMU Virtual CPU|Common KVM processor|Common 32-bit KVM processor/
- virtualization[:system] = "kvm"
- virtualization[:role] = "guest"
- end
-
- # http://www.dmo.ca/blog/detecting-virtualization-on-linux
- if File.exists?("/usr/local/sbin/dmidecode")
- so = shell_out("dmidecode")
- found_virt_manufacturer = nil
- found_virt_product = nil
- so.stdout.lines do |line|
- case line
- when /Manufacturer: Microsoft/
- found_virt_manufacturer = "microsoft"
- when /Product Name: Virtual Machine/
- found_virt_product = "microsoft"
- when /Version: 5.0/
- if found_virt_manufacturer == "microsoft" && found_virt_product == "microsoft"
- virtualization[:system] = "virtualpc"
- virtualization[:role] = "guest"
- end
- when /Version: VS2005R2/
- if found_virt_manufacturer == "microsoft" && found_virt_product == "microsoft"
- virtualization[:system] = "virtualserver"
- virtualization[:role] = "guest"
- end
- when /Manufacturer: VMware/
- found_virt_manufacturer = "vmware"
- when /Product Name: VMware Virtual Platform/
- if found_virt_manufacturer == "vmware"
- virtualization[:system] = "vmware"
- virtualization[:role] = "guest"
- end
- end
- end
- end
- end
-end
diff --git a/lib/ohai/plugins/linux/virtualization.rb b/lib/ohai/plugins/linux/virtualization.rb
index fb433824..c53c06ae 100644
--- a/lib/ohai/plugins/linux/virtualization.rb
+++ b/lib/ohai/plugins/linux/virtualization.rb
@@ -17,8 +17,10 @@
#
require 'ohai/util/file_helper'
+require 'ohai/mixin/dmi_decode'
include Ohai::Util::FileHelper
+include Ohai::Mixin::DmiDecode
Ohai.plugin(:Virtualization) do
provides "virtualization"
@@ -114,44 +116,13 @@ Ohai.plugin(:Virtualization) do
end
end
- # http://www.dmo.ca/blog/detecting-virtualization-on-linux
+ # parse dmidecode to discover various virtualization guests
if File.exists?("/usr/sbin/dmidecode")
- so = shell_out("dmidecode")
- case so.stdout
- when /Manufacturer: Microsoft/
- if so.stdout =~ /Product Name: Virtual Machine/
- virtualization[:system] = "virtualpc"
- virtualization[:role] = "guest"
- virtualization[:systems][:virtualpc] = "guest"
- end
- when /Manufacturer: VMware/
- if so.stdout =~ /Product Name: VMware Virtual Platform/
- virtualization[:system] = "vmware"
- virtualization[:role] = "guest"
- virtualization[:systems][:vmware] = "guest"
- end
- when /Manufacturer: Xen/
- if so.stdout =~ /Product Name: HVM domU/
- virtualization[:system] = "xen"
- virtualization[:role] = "guest"
- virtualization[:systems][:xen] = "guest"
- end
- when /Manufacturer: Oracle Corporation/
- if so.stdout =~ /Product Name: VirtualBox/
- virtualization[:system] = "vbox"
- virtualization[:role] = "guest"
- virtualization[:systems][:vbox] = "guest"
- end
- when /Product Name: OpenStack/
- virtualization[:system] = "openstack"
- virtualization[:role] = "guest"
- virtualization[:systems][:openstack] = "guest"
- when /Manufacturer: QEMU|Product Name: (KVM|RHEV)/
- virtualization[:system] = "kvm"
- virtualization[:role] = "guest"
- virtualization[:systems][:kvm] = "guest"
- else
- nil
+ guest = determine_guest(shell_out('dmidecode').stdout)
+ if guest
+ virtualization[:system] = guest
+ virtualization[:role] = 'guest'
+ virtualization[:systems][guest.to_sym] = 'guest'
end
end
diff --git a/lib/ohai/plugins/netbsd/filesystem.rb b/lib/ohai/plugins/netbsd/filesystem.rb
deleted file mode 100644
index 89a715b6..00000000
--- a/lib/ohai/plugins/netbsd/filesystem.rb
+++ /dev/null
@@ -1,57 +0,0 @@
-#
-# Author:: Adam Jacob (<adam@opscode.com>)
-# Copyright:: Copyright (c) 2008 Opscode, Inc.
-# 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.
-#
-
-Ohai.plugin(:Filesystem) do
- provides "filesystem"
-
- collect_data(:netbsd) do
- fs = Mash.new
-
- # Grab filesystem data from df
- so = shell_out("df")
- so.stdout.lines do |line|
- case line
- when /^Filesystem/
- next
- when /^(.+?)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+\%)\s+(.+)$/
- filesystem = $1
- fs[filesystem] = Mash.new
- fs[filesystem]['kb_size'] = $2
- fs[filesystem]['kb_used'] = $3
- fs[filesystem]['kb_available'] = $4
- fs[filesystem]['percent_used'] = $5
- fs[filesystem]['mount'] = $6
- end
- end
-
- # Grab mount information from mount
- so = shell_out("mount -l")
- so.stdout.lines do |line|
- if line =~ /^(.+?) on (.+?) \((.+?), (.+?)\)$/
- filesystem = $1
- fs[filesystem] = Mash.new unless fs.has_key?(filesystem)
- fs[filesystem]['mount'] = $2
- fs[filesystem]['fs_type'] = $3
- fs[filesystem]['mount-options'] = $4.split(/,\s*/)
- end
- end
-
- # Set the filesystem data
- filesystem fs
- end
-end
diff --git a/lib/ohai/plugins/netbsd/virtualization.rb b/lib/ohai/plugins/netbsd/virtualization.rb
deleted file mode 100644
index d2fabf25..00000000
--- a/lib/ohai/plugins/netbsd/virtualization.rb
+++ /dev/null
@@ -1,68 +0,0 @@
-#
-# Author:: Bryan McLellan (btm@loftninjas.org)
-# Copyright:: Copyright (c) 2009 Bryan McLellan
-# 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.
-#
-
-Ohai.plugin(:Virtualization) do
- provides "virtualization"
-
- collect_data(:netbsd) do
- virtualization Mash.new
-
- # KVM Host support for FreeBSD is in development
- # http://feanor.sssup.it/~fabio/freebsd/lkvm/
-
- # Detect KVM/QEMU from cpu, report as KVM
- # hw.model: QEMU Virtual CPU version 0.9.1
- so = shell_out("sysctl -n hw.model")
- if so.stdout.split($/)[0] =~ /QEMU Virtual CPU/
- virtualization[:system] = "kvm"
- virtualization[:role] = "guest"
- end
-
- # http://www.dmo.ca/blog/detecting-virtualization-on-linux
- if File.exists?("/usr/pkg/sbin/dmidecode")
- so = shell_out("dmidecode")
- found_virt_manufacturer = nil
- found_virt_product = nil
- so.stdout.lines do |line|
- case line
- when /Manufacturer: Microsoft/
- found_virt_manufacturer = "microsoft"
- when /Product Name: Virtual Machine/
- found_virt_product = "microsoft"
- when /Version: 5.0/
- if found_virt_manufacturer == "microsoft" && found_virt_product == "microsoft"
- virtualization[:system] = "virtualpc"
- virtualization[:role] = "guest"
- end
- when /Version: VS2005R2/
- if found_virt_manufacturer == "microsoft" && found_virt_product == "microsoft"
- virtualization[:system] = "virtualserver"
- virtualization[:role] = "guest"
- end
- when /Manufacturer: VMware/
- found_virt_manufacturer = "vmware"
- when /Product Name: VMware Virtual Platform/
- if found_virt_manufacturer == "vmware"
- virtualization[:system] = "vmware"
- virtualization[:role] = "guest"
- end
- end
- end
- end
- end
-end
diff --git a/lib/ohai/plugins/openbsd/filesystem.rb b/lib/ohai/plugins/openbsd/filesystem.rb
deleted file mode 100644
index aa33f9b2..00000000
--- a/lib/ohai/plugins/openbsd/filesystem.rb
+++ /dev/null
@@ -1,57 +0,0 @@
-#
-# Author:: Adam Jacob (<adam@opscode.com>)
-# Copyright:: Copyright (c) 2008 Opscode, Inc.
-# 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.
-#
-
-Ohai.plugin(:Filesystem) do
- provides "filesystem"
-
- collect_data(:openbsd) do
- fs = Mash.new
-
- # Grab filesystem data from df
- so = shell_out("df")
- so.stdout.lines do |line|
- case line
- when /^Filesystem/
- next
- when /^(.+?)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+\%)\s+(.+)$/
- filesystem = $1
- fs[filesystem] = Mash.new
- fs[filesystem]['kb_size'] = $2
- fs[filesystem]['kb_used'] = $3
- fs[filesystem]['kb_available'] = $4
- fs[filesystem]['percent_used'] = $5
- fs[filesystem]['mount'] = $6
- end
- end
-
- # Grab mount information from mount
- so = shell_out("mount -l")
- so.stdout.lines do |line|
- if line =~ /^(.+?) on (.+?) \((.+?), (.+?)\)$/
- filesystem = $1
- fs[filesystem] = Mash.new unless fs.has_key?(filesystem)
- fs[filesystem]['mount'] = $2
- fs[filesystem]['fs_type'] = $3
- fs[filesystem]['mount-options'] = $4.split(/,\s*/)
- end
- end
-
- # Set the filesystem data
- filesystem fs
- end
-end
diff --git a/lib/ohai/plugins/openbsd/virtualization.rb b/lib/ohai/plugins/openbsd/virtualization.rb
deleted file mode 100644
index 45715887..00000000
--- a/lib/ohai/plugins/openbsd/virtualization.rb
+++ /dev/null
@@ -1,68 +0,0 @@
-#
-# Author:: Bryan McLellan (btm@loftninjas.org)
-# Copyright:: Copyright (c) 2009 Bryan McLellan
-# 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.
-#
-
-Ohai.plugin(:Virtualization) do
- provides "virtualization"
-
- collect_data(:openbsd) do
- virtualization Mash.new
-
- # KVM Host support for FreeBSD is in development
- # http://feanor.sssup.it/~fabio/freebsd/lkvm/
-
- # Detect KVM/QEMU from cpu, report as KVM
- # hw.model: QEMU Virtual CPU version 0.9.1
- so = shell_out("sysctl -n hw.model")
- if so.stdout.split($/)[0] =~ /QEMU Virtual CPU/
- virtualization[:system] = "kvm"
- virtualization[:role] = "guest"
- end
-
- # http://www.dmo.ca/blog/detecting-virtualization-on-linux
- if File.exists?("/usr/local/sbin/dmidecode")
- so = shell_out("dmidecode")
- found_virt_manufacturer = nil
- found_virt_product = nil
- so.stdout.lines do |line|
- case line
- when /Manufacturer: Microsoft/
- found_virt_manufacturer = "microsoft"
- when /Product Name: Virtual Machine/
- found_virt_product = "microsoft"
- when /Version: 5.0/
- if found_virt_manufacturer == "microsoft" && found_virt_product == "microsoft"
- virtualization[:system] = "virtualpc"
- virtualization[:role] = "guest"
- end
- when /Version: VS2005R2/
- if found_virt_manufacturer == "microsoft" && found_virt_product == "microsoft"
- virtualization[:system] = "virtualserver"
- virtualization[:role] = "guest"
- end
- when /Manufacturer: VMware/
- found_virt_manufacturer = "vmware"
- when /Product Name: VMware Virtual Platform/
- if found_virt_manufacturer == "vmware"
- virtualization[:system] = "vmware"
- virtualization[:role] = "guest"
- end
- end
- end
- end
- end
-end
diff --git a/spec/unit/plugins/freebsd/filesystem_spec.rb b/spec/unit/plugins/bsd/filesystem_spec.rb
index ede13361..030f9d08 100644
--- a/spec/unit/plugins/freebsd/filesystem_spec.rb
+++ b/spec/unit/plugins/bsd/filesystem_spec.rb
@@ -19,8 +19,8 @@
require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
-describe Ohai::System, "FreeBSD filesystem plugin" do
- let(:plugin) { get_plugin("freebsd/filesystem") }
+describe Ohai::System, "BSD filesystem plugin" do
+ let(:plugin) { get_plugin("bsd/filesystem") }
before(:each) do
allow(plugin).to receive(:collect_os).and_return(:freebsd)
diff --git a/spec/unit/plugins/freebsd/virtualization_spec.rb b/spec/unit/plugins/bsd/virtualization_spec.rb
index dbd0d3f8..355df67f 100644
--- a/spec/unit/plugins/freebsd/virtualization_spec.rb
+++ b/spec/unit/plugins/bsd/virtualization_spec.rb
@@ -18,9 +18,9 @@
require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
-describe Ohai::System, "FreeBSD virtualization plugin" do
+describe Ohai::System, "BSD virtualization plugin" do
before(:each) do
- @plugin = get_plugin("freebsd/virtualization")
+ @plugin = get_plugin("bsd/virtualization")
allow(@plugin).to receive(:collect_os).and_return(:freebsd)
allow(@plugin).to receive(:shell_out).with("sysctl -n security.jail.jailed").and_return(mock_shell_out(0, "0", ""))
allow(@plugin).to receive(:shell_out).with("#{ Ohai.abs_path( "/sbin/kldstat" )}").and_return(mock_shell_out(0, "", ""))
@@ -34,6 +34,7 @@ describe Ohai::System, "FreeBSD virtualization plugin" do
@plugin.run
expect(@plugin[:virtualization][:system]).to eq("jail")
expect(@plugin[:virtualization][:role]).to eq("guest")
+ expect(@plugin[:virtualization][:systems][:jail]).to eq("guest")
end
it "detects we are hosting jails" do
@@ -43,6 +44,7 @@ describe Ohai::System, "FreeBSD virtualization plugin" do
@plugin.run
expect(@plugin[:virtualization][:system]).to eq("jail")
expect(@plugin[:virtualization][:role]).to eq("host")
+ expect(@plugin[:virtualization][:systems][:jail]).to eq("host")
end
end
@@ -60,6 +62,7 @@ OUT
@plugin.run
expect(@plugin[:virtualization][:system]).to eq("vbox")
expect(@plugin[:virtualization][:role]).to eq("guest")
+ expect(@plugin[:virtualization][:systems][:vbox]).to eq("guest")
end
end
@@ -77,6 +80,7 @@ OUT
@plugin.run
expect(@plugin[:virtualization][:system]).to eq("vbox")
expect(@plugin[:virtualization][:role]).to eq("host")
+ expect(@plugin[:virtualization][:systems][:vbox]).to eq("host")
end
end
@@ -87,9 +91,8 @@ OUT
@plugin.run
expect(@plugin[:virtualization][:system]).to eq("kvm")
expect(@plugin[:virtualization][:role]).to eq("guest")
+ expect(@plugin[:virtualization][:systems][:kvm]).to eq("guest")
end
end
end
-
- # TODO upfactor tests from linux virtualization plugin for dmidecode
end
diff --git a/spec/unit/plugins/linux/virtualization_spec.rb b/spec/unit/plugins/linux/virtualization_spec.rb
index ab7bf274..8509230a 100644
--- a/spec/unit/plugins/linux/virtualization_spec.rb
+++ b/spec/unit/plugins/linux/virtualization_spec.rb
@@ -168,7 +168,41 @@ MSVPC
expect(plugin[:virtualization][:systems][:virtualpc]).to eq("guest")
end
- it "sets vmware guest if dmidecode detects VMware Virtual Platform" do
+ it "sets hyperv guest if dmidecode detects Hyper-V or version 7.0" do
+ ms_hv_dmidecode=<<-MSHV
+System Information
+ Manufacturer: Microsoft Corporation
+ Product Name: Virtual Machine
+ Version: 7.0
+ Serial Number: 9242-2608-7031-8934-2088-5216-61
+ UUID: C2431A2D-D69C-244F-9DE8-CD5D09E0DA39
+ Wake-up Type: Power Switch
+MSHV
+ allow(plugin).to receive(:shell_out).with("dmidecode").and_return(mock_shell_out(0, ms_hv_dmidecode, ""))
+ plugin.run
+ expect(plugin[:virtualization][:system]).to eq("hyperv")
+ expect(plugin[:virtualization][:role]).to eq("guest")
+ expect(plugin[:virtualization][:systems][:hyperv]).to eq("guest")
+ end
+
+ it "sets virtualserver guest if dmidecode detects version 5.0" do
+ ms_vs_dmidecode=<<-MSVS
+System Information
+ Manufacturer: Microsoft Corporation
+ Product Name: Virtual Machine
+ Version: 5.0
+ Serial Number: 1688-7189-5337-7903-2297-1012-52
+ UUID: D29974A4-BE51-044C-BDC6-EFBC4B87A8E9
+ Wake-up Type: Power Switch
+MSVS
+ allow(plugin).to receive(:shell_out).with("dmidecode").and_return(mock_shell_out(0, ms_vs_dmidecode, ""))
+ plugin.run
+ expect(plugin[:virtualization][:system]).to eq("virtualserver")
+ expect(plugin[:virtualization][:role]).to eq("guest")
+ expect(plugin[:virtualization][:systems][:virtualserver]).to eq("guest")
+ end
+
+ it "sets vmware guest if dmidecode detects VMware" do
vmware_dmidecode=<<-VMWARE
System Information
Manufacturer: VMware, Inc.
@@ -187,7 +221,7 @@ VMWARE
expect(plugin[:virtualization][:systems][:vmware]).to eq("guest")
end
- it "sets vbox guest if dmidecode detects Oracle Corporation" do
+ it "sets vbox guest if dmidecode detects VirtualBox" do
vbox_dmidecode=<<-VBOX
Base Board Information
Manufacturer: Oracle Corporation
@@ -227,8 +261,8 @@ OPENSTACK
expect(plugin[:virtualization][:systems][:openstack]).to eq("guest")
end
- it "sets kvm guest if dmidecode detects KVM" do
- kvm_dmidecode=<<-KVM
+ it "sets kvm guest if dmidecode contains KVM" do
+ kvm_dmidecode=<<-RKVM
System Information
Manufacturer: Red Hat
Product Name: KVM
@@ -238,7 +272,7 @@ System Information
Wake-up Type: Power Switch
SKU Number: Not Specified
Family: Red Hat Enterprise Linux
-KVM
+RKVM
allow(plugin).to receive(:shell_out).with("dmidecode").and_return(mock_shell_out(0, kvm_dmidecode, ""))
plugin.run
expect(plugin[:virtualization][:system]).to eq("kvm")