diff options
author | Tim Smith <tsmith84@gmail.com> | 2015-11-27 13:27:48 -0800 |
---|---|---|
committer | Tim Smith <tsmith84@gmail.com> | 2015-11-27 18:03:40 -0800 |
commit | dbc5c406df19f0d2bbcca364d1f3d36957d04c81 (patch) | |
tree | 7879a69c63c3bbddf80ecb07a8be8f946c5125c0 /lib/ohai/mixin | |
parent | ebeb43911a65a39ab0b5ffb49e2f9eae7dfe61f4 (diff) | |
download | ohai-dbc5c406df19f0d2bbcca364d1f3d36957d04c81.tar.gz |
Move dmidecode parsing into a mixin to dedupe code
Diffstat (limited to 'lib/ohai/mixin')
-rw-r--r-- | lib/ohai/mixin/dmi_decode.rb | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/lib/ohai/mixin/dmi_decode.rb b/lib/ohai/mixin/dmi_decode.rb new file mode 100644 index 00000000..625b6c90 --- /dev/null +++ b/lib/ohai/mixin/dmi_decode.rb @@ -0,0 +1,45 @@ +# +# 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/ + return 'virtualpc' + else + 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 |